annotate lib-src/movemail.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents c5d627a313b1
children 19dcec799385
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* movemail foo bar -- move file foo to file bar,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 locking file foo the way /bin/mail respects.
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
3 Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 cause loss of mail* if you do it on a system that does not normally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 use flock as its way of interlocking access to inbox files. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 system's own conventions. It is not a choice that is up to you.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 So, if your system uses lock files rather than flock, then the only way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 you can get proper operation is to enable movemail to write lockfiles there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 This means you must either give that directory access modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 that permit everyone to write lockfiles in it, or you must make movemail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 a setuid or setgid program. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 *
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
37 * Added POP (Post Office Protocol) service. When compiled -DMAIL_USE_POP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 * movemail will accept input filename arguments of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 * "po:username". This will cause movemail to open a connection to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 * a pop server running on $MAILHOST (environment variable). Movemail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 * must be setuid to root in order to work with POP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * New module: popmail.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 * Modified routines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * after POP code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * New routines in movemail.c:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * get_errmsg - return pointer to system error message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 *
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
50 * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
51 *
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
52 * Move all of the POP code into a separate file, "pop.c".
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
53 * Use strerror instead of get_errmsg.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
54 *
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #define NO_SHORTNAMES /* Tell config not to load remap.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include <../src/config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #include <sys/file.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
62 #include <stdio.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include <errno.h>
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
64 #include "../src/syswait.h"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
65 #include "../src/systime.h"
122
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
66 #include <stdlib.h>
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
67 #include <string.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
68 #ifdef MAIL_USE_POP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
69 #include "pop.h"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
70 #endif
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
71
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
72 #ifndef HAVE_STRERROR
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
73 static char * strerror (int errnum);
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
74 #endif /* HAVE_STRERROR */
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
75
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 #undef access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
80 #ifndef DIRECTORY_SEP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
81 #define DIRECTORY_SEP '/'
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
82 #endif
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
83 #ifndef IS_DIRECTORY_SEP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
84 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
85 #endif
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
86
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
87 #ifdef WINDOWSNT
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
88 #undef access
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
89 #undef unlink
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
90 #define fork() 0
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
91 #define sys_wait(var) (*(var) = 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
92 /* Unfortunately, Samba doesn't seem to properly lock Unix files even
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
93 though the locking call succeeds (and indeed blocks local access from
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
94 other NT programs). If you have direct file access using an NFS
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
95 client or something other than Samba, the locking call might work
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
96 properly - make sure it does before you enable this! */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
97 #define DISABLE_DIRECT_ACCESS
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 272
diff changeset
98 #include <io.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
99 #endif /* WINDOWSNT */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
100
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
101 #if defined (HAVE_UNISTD_H) || defined (USG)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 #include <unistd.h>
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
103 #endif /* unistd.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #ifndef F_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #define F_OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #define X_OK 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #define W_OK 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 #define R_OK 4
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
109 #endif /* No F_OK */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
111 #if defined (HAVE_FCNTL_H) || defined (USG)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
112 #include <fcntl.h>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
113 #endif /* fcntl.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
115 #if defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #include <sys/locking.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #ifdef MAIL_USE_FLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 extern int lk_open (), lk_close ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 /* Cancel substitutions made by config.h for Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #undef open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #undef read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #undef write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 #undef close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
137 static void fatal (char *, char*);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
138 static void error (char *, char *, char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
139 static void pfatal_with_name (char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
140 static void pfatal_and_delete (char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
141 static char *concat (char *, char *, char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
142 static long *xmalloc (unsigned int);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
143 #ifdef MAIL_USE_POP
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
144 static int popmail (char *, char *, char *);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
145 static int pop_retr (popserver server, int msgno, int (*action)(), void *arg);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
146 static int mbx_write (char *, FILE *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
147 static int mbx_delimit_begin (FILE *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
148 static int mbx_delimit_end (FILE *);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
149 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 /* Nonzero means this is name of a lock file to delete on fatal error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 char *delete_lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
154 int
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
155 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 char *inname, *outname;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 272
diff changeset
158 #ifndef DISABLE_DIRECT_ACCESS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 int indesc, outdesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 int nread;
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
161 int status;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 272
diff changeset
162 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 long now;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 char *lockname, *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 char *tempname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 int desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 delete_lockname = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 if (argc < 3)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
176 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
177 fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n");
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
178 exit(1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
179 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 inname = argv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 outname = argv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 mmdf_init (argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
188 if (*outname == 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
189 fatal ("Destination file name is empty", 0);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
190
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 /* Check access to output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
195 /* Also check that outname's directory is writable to the real uid. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 char *buf = (char *) xmalloc (strlen (outname) + 1);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
198 char *cp;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 strcpy (buf, outname);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
200 cp = buf + strlen (buf);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
201 while (cp > buf && !IS_DIRECTORY_SEP (cp[-1]))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
202 *--cp = 0;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
203 if (cp == buf)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
204 *cp++ = '.';
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (access (buf, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 pfatal_with_name (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 free (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #ifdef MAIL_USE_POP
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
211 if (!strncmp (inname, "po:", 3))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
213 int retcode = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
214 exit (retcode);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
220 #ifndef DISABLE_DIRECT_ACCESS
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
221
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 /* Check access to input file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (access (inname, R_OK | W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 #ifndef MAIL_USE_SYSTEM_LOCK
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
228 /* Use a lock file named after our first argument with .lock appended:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 If it exists, the mail file is locked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 /* Note: this locking mechanism is *required* by the mailer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (on systems which use it) to prevent loss of mail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 On systems that use a lock file, extracting the mail without locking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 WILL occasionally cause loss of mail due to timing errors!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 So, if creation of the lock file fails
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
237 due to access permission on the mail spool directory,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 you simply MUST change the permission
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 and/or make movemail a setgid program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 so it can create lock files properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 You might also wish to verify that your system is one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 which uses lock files for this purpose. Some systems use other methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 If your system uses the `flock' system call for mail locking,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 and recompile movemail. If the s- file for your system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 lockname = concat (inname, ".lock", "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 strcpy (tempname, inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 p = tempname + strlen (tempname);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
255 while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 p--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 *p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 strcpy (p, "EXXXXXX");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 mktemp (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 /* Create the lock file, but not under the lock file name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 /* Give up if cannot do that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 if (desc < 0)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
268 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
269 char *message = (char *) xmalloc (strlen (tempname) + 50);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
270 sprintf (message, "%s--see source file lib-src/movemail.c",
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
271 tempname);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
272 pfatal_with_name (message);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
273 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 close (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 tem = link (tempname, lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 if (tem >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
282 /* If lock file is five minutes old, unlock it.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
283 Five minutes should be good enough to cope with crashes
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
284 and wedgitude, and long enough to avoid being fooled
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
285 by time differences between machines. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (stat (lockname, &st) >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 now = time (0);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
289 if (st.st_ctime < now - 300)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
290 unlink (lockname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 delete_lockname = lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 #endif /* not MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 if (fork () == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 indesc = open (inname, O_RDWR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 #else /* if not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 indesc = open (inname, O_RDONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 #else /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 #endif /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 if (indesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 #if defined (BSD) || defined (XENIX)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 /* In case movemail is setuid to root, make sure the user can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 read the output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 /* This is desirable for all systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 but I don't want to assume all have the umask system call */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 umask (umask (0) & 0333);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 #endif /* BSD or Xenix */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 if (outdesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 if (lockf (indesc, F_LOCK, 0) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 #else /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 #ifdef XENIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 #else
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
332 #ifdef WINDOWSNT
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
333 if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
334 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 #endif
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
337 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 #endif /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 char buf[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 nread = read (indesc, buf, sizeof buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 if (nread != write (outdesc, buf, nread))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 int saved_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 unlink (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 errno = saved_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 if (nread < sizeof buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 if (fsync (outdesc) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 /* Check to make sure no errors before we zap the inbox. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (close (outdesc) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 #ifdef MAIL_USE_SYSTEM_LOCK
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
369 #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ftruncate (indesc, 0L);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 #endif /* STRIDE or XENIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 lk_close (indesc, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 close (indesc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 /* Delete the input file; if we can't, at least get rid of its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 #ifdef MAIL_UNLINK_SPOOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 /* This is generally bad to do, because it destroys the permissions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 that were set on the file. Better to just empty the file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 if (unlink (inname) < 0 && errno != ENOENT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 #endif /* MAIL_UNLINK_SPOOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 creat (inname, 0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 wait (&status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 if (!WIFEXITED (status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 exit (1);
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
400 else if (WEXITSTATUS (status) != 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
401 exit (WEXITSTATUS (status));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 unlink (lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
406
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
407 #endif /* ! DISABLE_DIRECT_ACCESS */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
408
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
409 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
414 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
415 fatal (char *s1, char *s2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 if (delete_lockname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 unlink (delete_lockname);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
419 error (s1, s2, NULL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
425 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
426 error (char *s1, char *s2, char *s3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
428 fprintf (stderr, "movemail: ");
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
429 fprintf (stderr, s1, s2, s3);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
430 fprintf (stderr, "\n");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
433 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
434 pfatal_with_name (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
436 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
440 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
441 pfatal_and_delete (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
443 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 unlink (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
450 static char *
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
451 concat (char *s1, char *s2, char *s3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 strcpy (result, s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 strcpy (result + len1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 strcpy (result + len1 + len2, s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 *(result + len1 + len2 + len3) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
466 static long *
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
467 xmalloc (unsigned int size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
469 long *result = (long *) malloc (size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 if (!result)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
471 fatal ("virtual memory exhausted", 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 /* This is the guts of the interface to the Post Office Protocol. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 #ifdef MAIL_USE_POP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
479 #ifndef WINDOWSNT
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #include <netinet/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 #include <netdb.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
483 #else
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
484 #undef _WINSOCKAPI_
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
485 #include <winsock.h>
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
486 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 #include <pwd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 #define NOTOK (-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 #define OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 #define DONE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 FILE *sfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 FILE *sfo;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
497 char ibuffer[BUFSIZ];
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
498 char obuffer[BUFSIZ];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 char Errmsg[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
501 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
502 popmail (char *user, char *outfile, char *password)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 int nmsgs, nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 register int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 int mbfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 FILE *mbf;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
508 popserver server;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
510 server = pop_open (0, user, password, POP_NO_GETPASS);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
511 if (! server)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
513 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
514 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
517 if (pop_stat (server, &nmsgs, &nbytes))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
519 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
520 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if (!nmsgs)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
524 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
525 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
526 return (0);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
527 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 if (mbfi < 0)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
531 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
532 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
533 error ("Error in open: %s, %s", strerror (errno), outfile);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
534 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
535 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 213
diff changeset
536 #ifndef __CYGWIN32__
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 fchown (mbfi, getuid (), -1);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 213
diff changeset
538 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
540 if ((mbf = fdopen (mbfi, "wb")) == NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
542 pop_close (server);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
543 error ("Error in fdopen: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
544 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
545 unlink (outfile);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
546 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
549 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 mbx_delimit_begin (mbf);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
552 if (pop_retr (server, i, mbx_write, mbf) != OK)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
553 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
554 error (Errmsg, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
555 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
556 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
557 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 mbx_delimit_end (mbf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 fflush (mbf);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
560 if (ferror (mbf))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
561 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
562 error ("Error in fflush: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
563 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
564 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
565 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
566 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
569 /* On AFS, a call to write only modifies the file in the local
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
570 * workstation's AFS cache. The changes are not written to the server
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
571 * until a call to fsync or close is made. Users with AFS home
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
572 * directories have lost mail when over quota because these checks were
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
573 * not made in previous versions of movemail. */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
574
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
575 #ifdef BSD
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 if (fsync (mbfi) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
578 error ("Error in fsync: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
579 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
581 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 if (close (mbfi) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
585 error ("Error in close: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
586 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
589 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
591 if (pop_delete (server, i))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
592 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
593 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
594 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
595 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
596 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
599 if (pop_quit (server))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
600 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
601 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
602 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
603 }
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
604
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
608 static int
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
609 pop_retr (popserver server, int msgno, int (*action)(), void *arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
611 char *line;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
612 int ret;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
613
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
614 if (pop_retrieve_first (server, msgno, &line))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
615 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
616 strncpy (Errmsg, pop_error, sizeof (Errmsg));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
617 Errmsg[sizeof (Errmsg)-1] = '\0';
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
618 return (NOTOK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
620
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
621 while (! (ret = pop_retrieve_next (server, &line)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
622 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
623 if (! line)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
624 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
626 if ((*action)(line, arg) != OK)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
627 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
628 strcpy (Errmsg, strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
629 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
630 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
631 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
632 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
633
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
634 if (ret)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
635 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
636 strncpy (Errmsg, pop_error, sizeof (Errmsg));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
637 Errmsg[sizeof (Errmsg)-1] = '\0';
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
638 return (NOTOK);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
639 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
640
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
641 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
644 /* Do this as a macro instead of using strcmp to save on execution time. */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
645 #define IS_FROM_LINE(a) ((a[0] == 'F') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
646 && (a[1] == 'r') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
647 && (a[2] == 'o') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
648 && (a[3] == 'm') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
649 && (a[4] == ' '))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
651 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
652 mbx_write (char *line, FILE *mbf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
653 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
654 if (IS_FROM_LINE (line))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
655 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
656 if (fputc ('>', mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
657 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
658 }
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
659 if (fputs (line, mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
660 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
661 if (fputc (0x0a, mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
662 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
663 return (OK);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
664 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
665
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
666 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
667 mbx_delimit_begin (FILE *mbf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
668 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
669 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
670 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
671 return (OK);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
672 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
673
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
674 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
675 mbx_delimit_end (FILE *mbf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
676 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
677 if (putc ('\037', mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
678 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
679 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 #ifndef HAVE_STRERROR
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
685 static char *
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
686 strerror (int errnum)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 return (char *) "Unknown error";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 #endif /* ! HAVE_STRERROR */