Mercurial > emacs
annotate lib-src/movemail.c @ 23648:06e645781762
(MAKE_NON_ASCII_CHAR): Check validity of CHARSET.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 06 Nov 1998 00:44:16 +0000 |
parents | 9917b9a0024d |
children | a2148e59e0eb |
rev | line source |
---|---|
23 | 1 /* movemail foo bar -- move file foo to file bar, |
2 locking file foo the way /bin/mail respects. | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
3 Copyright (C) 1986, 1992, 1993, 1994, 1996 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 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
20 Boston, MA 02111-1307, USA. */ |
23 | 21 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
22 /* 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 |
4eaef1578a15
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
447
diff
changeset
|
28 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
|
29 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
|
30 This means you must either give that directory access modes |
4eaef1578a15
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
447
diff
changeset
|
31 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
|
32 a setuid or setgid program. */ |
4eaef1578a15
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
447
diff
changeset
|
33 |
23 | 34 /* |
35 * Modified January, 1986 by Michael R. Gretzinger (Project Athena) | |
36 * | |
14649 | 37 * Added POP (Post Office Protocol) service. When compiled -DMAIL_USE_POP |
23 | 38 * movemail will accept input filename arguments of the form |
39 * "po:username". This will cause movemail to open a connection to | |
40 * a pop server running on $MAILHOST (environment variable). Movemail | |
41 * must be setuid to root in order to work with POP. | |
42 * | |
43 * New module: popmail.c | |
44 * Modified routines: | |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
45 * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ()) |
23 | 46 * after POP code. |
47 * New routines in movemail.c: | |
48 * get_errmsg - return pointer to system error message | |
49 * | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
50 * 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
|
51 * |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
52 * 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
|
53 * 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
|
54 * |
23 | 55 */ |
56 | |
8449
805f9284065b
Include config.h first thing.
Richard M. Stallman <rms@gnu.org>
parents:
6862
diff
changeset
|
57 #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
|
58 #include <../src/config.h> |
23 | 59 #include <sys/types.h> |
60 #include <sys/stat.h> | |
61 #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
|
62 #include <stdio.h> |
23 | 63 #include <errno.h> |
5435 | 64 #include <../src/syswait.h> |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
65 #include <getopt.h> |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
66 #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
|
67 #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
|
68 #endif |
23 | 69 |
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
70 #ifdef MSDOS |
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
71 #undef access |
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
72 #endif /* MSDOS */ |
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
73 |
15105
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
74 #ifndef DIRECTORY_SEP |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
75 #define DIRECTORY_SEP '/' |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
76 #endif |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
77 #ifndef IS_DIRECTORY_SEP |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
78 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP) |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
79 #endif |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
80 |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
81 #ifdef WINDOWSNT |
21905
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
82 #include "ntlib.h" |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
83 #undef access |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
84 #undef unlink |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
85 #define fork() 0 |
22316
95d38cf99591
(sys_wait): Rename to wait.
Andrew Innes <andrewi@gnu.org>
parents:
22235
diff
changeset
|
86 #define wait(var) (*(var) = 0) |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
87 /* Unfortunately, Samba doesn't seem to properly lock Unix files even |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
88 though the locking call succeeds (and indeed blocks local access from |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
89 other NT programs). If you have direct file access using an NFS |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
90 client or something other than Samba, the locking call might work |
21905
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
91 properly - make sure it does before you enable this! |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
92 |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
93 [18-Feb-97 andrewi] I now believe my comment above to be incorrect, |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
94 since it was based on a misunderstanding of how locking calls are |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
95 implemented and used on Unix. */ |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
96 //#define DISABLE_DIRECT_ACCESS |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
97 |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
98 /* Ensure all file i/o is in binary mode. */ |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
99 #include <fcntl.h> |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
100 int _fmode = _O_BINARY; |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
101 #endif /* WINDOWSNT */ |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
102 |
21390
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
103 /* Cancel substitutions made by config.h for Emacs. */ |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
104 #undef open |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
105 #undef read |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
106 #undef write |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
107 #undef close |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
108 |
23 | 109 #ifdef USG |
110 #include <fcntl.h> | |
111 #include <unistd.h> | |
27 | 112 #ifndef F_OK |
113 #define F_OK 0 | |
114 #define X_OK 1 | |
115 #define W_OK 2 | |
116 #define R_OK 4 | |
117 #endif | |
23 | 118 #endif /* USG */ |
119 | |
6862
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
120 #ifdef HAVE_UNISTD_H |
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
121 #include <unistd.h> |
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
122 #endif |
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
123 |
21390
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
124 #ifdef STDC_HEADERS |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
125 #include <stdlib.h> |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
126 #endif |
5ade0c90128e
Move cancelations up. Include <stdlib.h> if
Andreas Schwab <schwab@suse.de>
parents:
20760
diff
changeset
|
127 |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
128 #if defined (XENIX) || defined (WINDOWSNT) |
23 | 129 #include <sys/locking.h> |
130 #endif | |
131 | |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
132 #ifdef MAIL_USE_LOCKF |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
133 #define MAIL_USE_SYSTEM_LOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
134 #endif |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
135 |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
136 #ifdef MAIL_USE_FLOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
137 #define MAIL_USE_SYSTEM_LOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
138 #endif |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
139 |
25 | 140 #ifdef MAIL_USE_MMDF |
141 extern int lk_open (), lk_close (); | |
142 #endif | |
143 | |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
144 #if !defined (MAIL_USE_SYSTEM_LOCK) && !defined (MAIL_USE_MMDF) && \ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
145 defined (HAVE_LIBMAIL) && defined (HAVE_MAILLOCK_H) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
146 #include <maillock.h> |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
147 /* We can't use maillock unless we know what directory system mail |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
148 files appear in. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
149 #ifdef MAILDIR |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
150 #define MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
151 static char *mail_spool_name (); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
152 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
153 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
154 |
571 | 155 #ifndef errno |
23 | 156 extern int errno; |
571 | 157 #endif |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
158 char *strerror (); |
18626
d3d968d0773a
(rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
17069
diff
changeset
|
159 extern char *rindex (); |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
160 |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
161 void fatal (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
162 void error (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
163 void pfatal_with_name (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
164 void pfatal_and_delete (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
165 char *concat (); |
11675
496576df5d46
(xmalloc): Declare it to return long *.
Richard M. Stallman <rms@gnu.org>
parents:
10399
diff
changeset
|
166 long *xmalloc (); |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
167 int popmail (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
168 int pop_retr (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
169 int mbx_write (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
170 int mbx_delimit_begin (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
171 int mbx_delimit_end (); |
23 | 172 |
173 /* Nonzero means this is name of a lock file to delete on fatal error. */ | |
174 char *delete_lockname; | |
175 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
176 int |
23 | 177 main (argc, argv) |
178 int argc; | |
179 char **argv; | |
180 { | |
181 char *inname, *outname; | |
182 int indesc, outdesc; | |
183 int nread; | |
5435 | 184 WAITTYPE status; |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
185 int c, preserve_mail = 0; |
23 | 186 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
187 #ifndef MAIL_USE_SYSTEM_LOCK |
23 | 188 struct stat st; |
189 long now; | |
190 int tem; | |
191 char *lockname, *p; | |
601
3db1540d4b97
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
580
diff
changeset
|
192 char *tempname; |
23 | 193 int desc; |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
194 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
23 | 195 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
196 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
197 char *spool_name; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
198 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
199 |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
200 #ifdef MAIL_USE_POP |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
201 int pop_reverse_order = 0; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
202 # define ARGSTR "pr" |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
203 #else /* ! MAIL_USE_POP */ |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
204 # define ARGSTR "p" |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
205 #endif /* MAIL_USE_POP */ |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
206 |
23 | 207 delete_lockname = 0; |
208 | |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
209 while ((c = getopt (argc, argv, ARGSTR)) != EOF) |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
210 { |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
211 switch (c) { |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
212 #ifdef MAIL_USE_POP |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
213 case 'r': |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
214 pop_reverse_order = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
215 break; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
216 #endif |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
217 case 'p': |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
218 preserve_mail++; |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
219 break; |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
220 default: |
22235
ee90e9da3a70
Undo this previous change:
Richard M. Stallman <rms@gnu.org>
parents:
21905
diff
changeset
|
221 exit(1); |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
222 } |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
223 } |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
224 |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
225 if ( |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
226 #ifdef MAIL_USE_POP |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
227 (argc - optind < 2) || (argc - optind > 3) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
228 #else |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
229 (argc - optind != 2) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
230 #endif |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
231 ) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
232 { |
22235
ee90e9da3a70
Undo this previous change:
Richard M. Stallman <rms@gnu.org>
parents:
21905
diff
changeset
|
233 fprintf (stderr, "Usage: movemail [-p] inbox destfile%s\n", |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
234 #ifdef MAIL_USE_POP |
22235
ee90e9da3a70
Undo this previous change:
Richard M. Stallman <rms@gnu.org>
parents:
21905
diff
changeset
|
235 " [POP-password]" |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
236 #else |
22235
ee90e9da3a70
Undo this previous change:
Richard M. Stallman <rms@gnu.org>
parents:
21905
diff
changeset
|
237 "" |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
238 #endif |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
239 ); |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
240 exit (1); |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
241 } |
23 | 242 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
243 inname = argv[optind]; |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
244 outname = argv[optind+1]; |
23 | 245 |
25 | 246 #ifdef MAIL_USE_MMDF |
247 mmdf_init (argv[0]); | |
248 #endif | |
249 | |
12793
0464324deda7
(main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
12777
diff
changeset
|
250 if (*outname == 0) |
0464324deda7
(main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
12777
diff
changeset
|
251 fatal ("Destination file name is empty", 0); |
0464324deda7
(main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
12777
diff
changeset
|
252 |
120 | 253 /* Check access to output file. */ |
23 | 254 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) |
255 pfatal_with_name (outname); | |
256 | |
14036 | 257 /* Also check that outname's directory is writable to the real uid. */ |
23 | 258 { |
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
259 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
|
260 char *p; |
23 | 261 strcpy (buf, outname); |
262 p = buf + strlen (buf); | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
263 while (p > buf && !IS_DIRECTORY_SEP (p[-1])) |
23 | 264 *--p = 0; |
265 if (p == buf) | |
266 *p++ = '.'; | |
267 if (access (buf, W_OK) != 0) | |
268 pfatal_with_name (buf); | |
269 free (buf); | |
270 } | |
271 | |
272 #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
|
273 if (!strncmp (inname, "po:", 3)) |
23 | 274 { |
12442
981986d7d82f
(main) [MAIL_USE_POP]: When a user specifies a
Richard M. Stallman <rms@gnu.org>
parents:
12389
diff
changeset
|
275 int status; |
23 | 276 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
277 status = popmail (inname + 3, outname, preserve_mail, |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
278 (argc - optind == 3) ? argv[optind+2] : NULL, |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
279 pop_reverse_order); |
23 | 280 exit (status); |
281 } | |
282 | |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
283 setuid (getuid ()); |
23 | 284 #endif /* MAIL_USE_POP */ |
285 | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
286 #ifndef DISABLE_DIRECT_ACCESS |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
287 |
120 | 288 /* Check access to input file. */ |
289 if (access (inname, R_OK | W_OK) != 0) | |
290 pfatal_with_name (inname); | |
291 | |
25 | 292 #ifndef MAIL_USE_MMDF |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
293 #ifndef MAIL_USE_SYSTEM_LOCK |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
294 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
295 spool_name = mail_spool_name (inname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
296 if (! spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
297 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
298 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
299 /* Use a lock file named after our first argument with .lock appended: |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
300 If it exists, the mail file is locked. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
301 /* Note: this locking mechanism is *required* by the mailer |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
302 (on systems which use it) to prevent loss of mail. |
351
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
303 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
304 On systems that use a lock file, extracting the mail without locking |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
305 WILL occasionally cause loss of mail due to timing errors! |
351
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
306 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
307 So, if creation of the lock file fails |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
308 due to access permission on the mail spool directory, |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
309 you simply MUST change the permission |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
310 and/or make movemail a setgid program |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
311 so it can create lock files properly. |
351
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
312 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
313 You might also wish to verify that your system is one |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
314 which uses lock files for this purpose. Some systems use other methods. |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
315 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
316 If your system uses the `flock' system call for mail locking, |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
317 define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
318 and recompile movemail. If the s- file for your system |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
319 should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
320 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ |
23 | 321 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
322 lockname = concat (inname, ".lock", ""); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
323 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
324 strcpy (tempname, inname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
325 p = tempname + strlen (tempname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
326 while (p != tempname && !IS_DIRECTORY_SEP (p[-1])) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
327 p--; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
328 *p = 0; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
329 strcpy (p, "EXXXXXX"); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
330 mktemp (tempname); |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
331 unlink (tempname); |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
332 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
333 while (1) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
334 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
335 /* Create the lock file, but not under the lock file name. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
336 /* Give up if cannot do that. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
337 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
338 if (desc < 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
339 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
340 char *message = (char *) xmalloc (strlen (tempname) + 50); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
341 sprintf (message, "%s--see source file lib-src/movemail.c", |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
342 tempname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
343 pfatal_with_name (message); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
344 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
345 close (desc); |
23 | 346 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
347 tem = link (tempname, lockname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
348 unlink (tempname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
349 if (tem >= 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
350 break; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
351 sleep (1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
352 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
353 /* If lock file is five minutes old, unlock it. |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
354 Five minutes should be good enough to cope with crashes |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
355 and wedgitude, and long enough to avoid being fooled |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
356 by time differences between machines. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
357 if (stat (lockname, &st) >= 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
358 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
359 now = time (0); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
360 if (st.st_ctime < now - 300) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
361 unlink (lockname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
362 } |
23 | 363 } |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
364 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
365 delete_lockname = lockname; |
23 | 366 } |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
367 #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
|
368 #endif /* not MAIL_USE_MMDF */ |
23 | 369 |
5435 | 370 if (fork () == 0) |
371 { | |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
372 int lockcount = 0; |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
373 int status = 0; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
374 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
375 long touched_lock, now; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
376 #endif |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
377 |
6813
76f93e487956
(main): Use setuid, not seteuid.
Karl Heuer <kwzh@gnu.org>
parents:
6690
diff
changeset
|
378 setuid (getuid ()); |
5435 | 379 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
380 #ifndef MAIL_USE_MMDF |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
381 #ifdef MAIL_USE_SYSTEM_LOCK |
5435 | 382 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
|
383 #else /* if not MAIL_USE_SYSTEM_LOCK */ |
5435 | 384 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
|
385 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
5435 | 386 #else /* MAIL_USE_MMDF */ |
387 indesc = lk_open (inname, O_RDONLY, 0, 0, 10); | |
25 | 388 #endif /* MAIL_USE_MMDF */ |
389 | |
5435 | 390 if (indesc < 0) |
391 pfatal_with_name (inname); | |
23 | 392 |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
15105
diff
changeset
|
393 #if defined (BSD_SYSTEM) || defined (XENIX) |
5435 | 394 /* In case movemail is setuid to root, make sure the user can |
395 read the output file. */ | |
396 /* This is desirable for all systems | |
397 but I don't want to assume all have the umask system call */ | |
398 umask (umask (0) & 0333); | |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
15105
diff
changeset
|
399 #endif /* BSD_SYSTEM || XENIX */ |
5435 | 400 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
401 if (outdesc < 0) | |
402 pfatal_with_name (outname); | |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
403 |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
404 /* This label exists so we can retry locking |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
405 after a delay, if it got EAGAIN or EBUSY. */ |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
406 retry_lock: |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
407 |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
408 /* Try to lock it. */ |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
409 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
410 if (spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
411 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
412 /* The "0 - " is to make it a negative number if maillock returns |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
413 non-zero. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
414 status = 0 - maillock (spool_name, 1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
415 #ifdef HAVE_TOUCHLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
416 touched_lock = time (0); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
417 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
418 lockcount = 5; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
419 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
420 else |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
421 #endif /* MAIL_USE_MAILLOCK */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
422 { |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
423 #ifdef MAIL_USE_SYSTEM_LOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
424 #ifdef MAIL_USE_LOCKF |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
425 status = lockf (indesc, F_LOCK, 0); |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
426 #else /* not MAIL_USE_LOCKF */ |
23 | 427 #ifdef XENIX |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
428 status = locking (indesc, LK_RLCK, 0L); |
23 | 429 #else |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
430 #ifdef WINDOWSNT |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
431 status = locking (indesc, LK_RLCK, -1L); |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
432 #else |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
433 status = flock (indesc, LOCK_EX); |
23 | 434 #endif |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
435 #endif |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
436 #endif /* not MAIL_USE_LOCKF */ |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
437 #endif /* MAIL_USE_SYSTEM_LOCK */ |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
438 } |
23 | 439 |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
440 /* If it fails, retry up to 5 times |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
441 for certain failure codes. */ |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
442 if (status < 0) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
443 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
444 if (++lockcount <= 5) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
445 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
446 #ifdef EAGAIN |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
447 if (errno == EAGAIN) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
448 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
449 sleep (1); |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
450 goto retry_lock; |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
451 } |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
452 #endif |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
453 #ifdef EBUSY |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
454 if (errno == EBUSY) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
455 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
456 sleep (1); |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
457 goto retry_lock; |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
458 } |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
459 #endif |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
460 } |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
461 |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
462 pfatal_with_name (inname); |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
463 } |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
464 |
5435 | 465 { |
466 char buf[1024]; | |
604 | 467 |
5435 | 468 while (1) |
604 | 469 { |
5435 | 470 nread = read (indesc, buf, sizeof buf); |
471 if (nread != write (outdesc, buf, nread)) | |
472 { | |
473 int saved_errno = errno; | |
474 unlink (outname); | |
475 errno = saved_errno; | |
476 pfatal_with_name (outname); | |
477 } | |
478 if (nread < sizeof buf) | |
479 break; | |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
480 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
481 if (spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
482 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
483 now = time (0); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
484 if (now - touched_lock > 60) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
485 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
486 touchlock (); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
487 touched_lock = now; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
488 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
489 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
490 #endif /* MAIL_USE_MAILLOCK */ |
604 | 491 } |
492 } | |
23 | 493 |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
15105
diff
changeset
|
494 #ifdef BSD_SYSTEM |
5435 | 495 if (fsync (outdesc) < 0) |
496 pfatal_and_delete (outname); | |
23 | 497 #endif |
498 | |
5435 | 499 /* Check to make sure no errors before we zap the inbox. */ |
500 if (close (outdesc) != 0) | |
501 pfatal_and_delete (outname); | |
23 | 502 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
503 #ifdef MAIL_USE_SYSTEM_LOCK |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
504 if (! preserve_mail) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
505 { |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
506 #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT) |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
507 /* Stride, xenix have file locking, but no ftruncate. |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
508 This mess will do. */ |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
509 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); |
23 | 510 #else |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
511 ftruncate (indesc, 0L); |
20760
4f1f4b226cb0
(main): Fix interwoven brace and cpp conditional nesting.
Andreas Schwab <schwab@suse.de>
parents:
20418
diff
changeset
|
512 #endif /* STRIDE or XENIX */ |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
513 } |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
514 #endif /* MAIL_USE_SYSTEM_LOCK */ |
25 | 515 |
516 #ifdef MAIL_USE_MMDF | |
5435 | 517 lk_close (indesc, 0, 0, 0); |
25 | 518 #else |
5435 | 519 close (indesc); |
25 | 520 #endif |
23 | 521 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
522 #ifndef MAIL_USE_SYSTEM_LOCK |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
523 if (! preserve_mail) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
524 { |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
525 /* Delete the input file; if we can't, at least get rid of its |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
526 contents. */ |
571 | 527 #ifdef MAIL_UNLINK_SPOOL |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
528 /* This is generally bad to do, because it destroys the permissions |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
529 that were set on the file. Better to just empty the file. */ |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
530 if (unlink (inname) < 0 && errno != ENOENT) |
571 | 531 #endif /* MAIL_UNLINK_SPOOL */ |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
532 creat (inname, 0600); |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
533 } |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
534 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
5435 | 535 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
536 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
537 /* This has to occur in the child, i.e., in the process that |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
538 acquired the lock! */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
539 if (spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
540 mailunlock (); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
541 #endif |
5435 | 542 exit (0); |
543 } | |
544 | |
545 wait (&status); | |
546 if (!WIFEXITED (status)) | |
547 exit (1); | |
548 else if (WRETCODE (status) != 0) | |
549 exit (WRETCODE (status)); | |
550 | |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
551 #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
552 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
553 if (! spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
554 #endif /* MAIL_USE_MAILLOCK */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
555 unlink (lockname); |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
556 #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
557 |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
558 #endif /* ! DISABLE_DIRECT_ACCESS */ |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
559 |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
560 return 0; |
23 | 561 } |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
562 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
563 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
564 /* This function uses stat to confirm that the mail directory is |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
565 identical to the directory of the input file, rather than just |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
566 string-comparing the two paths, because one or both of them might |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
567 be symbolic links pointing to some other directory. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
568 static char * |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
569 mail_spool_name (inname) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
570 char *inname; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
571 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
572 struct stat stat1, stat2; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
573 char *indir, *fname; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
574 int status; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
575 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
576 if (! (fname = rindex (inname, '/'))) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
577 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
578 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
579 fname++; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
580 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
581 if (stat (MAILDIR, &stat1) < 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
582 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
583 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
584 indir = (char *) xmalloc (fname - inname + 1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
585 strncpy (indir, inname, fname - inname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
586 indir[fname-inname] = '\0'; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
587 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
588 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
589 status = stat (indir, &stat2); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
590 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
591 free (indir); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
592 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
593 if (status < 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
594 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
595 |
18626
d3d968d0773a
(rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
17069
diff
changeset
|
596 if (stat1.st_dev == stat2.st_dev |
d3d968d0773a
(rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
17069
diff
changeset
|
597 && stat1.st_ino == stat2.st_ino) |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
598 return fname; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
599 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
600 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
601 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
602 #endif /* MAIL_USE_MAILLOCK */ |
23 | 603 |
604 /* Print error message and exit. */ | |
605 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
606 void |
23 | 607 fatal (s1, s2) |
608 char *s1, *s2; | |
609 { | |
610 if (delete_lockname) | |
611 unlink (delete_lockname); | |
612 error (s1, s2); | |
613 exit (1); | |
614 } | |
615 | |
616 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | |
617 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
618 void |
120 | 619 error (s1, s2, s3) |
620 char *s1, *s2, *s3; | |
23 | 621 { |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
622 fprintf (stderr, "movemail: "); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
623 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
|
624 fprintf (stderr, "\n"); |
23 | 625 } |
626 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
627 void |
23 | 628 pfatal_with_name (name) |
629 char *name; | |
630 { | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
631 char *s = concat ("", strerror (errno), " for %s"); |
23 | 632 fatal (s, name); |
633 } | |
634 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
635 void |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
636 pfatal_and_delete (name) |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
637 char *name; |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
638 { |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
639 char *s = concat ("", strerror (errno), " for %s"); |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
640 unlink (name); |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
641 fatal (s, name); |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
642 } |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
643 |
23 | 644 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ |
645 | |
646 char * | |
647 concat (s1, s2, s3) | |
648 char *s1, *s2, *s3; | |
649 { | |
650 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | |
651 char *result = (char *) xmalloc (len1 + len2 + len3 + 1); | |
652 | |
653 strcpy (result, s1); | |
654 strcpy (result + len1, s2); | |
655 strcpy (result + len1 + len2, s3); | |
656 *(result + len1 + len2 + len3) = 0; | |
657 | |
658 return result; | |
659 } | |
660 | |
661 /* Like malloc but get fatal error if memory is exhausted. */ | |
662 | |
11675
496576df5d46
(xmalloc): Declare it to return long *.
Richard M. Stallman <rms@gnu.org>
parents:
10399
diff
changeset
|
663 long * |
23 | 664 xmalloc (size) |
571 | 665 unsigned size; |
23 | 666 { |
11675
496576df5d46
(xmalloc): Declare it to return long *.
Richard M. Stallman <rms@gnu.org>
parents:
10399
diff
changeset
|
667 long *result = (long *) malloc (size); |
23 | 668 if (!result) |
669 fatal ("virtual memory exhausted", 0); | |
670 return result; | |
671 } | |
672 | |
673 /* This is the guts of the interface to the Post Office Protocol. */ | |
674 | |
675 #ifdef MAIL_USE_POP | |
676 | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
677 #ifndef WINDOWSNT |
23 | 678 #include <sys/socket.h> |
679 #include <netinet/in.h> | |
680 #include <netdb.h> | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
681 #else |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
682 #undef _WINSOCKAPI_ |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
683 #include <winsock.h> |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
684 #endif |
634
52d0ff659265
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
604
diff
changeset
|
685 #include <pwd.h> |
23 | 686 |
687 #define NOTOK (-1) | |
688 #define OK 0 | |
689 #define DONE 1 | |
690 | |
691 char *progname; | |
692 FILE *sfi; | |
693 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
|
694 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
|
695 char obuffer[BUFSIZ]; |
23 | 696 char Errmsg[80]; |
697 | |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
698 popmail (user, outfile, preserve, password, reverse_order) |
120 | 699 char *user; |
700 char *outfile; | |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
701 int preserve; |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
702 char *password; |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
703 int reverse_order; |
23 | 704 { |
120 | 705 int nmsgs, nbytes; |
706 register int i; | |
707 int mbfi; | |
708 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
|
709 char *getenv (); |
9630
5410efcb7b6e
PopServer renamed to popserver throughout.
Richard M. Stallman <rms@gnu.org>
parents:
9612
diff
changeset
|
710 popserver server; |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
711 int start, end, increment; |
23 | 712 |
22235
ee90e9da3a70
Undo this previous change:
Richard M. Stallman <rms@gnu.org>
parents:
21905
diff
changeset
|
713 server = pop_open (0, user, password, POP_NO_GETPASS); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
714 if (! server) |
120 | 715 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
716 error ("Error connecting to POP server: %s", pop_error); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
717 return (1); |
23 | 718 } |
719 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
720 if (pop_stat (server, &nmsgs, &nbytes)) |
120 | 721 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
722 error ("Error getting message count from POP server: %s", pop_error); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
723 return (1); |
120 | 724 } |
23 | 725 |
120 | 726 if (!nmsgs) |
727 { | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
728 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
|
729 return (0); |
23 | 730 } |
731 | |
120 | 732 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666); |
733 if (mbfi < 0) | |
734 { | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
735 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
|
736 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
|
737 return (1); |
120 | 738 } |
739 fchown (mbfi, getuid (), -1); | |
740 | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
741 if ((mbf = fdopen (mbfi, "wb")) == NULL) |
120 | 742 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
743 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
|
744 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
|
745 close (mbfi); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
746 unlink (outfile); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
747 return (1); |
120 | 748 } |
749 | |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
750 if (reverse_order) |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
751 { |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
752 start = nmsgs; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
753 end = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
754 increment = -1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
755 } |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
756 else |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
757 { |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
758 start = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
759 end = nmsgs; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
760 increment = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
761 } |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
762 |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
763 for (i = start; i * increment <= end * increment; i += increment) |
120 | 764 { |
765 mbx_delimit_begin (mbf); | |
17069
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
766 if (pop_retr (server, i, mbf) != OK) |
120 | 767 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
768 error (Errmsg); |
120 | 769 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
|
770 return (1); |
120 | 771 } |
772 mbx_delimit_end (mbf); | |
773 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
|
774 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
|
775 { |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
776 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
|
777 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
|
778 close (mbfi); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
779 return (1); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
780 } |
120 | 781 } |
782 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
783 /* 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
|
784 * 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
|
785 * 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
|
786 * 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
|
787 * 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
|
788 |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
15105
diff
changeset
|
789 #ifdef BSD_SYSTEM |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
790 if (fsync (mbfi) < 0) |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
791 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
792 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
|
793 return (1); |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
794 } |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
9490
diff
changeset
|
795 #endif |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
796 |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
797 if (close (mbfi) == -1) |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
798 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
799 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
|
800 return (1); |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
801 } |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
802 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
803 if (! preserve) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
804 for (i = 1; i <= nmsgs; i++) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
805 { |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
806 if (pop_delete (server, i)) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
807 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
808 error ("Error from POP server: %s", pop_error); |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
809 pop_close (server); |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
810 return (1); |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
811 } |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
812 } |
23 | 813 |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
814 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
|
815 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
816 error ("Error from POP server: %s", pop_error); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
817 return (1); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
818 } |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
819 |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
820 return (0); |
23 | 821 } |
822 | |
17069
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
823 int |
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
824 pop_retr (server, msgno, arg) |
9630
5410efcb7b6e
PopServer renamed to popserver throughout.
Richard M. Stallman <rms@gnu.org>
parents:
9612
diff
changeset
|
825 popserver server; |
17069
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
826 FILE *arg; |
23 | 827 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
828 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
|
829 char *line; |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
830 int ret; |
23 | 831 |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
832 if (pop_retrieve_first (server, msgno, &line)) |
120 | 833 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
834 char *error = concat ("Error from POP server: ", pop_error, ""); |
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
835 strncpy (Errmsg, error, sizeof (Errmsg)); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
836 Errmsg[sizeof (Errmsg)-1] = '\0'; |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
837 free(error); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
838 return (NOTOK); |
23 | 839 } |
840 | |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
841 while ((ret = pop_retrieve_next (server, &line)) >= 0) |
120 | 842 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
843 if (! line) |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
844 break; |
23 | 845 |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
846 if (mbx_write (line, ret, arg) != OK) |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
847 { |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
848 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
|
849 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
|
850 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
851 } |
23 | 852 } |
853 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
854 if (ret) |
120 | 855 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
856 char *error = concat ("Error from POP server: ", pop_error, ""); |
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
857 strncpy (Errmsg, error, sizeof (Errmsg)); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
858 Errmsg[sizeof (Errmsg)-1] = '\0'; |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
859 free(error); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
860 return (NOTOK); |
23 | 861 } |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
862 |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
863 return (OK); |
23 | 864 } |
865 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
866 /* 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
|
867 #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
|
868 && (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
|
869 && (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
|
870 && (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
|
871 && (a[4] == ' ')) |
23 | 872 |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
873 int |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
874 mbx_write (line, len, mbf) |
120 | 875 char *line; |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
876 int len; |
120 | 877 FILE *mbf; |
23 | 878 { |
20387
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
879 #ifdef MOVEMAIL_QUOTE_POP_FROM_LINES |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
880 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
|
881 { |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
882 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
|
883 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
884 } |
20387
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
885 #endif |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
886 if (line[0] == '\037') |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
887 { |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
888 if (fputs ("^_", mbf) == EOF) |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
889 return (NOTOK); |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
890 line++; |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
891 len--; |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
892 } |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
893 if (fwrite (line, 1, len, mbf) != len) |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
894 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
895 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
|
896 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
897 return (OK); |
23 | 898 } |
899 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
900 int |
120 | 901 mbx_delimit_begin (mbf) |
902 FILE *mbf; | |
23 | 903 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
904 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
|
905 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
906 return (OK); |
23 | 907 } |
908 | |
120 | 909 mbx_delimit_end (mbf) |
910 FILE *mbf; | |
23 | 911 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
912 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
|
913 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
914 return (OK); |
23 | 915 } |
916 | |
917 #endif /* MAIL_USE_POP */ | |
5532
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
918 |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
919 #ifndef HAVE_STRERROR |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
920 char * |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
921 strerror (errnum) |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
922 int errnum; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
923 { |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
924 extern char *sys_errlist[]; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
925 extern int sys_nerr; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
926 |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
927 if (errnum >= 0 && errnum < sys_nerr) |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
928 return sys_errlist[errnum]; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
929 return (char *) "Unknown error"; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
930 } |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
931 |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
932 #endif /* ! HAVE_STRERROR */ |