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