Mercurial > emacs
annotate lib-src/movemail.c @ 101076:6c4177798438
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 10 Jan 2009 21:13:02 +0000 |
parents | a9f7e446141d |
children | 091a8cf73243 |
rev | line source |
---|---|
23 | 1 /* movemail foo bar -- move file foo to file bar, |
2 locking file foo the way /bin/mail respects. | |
75250
6d19c76d81c5
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
70280
diff
changeset
|
3 Copyright (C) 1986, 1992, 1993, 1994, 1996, 1999, 2001, 2002, 2003, 2004, |
100958 | 4 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
23 | 5 |
6 This file is part of GNU Emacs. | |
7 | |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
8 GNU Emacs is free software: you can redistribute it and/or modify |
38 | 9 it under the terms of the GNU General Public License as published by |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
11 (at your option) any later version. |
23 | 12 |
38 | 13 GNU Emacs is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92159
diff
changeset
|
20 |
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. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48314
diff
changeset
|
42 * |
23 | 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 ()) |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48314
diff
changeset
|
46 * after POP code. |
23 | 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 | |
29046
7d5565d3cf32
Include config.h, not ../src/config.h.
Dave Love <fx@gnu.org>
parents:
27507
diff
changeset
|
57 #include <config.h> |
23 | 58 #include <sys/types.h> |
59 #include <sys/stat.h> | |
60 #include <sys/file.h> | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
61 #include <stdio.h> |
23 | 62 #include <errno.h> |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
63 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
64 #include <getopt.h> |
31317
d431eeb4028f
(toplevel): Remove redundant <fcntl.h>. Provide definitions for F_OK
Eli Zaretskii <eliz@gnu.org>
parents:
31274
diff
changeset
|
65 #ifdef HAVE_UNISTD_H |
d431eeb4028f
(toplevel): Remove redundant <fcntl.h>. Provide definitions for F_OK
Eli Zaretskii <eliz@gnu.org>
parents:
31274
diff
changeset
|
66 #include <unistd.h> |
d431eeb4028f
(toplevel): Remove redundant <fcntl.h>. Provide definitions for F_OK
Eli Zaretskii <eliz@gnu.org>
parents:
31274
diff
changeset
|
67 #endif |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
68 #ifdef HAVE_FCNTL_H |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
69 #include <fcntl.h> |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
70 #endif |
31317
d431eeb4028f
(toplevel): Remove redundant <fcntl.h>. Provide definitions for F_OK
Eli Zaretskii <eliz@gnu.org>
parents:
31274
diff
changeset
|
71 #include "syswait.h" |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
72 #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
|
73 #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
|
74 #endif |
23 | 75 |
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
76 #ifdef MSDOS |
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
77 #undef access |
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
78 #endif /* MSDOS */ |
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
79 |
15105
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
80 #ifndef DIRECTORY_SEP |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
81 #define DIRECTORY_SEP '/' |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
82 #endif |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
83 #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
|
84 #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
|
85 #endif |
328889a58f6d
(DIRECTORY_SEP, IS_DIRECTORY_SEP): Definitions copied from lisp.h.
Richard M. Stallman <rms@gnu.org>
parents:
15101
diff
changeset
|
86 |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
87 #ifdef WINDOWSNT |
21905
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
88 #include "ntlib.h" |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
89 #undef access |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
90 #undef unlink |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
91 #define fork() 0 |
22316
95d38cf99591
(sys_wait): Rename to wait.
Andrew Innes <andrewi@gnu.org>
parents:
22235
diff
changeset
|
92 #define wait(var) (*(var) = 0) |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
93 /* 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
99 [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
|
100 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
|
101 implemented and used on Unix. */ |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
102 //#define DISABLE_DIRECT_ACCESS |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
103 |
b1e64615e700
[WINDOWSNT]: Undefine DISABLE_DIRECT_ACCESS. Force
Richard M. Stallman <rms@gnu.org>
parents:
21396
diff
changeset
|
104 #include <fcntl.h> |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
105 #endif /* WINDOWSNT */ |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
106 |
27 | 107 #ifndef F_OK |
108 #define F_OK 0 | |
109 #define X_OK 1 | |
110 #define W_OK 2 | |
111 #define R_OK 4 | |
112 #endif | |
23 | 113 |
87833
36e4ffad31fe
* movemail.c: Remove references to XENIX.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87730
diff
changeset
|
114 #ifdef WINDOWSNT |
23 | 115 #include <sys/locking.h> |
116 #endif | |
117 | |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
118 #ifdef MAIL_USE_LOCKF |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
119 #define MAIL_USE_SYSTEM_LOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
120 #endif |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
121 |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
122 #ifdef MAIL_USE_FLOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
123 #define MAIL_USE_SYSTEM_LOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
124 #endif |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
125 |
25 | 126 #ifdef MAIL_USE_MMDF |
127 extern int lk_open (), lk_close (); | |
128 #endif | |
129 | |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
130 #if !defined (MAIL_USE_SYSTEM_LOCK) && !defined (MAIL_USE_MMDF) && \ |
51112
b0811540692f
Check HAVE_LIBLOCKFILE like HAVE_LIBMAIL.
Dave Love <fx@gnu.org>
parents:
49600
diff
changeset
|
131 (defined (HAVE_LIBMAIL) || defined (HAVE_LIBLOCKFILE)) && \ |
b0811540692f
Check HAVE_LIBLOCKFILE like HAVE_LIBMAIL.
Dave Love <fx@gnu.org>
parents:
49600
diff
changeset
|
132 defined (HAVE_MAILLOCK_H) |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
133 #include <maillock.h> |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
134 /* 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
|
135 files appear in. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
136 #ifdef MAILDIR |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
137 #define MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
138 static char *mail_spool_name (); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
139 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
140 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
141 |
571 | 142 #ifndef errno |
23 | 143 extern int errno; |
571 | 144 #endif |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
145 char *strerror (); |
31376
f5cd669613d2
(index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents:
31317
diff
changeset
|
146 #ifdef HAVE_INDEX |
f5cd669613d2
(index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents:
31317
diff
changeset
|
147 extern char *index __P ((const char *, int)); |
f5cd669613d2
(index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents:
31317
diff
changeset
|
148 #endif |
f5cd669613d2
(index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents:
31317
diff
changeset
|
149 #ifdef HAVE_RINDEX |
f5cd669613d2
(index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents:
31317
diff
changeset
|
150 extern char *rindex __P((const char *, int)); |
f5cd669613d2
(index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents:
31317
diff
changeset
|
151 #endif |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
152 |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
153 void fatal (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
154 void error (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
155 void pfatal_with_name (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
156 void pfatal_and_delete (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
157 char *concat (); |
11675
496576df5d46
(xmalloc): Declare it to return long *.
Richard M. Stallman <rms@gnu.org>
parents:
10399
diff
changeset
|
158 long *xmalloc (); |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
159 int popmail (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
160 int pop_retr (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
161 int mbx_write (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
162 int mbx_delimit_begin (); |
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
163 int mbx_delimit_end (); |
23 | 164 |
165 /* Nonzero means this is name of a lock file to delete on fatal error. */ | |
166 char *delete_lockname; | |
167 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
168 int |
23 | 169 main (argc, argv) |
170 int argc; | |
171 char **argv; | |
172 { | |
173 char *inname, *outname; | |
174 int indesc, outdesc; | |
175 int nread; | |
96620
3bea8ede5bd0
* syswait.h: Remove old if 0 code. Do not define WAITTYPE, it was
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94828
diff
changeset
|
176 int status; |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
177 int c, preserve_mail = 0; |
23 | 178 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
179 #ifndef MAIL_USE_SYSTEM_LOCK |
23 | 180 struct stat st; |
181 long now; | |
182 int tem; | |
183 char *lockname, *p; | |
601
3db1540d4b97
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
580
diff
changeset
|
184 char *tempname; |
23 | 185 int desc; |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
186 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
23 | 187 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
188 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
189 char *spool_name; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
190 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
191 |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
192 #ifdef MAIL_USE_POP |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
193 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
|
194 # define ARGSTR "pr" |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
195 #else /* ! MAIL_USE_POP */ |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
196 # define ARGSTR "p" |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
197 #endif /* MAIL_USE_POP */ |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
198 |
31080
7ae519dba237
(main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents:
29046
diff
changeset
|
199 #ifdef WINDOWSNT |
7ae519dba237
(main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents:
29046
diff
changeset
|
200 /* Ensure all file i/o is in binary mode. */ |
7ae519dba237
(main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents:
29046
diff
changeset
|
201 _fmode = _O_BINARY; |
7ae519dba237
(main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents:
29046
diff
changeset
|
202 #endif |
7ae519dba237
(main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents:
29046
diff
changeset
|
203 |
23 | 204 delete_lockname = 0; |
205 | |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
206 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
|
207 { |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
208 switch (c) { |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
209 #ifdef MAIL_USE_POP |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
210 case 'r': |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
211 pop_reverse_order = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
212 break; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
213 #endif |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
214 case 'p': |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
215 preserve_mail++; |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
216 break; |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
217 default: |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
218 exit (EXIT_FAILURE); |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
219 } |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
220 } |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
221 |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
222 if ( |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
223 #ifdef MAIL_USE_POP |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
224 (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
|
225 #else |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
226 (argc - optind != 2) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
227 #endif |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
228 ) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
229 { |
52069
76d453ac3c4f
(main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents:
51112
diff
changeset
|
230 #ifdef MAIL_USE_POP |
22235
ee90e9da3a70
Undo this previous change:
Richard M. Stallman <rms@gnu.org>
parents:
21905
diff
changeset
|
231 fprintf (stderr, "Usage: movemail [-p] inbox destfile%s\n", |
52069
76d453ac3c4f
(main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents:
51112
diff
changeset
|
232 " [POP-password]"); |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
233 #else |
52069
76d453ac3c4f
(main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents:
51112
diff
changeset
|
234 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
|
235 #endif |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
236 exit (EXIT_FAILURE); |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
237 } |
23 | 238 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
239 inname = argv[optind]; |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
240 outname = argv[optind+1]; |
23 | 241 |
25 | 242 #ifdef MAIL_USE_MMDF |
243 mmdf_init (argv[0]); | |
244 #endif | |
245 | |
12793
0464324deda7
(main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
12777
diff
changeset
|
246 if (*outname == 0) |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
247 fatal ("Destination file name is empty", 0, 0); |
12793
0464324deda7
(main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
12777
diff
changeset
|
248 |
120 | 249 /* Check access to output file. */ |
23 | 250 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) |
251 pfatal_with_name (outname); | |
252 | |
14036 | 253 /* Also check that outname's directory is writable to the real uid. */ |
23 | 254 { |
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
255 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
|
256 char *p; |
23 | 257 strcpy (buf, outname); |
258 p = buf + strlen (buf); | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
259 while (p > buf && !IS_DIRECTORY_SEP (p[-1])) |
23 | 260 *--p = 0; |
261 if (p == buf) | |
262 *p++ = '.'; | |
263 if (access (buf, W_OK) != 0) | |
264 pfatal_with_name (buf); | |
265 free (buf); | |
266 } | |
267 | |
268 #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
|
269 if (!strncmp (inname, "po:", 3)) |
23 | 270 { |
12442
981986d7d82f
(main) [MAIL_USE_POP]: When a user specifies a
Richard M. Stallman <rms@gnu.org>
parents:
12389
diff
changeset
|
271 int status; |
23 | 272 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
273 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
|
274 (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
|
275 pop_reverse_order); |
23 | 276 exit (status); |
277 } | |
278 | |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
279 setuid (getuid ()); |
23 | 280 #endif /* MAIL_USE_POP */ |
281 | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
282 #ifndef DISABLE_DIRECT_ACCESS |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
283 |
120 | 284 /* Check access to input file. */ |
285 if (access (inname, R_OK | W_OK) != 0) | |
286 pfatal_with_name (inname); | |
287 | |
25 | 288 #ifndef MAIL_USE_MMDF |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
289 #ifndef MAIL_USE_SYSTEM_LOCK |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
290 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
291 spool_name = mail_spool_name (inname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
292 if (! spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
293 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
294 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
295 /* 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
|
296 If it exists, the mail file is locked. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
297 /* Note: this locking mechanism is *required* by the mailer |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
298 (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
|
299 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
300 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
|
301 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
|
302 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
303 So, if creation of the lock file fails |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
304 due to access permission on the mail spool directory, |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
305 you simply MUST change the permission |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
306 and/or make movemail a setgid program |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
307 so it can create lock files properly. |
351
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
308 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
309 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
|
310 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
|
311 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */ |
23 | 317 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
318 lockname = concat (inname, ".lock", ""); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
319 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
320 strcpy (tempname, inname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
321 p = tempname + strlen (tempname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
322 while (p != tempname && !IS_DIRECTORY_SEP (p[-1])) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
323 p--; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
324 *p = 0; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
325 strcpy (p, "EXXXXXX"); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
326 mktemp (tempname); |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
327 unlink (tempname); |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
328 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
329 while (1) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
330 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
331 /* 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
|
332 /* Give up if cannot do that. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
333 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
|
334 if (desc < 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
335 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
336 char *message = (char *) xmalloc (strlen (tempname) + 50); |
27507 | 337 sprintf (message, "creating %s, which would become the lock file", |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
338 tempname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
339 pfatal_with_name (message); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
340 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
341 close (desc); |
23 | 342 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
343 tem = link (tempname, lockname); |
100823
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
344 |
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
345 #ifdef EPERM |
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
346 if (tem < 0 && errno == EPERM) |
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
347 fatal ("Unable to create hard link between %s and %s", |
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
348 tempname, lockname); |
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
349 #endif |
d893844c75a7
(main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents:
96620
diff
changeset
|
350 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
351 unlink (tempname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
352 if (tem >= 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
353 break; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
354 sleep (1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
355 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
356 /* If lock file is five minutes old, unlock it. |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
357 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
|
358 and wedgitude, and long enough to avoid being fooled |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
359 by time differences between machines. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
360 if (stat (lockname, &st) >= 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
361 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
362 now = time (0); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
363 if (st.st_ctime < now - 300) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
364 unlink (lockname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
365 } |
23 | 366 } |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
367 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
368 delete_lockname = lockname; |
23 | 369 } |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
370 #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
|
371 #endif /* not MAIL_USE_MMDF */ |
23 | 372 |
5435 | 373 if (fork () == 0) |
374 { | |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
375 int lockcount = 0; |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
376 int status = 0; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
377 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
378 long touched_lock, now; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
379 #endif |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
380 |
6813
76f93e487956
(main): Use setuid, not seteuid.
Karl Heuer <kwzh@gnu.org>
parents:
6690
diff
changeset
|
381 setuid (getuid ()); |
5435 | 382 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
383 #ifndef MAIL_USE_MMDF |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
384 #ifdef MAIL_USE_SYSTEM_LOCK |
5435 | 385 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
|
386 #else /* if not MAIL_USE_SYSTEM_LOCK */ |
5435 | 387 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
|
388 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
5435 | 389 #else /* MAIL_USE_MMDF */ |
390 indesc = lk_open (inname, O_RDONLY, 0, 0, 10); | |
25 | 391 #endif /* MAIL_USE_MMDF */ |
392 | |
5435 | 393 if (indesc < 0) |
394 pfatal_with_name (inname); | |
23 | 395 |
87833
36e4ffad31fe
* movemail.c: Remove references to XENIX.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87730
diff
changeset
|
396 #ifdef BSD_SYSTEM |
5435 | 397 /* In case movemail is setuid to root, make sure the user can |
398 read the output file. */ | |
399 /* This is desirable for all systems | |
400 but I don't want to assume all have the umask system call */ | |
401 umask (umask (0) & 0333); | |
87833
36e4ffad31fe
* movemail.c: Remove references to XENIX.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87730
diff
changeset
|
402 #endif /* BSD_SYSTEM */ |
5435 | 403 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
404 if (outdesc < 0) | |
405 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
|
406 |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
407 /* 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
|
408 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
|
409 retry_lock: |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
410 |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
411 /* Try to lock it. */ |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
412 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
413 if (spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
414 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
415 /* 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
|
416 non-zero. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
417 status = 0 - maillock (spool_name, 1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
418 #ifdef HAVE_TOUCHLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
419 touched_lock = time (0); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
420 #endif |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
421 lockcount = 5; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
422 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
423 else |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
424 #endif /* MAIL_USE_MAILLOCK */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
425 { |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
426 #ifdef MAIL_USE_SYSTEM_LOCK |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
427 #ifdef MAIL_USE_LOCKF |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
428 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
|
429 #else /* not MAIL_USE_LOCKF */ |
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 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
435 #endif /* not MAIL_USE_LOCKF */ |
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
436 #endif /* MAIL_USE_SYSTEM_LOCK */ |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
437 } |
23 | 438 |
16366
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
439 /* 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
|
440 for certain failure codes. */ |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
441 if (status < 0) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
442 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
443 if (++lockcount <= 5) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
444 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
445 #ifdef EAGAIN |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
446 if (errno == EAGAIN) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
447 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
448 sleep (1); |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
449 goto retry_lock; |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
450 } |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
451 #endif |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
452 #ifdef EBUSY |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
453 if (errno == EBUSY) |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
454 { |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
455 sleep (1); |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
456 goto retry_lock; |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
457 } |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
458 #endif |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
459 } |
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 pfatal_with_name (inname); |
ed13d19dbce5
(main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
462 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48314
diff
changeset
|
463 |
5435 | 464 { |
465 char buf[1024]; | |
604 | 466 |
5435 | 467 while (1) |
604 | 468 { |
5435 | 469 nread = read (indesc, buf, sizeof buf); |
70280
bca72679c7d8
(main): Check for negative value from `read'.
Richard M. Stallman <rms@gnu.org>
parents:
68647
diff
changeset
|
470 if (nread < 0) |
bca72679c7d8
(main): Check for negative value from `read'.
Richard M. Stallman <rms@gnu.org>
parents:
68647
diff
changeset
|
471 pfatal_with_name (inname); |
5435 | 472 if (nread != write (outdesc, buf, nread)) |
473 { | |
474 int saved_errno = errno; | |
475 unlink (outname); | |
476 errno = saved_errno; | |
477 pfatal_with_name (outname); | |
478 } | |
479 if (nread < sizeof buf) | |
480 break; | |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
481 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
482 if (spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
483 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
484 now = time (0); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
485 if (now - touched_lock > 60) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
486 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
487 touchlock (); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
488 touched_lock = now; |
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 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
491 #endif /* MAIL_USE_MAILLOCK */ |
604 | 492 } |
493 } | |
23 | 494 |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
15105
diff
changeset
|
495 #ifdef BSD_SYSTEM |
5435 | 496 if (fsync (outdesc) < 0) |
497 pfatal_and_delete (outname); | |
23 | 498 #endif |
499 | |
5435 | 500 /* Check to make sure no errors before we zap the inbox. */ |
501 if (close (outdesc) != 0) | |
502 pfatal_and_delete (outname); | |
23 | 503 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
504 #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
|
505 if (! preserve_mail) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
506 { |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
507 ftruncate (indesc, 0L); |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
508 } |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
509 #endif /* MAIL_USE_SYSTEM_LOCK */ |
25 | 510 |
511 #ifdef MAIL_USE_MMDF | |
5435 | 512 lk_close (indesc, 0, 0, 0); |
25 | 513 #else |
5435 | 514 close (indesc); |
25 | 515 #endif |
23 | 516 |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
517 #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
|
518 if (! preserve_mail) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
519 { |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
520 /* 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
|
521 contents. */ |
571 | 522 #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
|
523 /* 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
|
524 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
|
525 if (unlink (inname) < 0 && errno != ENOENT) |
571 | 526 #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
|
527 creat (inname, 0600); |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
528 } |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
529 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
5435 | 530 |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
531 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
532 /* 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
|
533 acquired the lock! */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
534 if (spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
535 mailunlock (); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
536 #endif |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
537 exit (EXIT_SUCCESS); |
5435 | 538 } |
539 | |
540 wait (&status); | |
541 if (!WIFEXITED (status)) | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
542 exit (EXIT_FAILURE); |
5435 | 543 else if (WRETCODE (status) != 0) |
544 exit (WRETCODE (status)); | |
545 | |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
546 #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
|
547 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
548 if (! spool_name) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
549 #endif /* MAIL_USE_MAILLOCK */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
550 unlink (lockname); |
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
551 #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
|
552 |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
553 #endif /* ! DISABLE_DIRECT_ACCESS */ |
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
554 |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
555 return EXIT_SUCCESS; |
23 | 556 } |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
557 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
558 #ifdef MAIL_USE_MAILLOCK |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
559 /* 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
|
560 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
|
561 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
|
562 be symbolic links pointing to some other directory. */ |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
563 static char * |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
564 mail_spool_name (inname) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
565 char *inname; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
566 { |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
567 struct stat stat1, stat2; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
568 char *indir, *fname; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
569 int status; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
570 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
571 if (! (fname = rindex (inname, '/'))) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
572 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
573 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
574 fname++; |
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 (stat (MAILDIR, &stat1) < 0) |
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 indir = (char *) xmalloc (fname - inname + 1); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
580 strncpy (indir, inname, fname - inname); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
581 indir[fname-inname] = '\0'; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
582 |
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 status = stat (indir, &stat2); |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
585 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
586 free (indir); |
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 if (status < 0) |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
589 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
590 |
18626
d3d968d0773a
(rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
17069
diff
changeset
|
591 if (stat1.st_dev == stat2.st_dev |
d3d968d0773a
(rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents:
17069
diff
changeset
|
592 && stat1.st_ino == stat2.st_ino) |
16897
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
593 return fname; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
594 |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
595 return NULL; |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
596 } |
523d5c54a3f5
Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents:
16366
diff
changeset
|
597 #endif /* MAIL_USE_MAILLOCK */ |
23 | 598 |
599 /* Print error message and exit. */ | |
600 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
601 void |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
602 fatal (s1, s2, s3) |
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
603 char *s1, *s2, *s3; |
23 | 604 { |
605 if (delete_lockname) | |
606 unlink (delete_lockname); | |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
607 error (s1, s2, s3); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
608 exit (EXIT_FAILURE); |
23 | 609 } |
610 | |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
611 /* Print error message. `s1' is printf control string, `s2' and `s3' |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
612 are args for it or null. */ |
23 | 613 |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
614 void |
120 | 615 error (s1, s2, s3) |
616 char *s1, *s2, *s3; | |
23 | 617 { |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
618 fprintf (stderr, "movemail: "); |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
619 if (s3) |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
620 fprintf (stderr, s1, s2, s3); |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
621 else if (s2) |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
622 fprintf (stderr, s1, s2); |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
623 else |
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
624 fprintf (stderr, s1); |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
625 fprintf (stderr, "\n"); |
23 | 626 } |
627 | |
9490
4e70299f958d
Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents:
9157
diff
changeset
|
628 void |
23 | 629 pfatal_with_name (name) |
630 char *name; | |
631 { | |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
632 fatal ("%s for %s", strerror (errno), name); |
23 | 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 { |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
639 char *s = strerror (errno); |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
640 unlink (name); |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
641 fatal ("%s for %s", s, name); |
447
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) |
59918
5a468b3bfb27
(fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents:
59775
diff
changeset
|
669 fatal ("virtual memory exhausted", 0, 0); |
23 | 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]; |
29046
7d5565d3cf32
Include config.h, not ../src/config.h.
Dave Love <fx@gnu.org>
parents:
27507
diff
changeset
|
696 char Errmsg[200]; /* POP errors, at least, can exceed |
7d5565d3cf32
Include config.h, not ../src/config.h.
Dave Love <fx@gnu.org>
parents:
27507
diff
changeset
|
697 the original length of 80. */ |
23 | 698 |
26794
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
699 /* |
80028
f56936039199
*** empty log message ***
Juanma Barranquero <lekktu@gmail.com>
parents:
79748
diff
changeset
|
700 * The full valid syntax for a POP mailbox specification for movemail |
26794
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
701 * is "po:username:hostname". The ":hostname" is optional; if it is |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
702 * omitted, the MAILHOST environment variable will be consulted. Note |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
703 * that by the time popmail() is called the "po:" has been stripped |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
704 * off of the front of the mailbox name. |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
705 * |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
706 * If the mailbox is in the form "po:username:hostname", then it is |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
707 * modified by this function -- the second colon is replaced by a |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
708 * null. |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
709 * |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
710 * Return a value suitable for passing to `exit'. |
26794
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
711 */ |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
712 |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
713 int |
26794
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
714 popmail (mailbox, outfile, preserve, password, reverse_order) |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
715 char *mailbox; |
120 | 716 char *outfile; |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
717 int preserve; |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
718 char *password; |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
719 int reverse_order; |
23 | 720 { |
120 | 721 int nmsgs, nbytes; |
722 register int i; | |
723 int mbfi; | |
724 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
|
725 char *getenv (); |
9630
5410efcb7b6e
PopServer renamed to popserver throughout.
Richard M. Stallman <rms@gnu.org>
parents:
9612
diff
changeset
|
726 popserver server; |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
727 int start, end, increment; |
26794
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
728 char *user, *hostname; |
23 | 729 |
26794
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
730 user = mailbox; |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
731 if ((hostname = index(mailbox, ':'))) |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
732 *hostname++ = '\0'; |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
733 |
535af4b15059
(popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
734 server = pop_open (hostname, 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
|
735 if (! server) |
120 | 736 { |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
737 error ("Error connecting to POP server: %s", pop_error, 0); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
738 return EXIT_FAILURE; |
23 | 739 } |
740 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
741 if (pop_stat (server, &nmsgs, &nbytes)) |
120 | 742 { |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
743 error ("Error getting message count from POP server: %s", pop_error, 0); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
744 return EXIT_FAILURE; |
120 | 745 } |
23 | 746 |
120 | 747 if (!nmsgs) |
748 { | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
749 pop_close (server); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
750 return EXIT_SUCCESS; |
23 | 751 } |
752 | |
120 | 753 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666); |
754 if (mbfi < 0) | |
755 { | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
756 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
|
757 error ("Error in open: %s, %s", strerror (errno), outfile); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
758 return EXIT_FAILURE; |
120 | 759 } |
760 fchown (mbfi, getuid (), -1); | |
761 | |
15101
f86169152e74
(access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents:
14649
diff
changeset
|
762 if ((mbf = fdopen (mbfi, "wb")) == NULL) |
120 | 763 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
764 pop_close (server); |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
765 error ("Error in fdopen: %s", strerror (errno), 0); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
766 close (mbfi); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
767 unlink (outfile); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
768 return EXIT_FAILURE; |
120 | 769 } |
770 | |
23182
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
771 if (reverse_order) |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
772 { |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
773 start = nmsgs; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
774 end = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
775 increment = -1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
776 } |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
777 else |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
778 { |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
779 start = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
780 end = nmsgs; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
781 increment = 1; |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
782 } |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
783 |
0ba967162ee0
[MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents:
22316
diff
changeset
|
784 for (i = start; i * increment <= end * increment; i += increment) |
120 | 785 { |
786 mbx_delimit_begin (mbf); | |
17069
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
787 if (pop_retr (server, i, mbf) != OK) |
120 | 788 { |
59775
d39551ad7f40
(popmail): Don't use Errmsg as format string.
Richard M. Stallman <rms@gnu.org>
parents:
55442
diff
changeset
|
789 error ("%s", Errmsg, 0); |
120 | 790 close (mbfi); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
791 return EXIT_FAILURE; |
120 | 792 } |
793 mbx_delimit_end (mbf); | |
794 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
|
795 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
|
796 { |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
797 error ("Error in fflush: %s", strerror (errno), 0); |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
798 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
|
799 close (mbfi); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
800 return EXIT_FAILURE; |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
801 } |
120 | 802 } |
803 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
804 /* 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
|
805 * 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
|
806 * 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
|
807 * 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
|
808 * 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
|
809 |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
15105
diff
changeset
|
810 #ifdef BSD_SYSTEM |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
811 if (fsync (mbfi) < 0) |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
812 { |
40683
580a1a573d3e
(popmail): Always pass two args to `error'.
Richard M. Stallman <rms@gnu.org>
parents:
31376
diff
changeset
|
813 error ("Error in fsync: %s", strerror (errno), 0); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
814 return EXIT_FAILURE; |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
815 } |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
9490
diff
changeset
|
816 #endif |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
817 |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
818 if (close (mbfi) == -1) |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
819 { |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
820 error ("Error in close: %s", strerror (errno), 0); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
821 return EXIT_FAILURE; |
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
822 } |
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
823 |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
824 if (! preserve) |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
825 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
|
826 { |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
827 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
|
828 { |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
829 error ("Error from POP server: %s", pop_error, 0); |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
830 pop_close (server); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
831 return EXIT_FAILURE; |
16909
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
832 } |
d878e23bbfa6
(main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents:
16897
diff
changeset
|
833 } |
23 | 834 |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
835 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
|
836 { |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
837 error ("Error from POP server: %s", pop_error, 0); |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
838 return EXIT_FAILURE; |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
839 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48314
diff
changeset
|
840 |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
841 return EXIT_SUCCESS; |
23 | 842 } |
843 | |
17069
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
844 int |
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
845 pop_retr (server, msgno, arg) |
9630
5410efcb7b6e
PopServer renamed to popserver throughout.
Richard M. Stallman <rms@gnu.org>
parents:
9612
diff
changeset
|
846 popserver server; |
48314 | 847 int msgno; |
17069
0b2b8a0f7570
(popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents:
16994
diff
changeset
|
848 FILE *arg; |
23 | 849 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
850 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
|
851 char *line; |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
852 int ret; |
23 | 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 (pop_retrieve_first (server, msgno, &line)) |
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 } |
862 | |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
863 while ((ret = pop_retrieve_next (server, &line)) >= 0) |
120 | 864 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
865 if (! line) |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
866 break; |
23 | 867 |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
868 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
|
869 { |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
870 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
|
871 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
|
872 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
873 } |
23 | 874 } |
875 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
876 if (ret) |
120 | 877 { |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
878 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
|
879 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
|
880 Errmsg[sizeof (Errmsg)-1] = '\0'; |
23290
9917b9a0024d
(popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents:
23182
diff
changeset
|
881 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
|
882 return (NOTOK); |
23 | 883 } |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
884 |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
885 return (OK); |
23 | 886 } |
887 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
888 /* 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
|
889 #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
|
890 && (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
|
891 && (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
|
892 && (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
|
893 && (a[4] == ' ')) |
23 | 894 |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
895 int |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
896 mbx_write (line, len, mbf) |
120 | 897 char *line; |
20418
7e1538a45702
Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents:
20387
diff
changeset
|
898 int len; |
120 | 899 FILE *mbf; |
23 | 900 { |
20387
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
901 #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
|
902 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
|
903 { |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
904 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
|
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 } |
20387
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
907 #endif |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
908 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
|
909 { |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
910 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
|
911 return (NOTOK); |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
912 line++; |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
913 len--; |
4c524f5214ce
(mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents:
18626
diff
changeset
|
914 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48314
diff
changeset
|
915 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
|
916 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
917 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
|
918 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
919 return (OK); |
23 | 920 } |
921 | |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
922 int |
120 | 923 mbx_delimit_begin (mbf) |
924 FILE *mbf; | |
23 | 925 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
926 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
|
927 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
928 return (OK); |
23 | 929 } |
930 | |
31233
77ed917b12ee
(toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents:
31080
diff
changeset
|
931 int |
120 | 932 mbx_delimit_end (mbf) |
933 FILE *mbf; | |
23 | 934 { |
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
935 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
|
936 return (NOTOK); |
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
937 return (OK); |
23 | 938 } |
939 | |
940 #endif /* MAIL_USE_POP */ | |
5532
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
941 |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
942 #ifndef HAVE_STRERROR |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
943 char * |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
944 strerror (errnum) |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
945 int errnum; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
946 { |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
947 extern char *sys_errlist[]; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
948 extern int sys_nerr; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
949 |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
950 if (errnum >= 0 && errnum < sys_nerr) |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
951 return sys_errlist[errnum]; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
952 return (char *) "Unknown error"; |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
953 } |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
954 |
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
955 #endif /* ! HAVE_STRERROR */ |
52401 | 956 |
957 /* arch-tag: 1c323112-41fe-4fe5-8de9-494de631f73f | |
958 (do not change this comment) */ | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
959 |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
960 /* movemail.c ends here */ |