annotate lib-src/movemail.c @ 157:6b37e6ddd302 r20-3b5

Import from CVS: tag r20-3b5
author cvs
date Mon, 13 Aug 2007 09:40:41 +0200
parents 43dd3413c7c7
children 0132846995bd
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"
122
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
65 #include <stdlib.h>
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
66 #include <string.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
67 #ifdef MAIL_USE_POP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
68 #include "pop.h"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
69 #endif
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
70
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #undef access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
75 #ifndef DIRECTORY_SEP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
76 #define DIRECTORY_SEP '/'
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
77 #endif
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
78 #ifndef IS_DIRECTORY_SEP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
79 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
80 #endif
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
81
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
82 #ifdef WINDOWSNT
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
83 #undef access
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
84 #undef unlink
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
85 #define fork() 0
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
86 #define sys_wait(var) (*(var) = 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
87 /* Unfortunately, Samba doesn't seem to properly lock Unix files even
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
88 though the locking call succeeds (and indeed blocks local access from
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
89 other NT programs). If you have direct file access using an NFS
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
90 client or something other than Samba, the locking call might work
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
91 properly - make sure it does before you enable this! */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
92 #define DISABLE_DIRECT_ACCESS
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
93 #endif /* WINDOWSNT */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
94
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
95 #ifdef USG
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
96 #include <fcntl.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 #include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #ifndef F_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 #define F_OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #define X_OK 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #define W_OK 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 #define R_OK 4
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
103 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
104 #endif /* USG */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
106 #ifdef HAVE_UNISTD_H
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
107 #include <unistd.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
108 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
110 #if defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #include <sys/locking.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #ifdef MAIL_USE_FLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 extern int lk_open (), lk_close ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 /* Cancel substitutions made by config.h for Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 #undef open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 #undef read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #undef write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 #undef close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
132 #ifndef errno
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
133 extern int errno;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #endif
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
135 char *strerror ();
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
136
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 122
diff changeset
137 void fatal (char *, char*);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
138 void error ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
139 void pfatal_with_name ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
140 void pfatal_and_delete ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
141 char *concat ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
142 long *xmalloc ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
143 int popmail ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
144 int pop_retr ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
145 int mbx_write ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
146 int mbx_delimit_begin ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
147 int mbx_delimit_end ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 /* 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
150 char *delete_lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
152 int
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
153 main (argc, argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
154 int argc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
155 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;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 int indesc, outdesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 int nread;
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
160 int status;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 long now;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 char *lockname, *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 char *tempname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 int desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 delete_lockname = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 if (argc < 3)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
174 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
175 fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n");
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
176 exit(1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
177 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 inname = argv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 outname = argv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 mmdf_init (argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
186 if (*outname == 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
187 fatal ("Destination file name is empty", 0);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
188
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 /* Check access to output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
193 /* Also check that outname's directory is writable to the real uid. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 char *buf = (char *) xmalloc (strlen (outname) + 1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
196 char *p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 strcpy (buf, outname);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
198 p = buf + strlen (buf);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
199 while (p > buf && !IS_DIRECTORY_SEP (p[-1]))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
200 *--p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
201 if (p == buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
202 *p++ = '.';
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 if (access (buf, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 pfatal_with_name (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 free (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #ifdef MAIL_USE_POP
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
209 if (!strncmp (inname, "po:", 3))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
211 int status;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
213 status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 exit (status);
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
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
414 void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
415 fatal (s1, s2)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
416 char *s1, *s2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 if (delete_lockname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 unlink (delete_lockname);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
420 error (s1, s2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
426 void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
427 error (s1, s2, s3)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
428 char *s1, *s2, *s3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
430 fprintf (stderr, "movemail: ");
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
431 fprintf (stderr, s1, s2, s3);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
432 fprintf (stderr, "\n");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
435 void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
436 pfatal_with_name (name)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
437 char *name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
439 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 }
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 void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
444 pfatal_and_delete (name)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
445 char *name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
447 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 unlink (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
454 char *
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
455 concat (s1, s2, s3)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
456 char *s1, *s2, *s3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 strcpy (result, s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 strcpy (result + len1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 strcpy (result + len1 + len2, s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 *(result + len1 + len2 + len3) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
471 long *
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
472 xmalloc (size)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
473 unsigned size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
475 long *result = (long *) malloc (size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 if (!result)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
477 fatal ("virtual memory exhausted", 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 /* This is the guts of the interface to the Post Office Protocol. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 #ifdef MAIL_USE_POP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
485 #ifndef WINDOWSNT
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #include <netinet/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 #include <netdb.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
489 #else
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
490 #undef _WINSOCKAPI_
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
491 #include <winsock.h>
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
492 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 #include <pwd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
496 #ifdef USG
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
497 #include <fcntl.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
498 /* Cancel substitutions made by config.h for Emacs. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
499 #undef open
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
500 #undef read
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
501 #undef write
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
502 #undef close
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
503 #endif /* USG */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
504
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 #define NOTOK (-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 #define OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 #define DONE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 FILE *sfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 FILE *sfo;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
512 char ibuffer[BUFSIZ];
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
513 char obuffer[BUFSIZ];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 char Errmsg[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
516 popmail (user, outfile, password)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
517 char *user;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
518 char *outfile;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
519 char *password;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 int nmsgs, nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 register int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 int mbfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 FILE *mbf;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
525 char *getenv ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
526 int mbx_write ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
527 popserver server;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
528 extern char *strerror ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
530 server = pop_open (0, user, password, POP_NO_GETPASS);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
531 if (! server)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
533 error (pop_error);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
534 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
537 if (pop_stat (server, &nmsgs, &nbytes))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
539 error (pop_error);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
540 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 if (!nmsgs)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
544 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
545 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
546 return (0);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
547 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 if (mbfi < 0)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
551 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
552 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
553 error ("Error in open: %s, %s", strerror (errno), outfile);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
554 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
555 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 fchown (mbfi, getuid (), -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
558 if ((mbf = fdopen (mbfi, "wb")) == NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
560 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
561 error ("Error in fdopen: %s", strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
562 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
563 unlink (outfile);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
564 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
567 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 mbx_delimit_begin (mbf);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
570 if (pop_retr (server, i, mbx_write, mbf) != OK)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
571 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
572 error (Errmsg);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
573 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
574 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
575 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 mbx_delimit_end (mbf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 fflush (mbf);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
578 if (ferror (mbf))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
579 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
580 error ("Error in fflush: %s", strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
581 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
582 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
583 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
584 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
587 /* 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
588 * workstation's AFS cache. The changes are not written to the server
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
589 * 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
590 * directories have lost mail when over quota because these checks were
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
591 * not made in previous versions of movemail. */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
592
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
593 #ifdef BSD
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 if (fsync (mbfi) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
596 error ("Error in fsync: %s", strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
597 return (1);
0
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 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 if (close (mbfi) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
603 error ("Error in close: %s", strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
604 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
607 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
609 if (pop_delete (server, i))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
610 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
611 error (pop_error);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
612 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
613 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
614 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
617 if (pop_quit (server))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
618 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
619 error (pop_error);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
620 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
621 }
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
622
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 }
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 pop_retr (server, msgno, action, arg)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
627 popserver server;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
628 int (*action)();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
630 extern char *strerror ();
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
631 char *line;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
632 int ret;
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 (pop_retrieve_first (server, msgno, &line))
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);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
640
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
641 while (! (ret = pop_retrieve_next (server, &line)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
642 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
643 if (! line)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
644 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
646 if ((*action)(line, arg) != OK)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
647 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
648 strcpy (Errmsg, strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
649 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
650 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
651 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
652 }
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 (ret)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
655 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
656 strncpy (Errmsg, pop_error, sizeof (Errmsg));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
657 Errmsg[sizeof (Errmsg)-1] = '\0';
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
658 return (NOTOK);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
659 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
660
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
661 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
664 /* 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
665 #define IS_FROM_LINE(a) ((a[0] == 'F') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
666 && (a[1] == 'r') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
667 && (a[2] == 'o') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
668 && (a[3] == 'm') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
669 && (a[4] == ' '))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
671 int
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
672 mbx_write (line, mbf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
673 char *line;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
674 FILE *mbf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
675 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
676 if (IS_FROM_LINE (line))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
677 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
678 if (fputc ('>', mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
679 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
680 }
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
681 if (fputs (line, mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
682 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
683 if (fputc (0x0a, mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
684 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
685 return (OK);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
686 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
687
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
688 int
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
689 mbx_delimit_begin (mbf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
690 FILE *mbf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
691 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
692 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
693 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
694 return (OK);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
695 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
696
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
697 mbx_delimit_end (mbf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
698 FILE *mbf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
699 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
700 if (putc ('\037', mbf) == EOF)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
701 return (NOTOK);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
702 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 #ifndef HAVE_STRERROR
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
708 char *
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
709 strerror (errnum)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
710 int errnum;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 return (char *) "Unknown error";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 #endif /* ! HAVE_STRERROR */