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