annotate lib-src/movemail.c @ 112440:b5017c649dfb

Check return values of some library calls.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 22 Jan 2011 23:30:19 -0800
parents 56d3e9c28eb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* movemail foo bar -- move file foo to file bar,
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 107762
diff changeset
4 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 This file is part of GNU Emacs.
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
94828
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
8 GNU Emacs is free software: you can redistribute it and/or modify
38
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
9 it under the terms of the GNU General Public License as published by
94828
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
11 (at your option) any later version.
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
38
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
13 GNU Emacs is distributed in the hope that it will be useful,
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
16 GNU General Public License for more details.
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
17
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
18 You should have received a copy of the GNU General Public License
94828
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
3a4bc081639c Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
20
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
22 /* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
23 cause loss of mail* if you do it on a system that does not normally
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
24 use flock as its way of interlocking access to inbox files. The
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
25 setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
26 system's own conventions. It is not a choice that is up to you.
510
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
27
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
28 So, if your system uses lock files rather than flock, then the only way
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
29 you can get proper operation is to enable movemail to write lockfiles there.
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
30 This means you must either give that directory access modes
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
31 that permit everyone to write lockfiles in it, or you must make movemail
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
32 a setuid or setgid program. */
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
33
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 /*
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 *
14649
2925c3f0d038 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
37 * Added POP (Post Office Protocol) service. When compiled -DMAIL_USE_POP
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 * movemail will accept input filename arguments of the form
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 * "po:username". This will cause movemail to open a connection to
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 * a pop server running on $MAILHOST (environment variable). Movemail
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 * must be setuid to root in order to work with POP.
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48314
diff changeset
42 *
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 * New module: popmail.c
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 * Modified routines:
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
45 * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48314
diff changeset
46 * after POP code.
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 * New routines in movemail.c:
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 * get_errmsg - return pointer to system error message
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 *
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
50 * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies)
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
51 *
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
52 * Move all of the POP code into a separate file, "pop.c".
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
53 * Use strerror instead of get_errmsg.
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
54 *
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
29046
7d5565d3cf32 Include config.h, not ../src/config.h.
Dave Love <fx@gnu.org>
parents: 27507
diff changeset
57 #include <config.h>
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 #include <sys/types.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 #include <sys/stat.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 #include <sys/file.h>
9490
4e70299f958d Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents: 9157
diff changeset
61 #include <stdio.h>
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 #include <errno.h>
102006
86059ded629a Include time.h unconditionally.
Chong Yidong <cyd@stupidchicken.com>
parents: 101936
diff changeset
63 #include <time.h>
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
64
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
65 #include <getopt.h>
31317
d431eeb4028f (toplevel): Remove redundant <fcntl.h>. Provide definitions for F_OK
Eli Zaretskii <eliz@gnu.org>
parents: 31274
diff changeset
66 #include <unistd.h>
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
67 #ifdef HAVE_FCNTL_H
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
68 #include <fcntl.h>
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
69 #endif
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
70 #ifdef HAVE_STRING_H
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
71 #include <string.h>
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
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
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
109 #ifndef F_OK
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
110 #define F_OK 0
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
111 #define X_OK 1
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
112 #define W_OK 2
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
113 #define R_OK 4
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
114 #endif
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
87833
36e4ffad31fe * movemail.c: Remove references to XENIX.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87730
diff changeset
116 #ifdef WINDOWSNT
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 #include <sys/locking.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 #endif
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
128 #ifdef MAIL_USE_MMDF
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
129 extern int lk_open (), lk_close ();
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
130 #endif
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
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
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
144 #ifndef HAVE_STRERROR
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
145 char *strerror (int);
31376
f5cd669613d2 (index, rindex): Prototype conditionally.
Dave Love <fx@gnu.org>
parents: 31317
diff changeset
146 #endif
9490
4e70299f958d Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents: 9157
diff changeset
147
109744
fdbd24f8d999 Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents: 109511
diff changeset
148 static void fatal (const char *s1, const char *s2, const char *s3) NO_RETURN;
fdbd24f8d999 Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents: 109511
diff changeset
149 static void error (const char *s1, const char *s2, const char *s3);
109511
09a43f890565 Add NO_RETURN specifiers to functions in lib-src.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109315
diff changeset
150 static void pfatal_with_name (char *name) NO_RETURN;
09a43f890565 Add NO_RETURN specifiers to functions in lib-src.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109315
diff changeset
151 static void pfatal_and_delete (char *name) NO_RETURN;
109744
fdbd24f8d999 Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents: 109511
diff changeset
152 static char *concat (const char *s1, const char *s2, const char *s3);
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
153 static long *xmalloc (unsigned int size);
109149
5833ef142374 * movemail.c: Add MAIL_USE_POP around prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 109111
diff changeset
154 #ifdef MAIL_USE_POP
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
155 static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order);
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
156 static int pop_retr (popserver server, int msgno, FILE *arg);
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
157 static int mbx_write (char *line, int len, FILE *mbf);
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
158 static int mbx_delimit_begin (FILE *mbf);
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
159 static int mbx_delimit_end (FILE *mbf);
109149
5833ef142374 * movemail.c: Add MAIL_USE_POP around prototypes.
Andreas Schwab <schwab@linux-m68k.org>
parents: 109111
diff changeset
160 #endif
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 /* Nonzero means this is name of a lock file to delete on fatal error. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 char *delete_lockname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
9490
4e70299f958d Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents: 9157
diff changeset
165 int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
166 main (int argc, char **argv)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 char *inname, *outname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 int indesc, outdesc;
110746
5c1a707ab452 Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109744
diff changeset
170 ssize_t nread;
96620
3bea8ede5bd0 * syswait.h: Remove old if 0 code. Do not define WAITTYPE, it was
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94828
diff changeset
171 int status;
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
172 int c, preserve_mail = 0;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
174 #ifndef MAIL_USE_SYSTEM_LOCK
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 struct stat st;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 long now;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 int tem;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 char *lockname, *p;
601
3db1540d4b97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 580
diff changeset
179 char *tempname;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 int desc;
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
181 #endif /* not MAIL_USE_SYSTEM_LOCK */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
183 #ifdef MAIL_USE_MAILLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
184 char *spool_name;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
185 #endif
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
186
23182
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
187 #ifdef MAIL_USE_POP
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
188 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
189 # define ARGSTR "pr"
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
190 #else /* ! MAIL_USE_POP */
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
191 # define ARGSTR "p"
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
192 #endif /* MAIL_USE_POP */
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
193
107762
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
194 uid_t real_gid = getgid();
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
195 uid_t priv_gid = getegid();
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
196
31080
7ae519dba237 (main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents: 29046
diff changeset
197 #ifdef WINDOWSNT
7ae519dba237 (main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents: 29046
diff changeset
198 /* 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
199 _fmode = _O_BINARY;
7ae519dba237 (main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents: 29046
diff changeset
200 #endif
7ae519dba237 (main) [WINDOWSNT]: Force binary mode for fileio.
Andrew Innes <andrewi@gnu.org>
parents: 29046
diff changeset
201
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 delete_lockname = 0;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
23182
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
204 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
205 {
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
206 switch (c) {
23182
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
207 #ifdef MAIL_USE_POP
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
208 case 'r':
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
209 pop_reverse_order = 1;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
210 break;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
211 #endif
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
212 case 'p':
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
213 preserve_mail++;
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
214 break;
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
215 default:
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
216 exit (EXIT_FAILURE);
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
217 }
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
218 }
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
219
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
220 if (
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
221 #ifdef MAIL_USE_POP
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
222 (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
223 #else
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
224 (argc - optind != 2)
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
225 #endif
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
226 )
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
227 {
52069
76d453ac3c4f (main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 51112
diff changeset
228 #ifdef MAIL_USE_POP
102385
e85d013e3140 (main) [MAIL_USE_POP]: Add -r to usage message.
Glenn Morris <rgm@gnu.org>
parents: 102006
diff changeset
229 fprintf (stderr, "Usage: movemail [-p] [-r] inbox destfile%s\n",
52069
76d453ac3c4f (main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 51112
diff changeset
230 " [POP-password]");
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
231 #else
52069
76d453ac3c4f (main): Fix having macros in a printf statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 51112
diff changeset
232 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
233 #endif
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
234 exit (EXIT_FAILURE);
9490
4e70299f958d Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents: 9157
diff changeset
235 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
237 inname = argv[optind];
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
238 outname = argv[optind+1];
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
240 #ifdef MAIL_USE_MMDF
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
241 mmdf_init (argv[0]);
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
242 #endif
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
243
12793
0464324deda7 (main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 12777
diff changeset
244 if (*outname == 0)
59918
5a468b3bfb27 (fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents: 59775
diff changeset
245 fatal ("Destination file name is empty", 0, 0);
12793
0464324deda7 (main): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 12777
diff changeset
246
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 #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
248 if (!strncmp (inname, "po:", 3))
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 {
12442
981986d7d82f (main) [MAIL_USE_POP]: When a user specifies a
Richard M. Stallman <rms@gnu.org>
parents: 12389
diff changeset
250 int status;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
252 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
253 (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
254 pop_reverse_order);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 exit (status);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
107762
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
258 if (setuid (getuid ()) < 0)
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
259 fatal ("Failed to drop privileges", 0, 0);
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
260
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 #endif /* MAIL_USE_POP */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
15101
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
263 #ifndef DISABLE_DIRECT_ACCESS
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
264 #ifndef MAIL_USE_MMDF
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
265 #ifndef MAIL_USE_SYSTEM_LOCK
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
266 #ifdef MAIL_USE_MAILLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
267 spool_name = mail_spool_name (inname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
268 if (! spool_name)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
269 #endif
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
270 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
271 /* 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
272 If it exists, the mail file is locked. */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
273 /* Note: this locking mechanism is *required* by the mailer
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
274 (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
275
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
276 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
277 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
278
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
279 So, if creation of the lock file fails
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
280 due to access permission on the mail spool directory,
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
281 you simply MUST change the permission
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
282 and/or make movemail a setgid program
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
283 so it can create lock files properly.
351
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
284
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
285 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
286 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
287
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
288 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
289 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
290 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
291 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
292 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
294 lockname = concat (inname, ".lock", "");
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
295 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
296 strcpy (tempname, inname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
297 p = tempname + strlen (tempname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
298 while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
299 p--;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
300 *p = 0;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
301 strcpy (p, "EXXXXXX");
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
302 mktemp (tempname);
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
303 unlink (tempname);
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
304
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
305 while (1)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
306 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
307 /* 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
308 /* Give up if cannot do that. */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
309 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
310 if (desc < 0)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
311 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
312 char *message = (char *) xmalloc (strlen (tempname) + 50);
27507
b7db0c0368dc Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 27504
diff changeset
313 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
314 tempname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
315 pfatal_with_name (message);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
316 }
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
317 close (desc);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
319 tem = link (tempname, lockname);
100823
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
320
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
321 #ifdef EPERM
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
322 if (tem < 0 && errno == EPERM)
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
323 fatal ("Unable to create hard link between %s and %s",
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
324 tempname, lockname);
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
325 #endif
d893844c75a7 (main): Fatal if hard links cannot be created.
Chong Yidong <cyd@stupidchicken.com>
parents: 96620
diff changeset
326
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
327 unlink (tempname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
328 if (tem >= 0)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
329 break;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
330 sleep (1);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
331
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
332 /* If lock file is five minutes old, unlock it.
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
333 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
334 and wedgitude, and long enough to avoid being fooled
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
335 by time differences between machines. */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
336 if (stat (lockname, &st) >= 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 now = time (0);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
339 if (st.st_ctime < now - 300)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
340 unlink (lockname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
341 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 }
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
343
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
344 delete_lockname = lockname;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 }
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
346 #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
347 #endif /* not MAIL_USE_MMDF */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
349 if (fork () == 0)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
350 {
16366
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
351 int lockcount = 0;
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
352 int status = 0;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
353 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
102006
86059ded629a Include time.h unconditionally.
Chong Yidong <cyd@stupidchicken.com>
parents: 101936
diff changeset
354 time_t touched_lock, now;
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
355 #endif
16366
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
356
107762
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
357 if (setuid (getuid ()) < 0 || setegid (real_gid) < 0)
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
358 fatal ("Failed to drop privileges", 0, 0);
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
359
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
360 #ifndef MAIL_USE_MMDF
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
361 #ifdef MAIL_USE_SYSTEM_LOCK
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
362 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
363 #else /* if not MAIL_USE_SYSTEM_LOCK */
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
364 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
365 #endif /* not MAIL_USE_SYSTEM_LOCK */
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
366 #else /* MAIL_USE_MMDF */
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
367 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
368 #endif /* MAIL_USE_MMDF */
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
369
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
370 if (indesc < 0)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
371 pfatal_with_name (inname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372
87833
36e4ffad31fe * movemail.c: Remove references to XENIX.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87730
diff changeset
373 #ifdef BSD_SYSTEM
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
374 /* In case movemail is setuid to root, make sure the user can
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
375 read the output file. */
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
376 /* This is desirable for all systems
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
377 but I don't want to assume all have the umask system call */
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
378 umask (umask (0) & 0333);
87833
36e4ffad31fe * movemail.c: Remove references to XENIX.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87730
diff changeset
379 #endif /* BSD_SYSTEM */
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
380 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
381 if (outdesc < 0)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
382 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
383
107762
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
384 if (setegid (priv_gid) < 0)
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
385 fatal ("Failed to regain privileges", 0, 0);
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
386
16366
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
387 /* 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
388 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
389 retry_lock:
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
390
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
391 /* Try to lock it. */
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
392 #ifdef MAIL_USE_MAILLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
393 if (spool_name)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
394 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
395 /* 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
396 non-zero. */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
397 status = 0 - maillock (spool_name, 1);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
398 #ifdef HAVE_TOUCHLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
399 touched_lock = time (0);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
400 #endif
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
401 lockcount = 5;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
402 }
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
403 else
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
404 #endif /* MAIL_USE_MAILLOCK */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
405 {
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
406 #ifdef MAIL_USE_SYSTEM_LOCK
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
407 #ifdef MAIL_USE_LOCKF
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
408 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
409 #else /* not MAIL_USE_LOCKF */
15101
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
410 #ifdef WINDOWSNT
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
411 status = locking (indesc, LK_RLCK, -1L);
15101
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
412 #else
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
413 status = flock (indesc, LOCK_EX);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 #endif
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
415 #endif /* not MAIL_USE_LOCKF */
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
416 #endif /* MAIL_USE_SYSTEM_LOCK */
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
417 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
16366
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
419 /* 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
420 for certain failure codes. */
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
421 if (status < 0)
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
422 {
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
423 if (++lockcount <= 5)
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
424 {
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
425 #ifdef EAGAIN
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
426 if (errno == EAGAIN)
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
427 {
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
428 sleep (1);
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
429 goto retry_lock;
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
430 }
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
431 #endif
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
432 #ifdef EBUSY
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
433 if (errno == EBUSY)
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
434 {
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
435 sleep (1);
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
436 goto retry_lock;
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 #endif
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
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
441 pfatal_with_name (inname);
ed13d19dbce5 (main): If the lock call fails with EBUSY or
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
442 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48314
diff changeset
443
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
444 {
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
445 char buf[1024];
604
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
446
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
447 while (1)
604
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
448 {
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
449 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
450 if (nread < 0)
bca72679c7d8 (main): Check for negative value from `read'.
Richard M. Stallman <rms@gnu.org>
parents: 68647
diff changeset
451 pfatal_with_name (inname);
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
452 if (nread != write (outdesc, buf, nread))
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
453 {
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
454 int saved_errno = errno;
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
455 unlink (outname);
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
456 errno = saved_errno;
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
457 pfatal_with_name (outname);
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
458 }
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
459 if (nread < sizeof buf)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
460 break;
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
461 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
462 if (spool_name)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
463 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
464 now = time (0);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
465 if (now - touched_lock > 60)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
466 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
467 touchlock ();
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
468 touched_lock = now;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
469 }
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
470 }
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
471 #endif /* MAIL_USE_MAILLOCK */
604
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
472 }
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
473 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474
16218
32f82ca8b41f Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents: 15105
diff changeset
475 #ifdef BSD_SYSTEM
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
476 if (fsync (outdesc) < 0)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
477 pfatal_and_delete (outname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 #endif
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479
107762
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
480 /* Prevent symlink attacks truncating other users' mailboxes */
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
481 if (setegid (real_gid) < 0)
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
482 fatal ("Failed to drop privileges", 0, 0);
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
483
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
484 /* Check to make sure no errors before we zap the inbox. */
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
485 if (close (outdesc) != 0)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
486 pfatal_and_delete (outname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
488 #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
489 if (! preserve_mail)
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
490 {
112440
b5017c649dfb Check return values of some library calls.
Paul Eggert <eggert@cs.ucla.edu>
parents: 112330
diff changeset
491 if (ftruncate (indesc, 0L) != 0)
b5017c649dfb Check return values of some library calls.
Paul Eggert <eggert@cs.ucla.edu>
parents: 112330
diff changeset
492 pfatal_with_name (inname);
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
493 }
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
494 #endif /* MAIL_USE_SYSTEM_LOCK */
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
495
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
496 #ifdef MAIL_USE_MMDF
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
497 lk_close (indesc, 0, 0, 0);
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
498 #else
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
499 close (indesc);
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
500 #endif
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
502 #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
503 if (! preserve_mail)
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
504 {
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
505 /* 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
506 contents. */
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
507 #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
508 /* 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
509 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
510 if (unlink (inname) < 0 && errno != ENOENT)
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
511 #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
512 creat (inname, 0600);
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
513 }
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
514 #endif /* not MAIL_USE_SYSTEM_LOCK */
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
515
107762
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
516 /* End of mailbox truncation */
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
517 if (setegid (priv_gid) < 0)
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
518 fatal ("Failed to regain privileges", 0, 0);
2d36607da023 Fix permissions handling (CVE-2010-0825).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
519
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
520 #ifdef MAIL_USE_MAILLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
521 /* 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
522 acquired the lock! */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
523 if (spool_name)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
524 mailunlock ();
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
525 #endif
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
526 exit (EXIT_SUCCESS);
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
527 }
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
528
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
529 wait (&status);
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
530 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
531 exit (EXIT_FAILURE);
5435
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
532 else if (WRETCODE (status) != 0)
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
533 exit (WRETCODE (status));
d7408b99b88f Include syswait.h.
Richard M. Stallman <rms@gnu.org>
parents: 5318
diff changeset
534
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
535 #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
536 #ifdef MAIL_USE_MAILLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
537 if (! spool_name)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
538 #endif /* MAIL_USE_MAILLOCK */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
539 unlink (lockname);
6690
a1a42eefcc61 (main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents: 5532
diff changeset
540 #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
541
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
542 #endif /* ! DISABLE_DIRECT_ACCESS */
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
543
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
544 return EXIT_SUCCESS;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 }
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
546
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
547 #ifdef MAIL_USE_MAILLOCK
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
548 /* 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
549 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
550 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
551 be symbolic links pointing to some other directory. */
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
552 static char *
110746
5c1a707ab452 Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109744
diff changeset
553 mail_spool_name (char *inname)
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
554 {
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
555 struct stat stat1, stat2;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
556 char *indir, *fname;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
557 int status;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
558
109315
8f3464b85afb Use strchr, strrchr instead of index, rindex
Andreas Schwab <schwab@linux-m68k.org>
parents: 109150
diff changeset
559 if (! (fname = strrchr (inname, '/')))
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
560 return NULL;
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 fname++;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
563
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
564 if (stat (MAILDIR, &stat1) < 0)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
565 return NULL;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
566
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
567 indir = (char *) xmalloc (fname - inname + 1);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
568 strncpy (indir, inname, fname - inname);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
569 indir[fname-inname] = '\0';
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
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
572 status = stat (indir, &stat2);
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 free (indir);
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
575
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
576 if (status < 0)
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
577 return NULL;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
578
18626
d3d968d0773a (rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents: 17069
diff changeset
579 if (stat1.st_dev == stat2.st_dev
d3d968d0773a (rindex): Add declaration.
Richard M. Stallman <rms@gnu.org>
parents: 17069
diff changeset
580 && stat1.st_ino == stat2.st_ino)
16897
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
581 return fname;
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 return NULL;
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
584 }
523d5c54a3f5 Include maillock.h (conditionally).
Richard M. Stallman <rms@gnu.org>
parents: 16366
diff changeset
585 #endif /* MAIL_USE_MAILLOCK */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 /* Print error message and exit. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
589 static void
109744
fdbd24f8d999 Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents: 109511
diff changeset
590 fatal (const char *s1, const char *s2, const char *s3)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 if (delete_lockname)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 unlink (delete_lockname);
59918
5a468b3bfb27 (fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents: 59775
diff changeset
594 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
595 exit (EXIT_FAILURE);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
598 /* 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
599 are args for it or null. */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
601 static void
109744
fdbd24f8d999 Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents: 109511
diff changeset
602 error (const char *s1, const char *s2, const char *s3)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 {
9490
4e70299f958d Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents: 9157
diff changeset
604 fprintf (stderr, "movemail: ");
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
605 if (s3)
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
606 fprintf (stderr, s1, s2, s3);
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
607 else if (s2)
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
608 fprintf (stderr, s1, s2);
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
609 else
109041
3465b68cf225 lib-src/movemail.c (error): Avoid warning when there are no args.
Juanma Barranquero <lekktu@gmail.com>
parents: 107750
diff changeset
610 fprintf (stderr, "%s", s1);
9490
4e70299f958d Make functions that return nothing void, not implicitly int.
David J. MacKenzie <djm@gnu.org>
parents: 9157
diff changeset
611 fprintf (stderr, "\n");
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
614 static void
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
615 pfatal_with_name (char *name)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 {
59918
5a468b3bfb27 (fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents: 59775
diff changeset
617 fatal ("%s for %s", strerror (errno), name);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
620 static void
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
621 pfatal_and_delete (char *name)
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
622 {
59918
5a468b3bfb27 (fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents: 59775
diff changeset
623 char *s = strerror (errno);
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
624 unlink (name);
59918
5a468b3bfb27 (fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents: 59775
diff changeset
625 fatal ("%s for %s", s, name);
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
626 }
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
627
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
630 static char *
109744
fdbd24f8d999 Fix warnings produced by compiling with -Wwrite_strings (i.e. use const char *).
Jan D <jan.h.d@swipnet.se>
parents: 109511
diff changeset
631 concat (const char *s1, const char *s2, const char *s3)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 {
110746
5c1a707ab452 Fix compilation warnings.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109744
diff changeset
633 size_t len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 strcpy (result, s1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 strcpy (result + len1, s2);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 strcpy (result + len1 + len2, s3);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 *(result + len1 + len2 + len3) = 0;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 return result;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 /* Like malloc but get fatal error if memory is exhausted. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
646 static long *
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
647 xmalloc (unsigned int size)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 {
11675
496576df5d46 (xmalloc): Declare it to return long *.
Richard M. Stallman <rms@gnu.org>
parents: 10399
diff changeset
649 long *result = (long *) malloc (size);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 if (!result)
59918
5a468b3bfb27 (fatal): Accept third parameter and pass down to
Andreas Schwab <schwab@suse.de>
parents: 59775
diff changeset
651 fatal ("virtual memory exhausted", 0, 0);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 return result;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 /* This is the guts of the interface to the Post Office Protocol. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 #ifdef MAIL_USE_POP
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658
15101
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
659 #ifndef WINDOWSNT
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 #include <sys/socket.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 #include <netinet/in.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 #include <netdb.h>
15101
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
663 #else
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
664 #undef _WINSOCKAPI_
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
665 #include <winsock.h>
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
666 #endif
634
52d0ff659265 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 604
diff changeset
667 #include <pwd.h>
101936
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
668 #include <string.h>
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 #define NOTOK (-1)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 #define OK 0
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 #define DONE 1
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 char *progname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 FILE *sfi;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 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
677 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
678 char obuffer[BUFSIZ];
29046
7d5565d3cf32 Include config.h, not ../src/config.h.
Dave Love <fx@gnu.org>
parents: 27507
diff changeset
679 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
680 the original length of 80. */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
26794
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
682 /*
80028
f56936039199 *** empty log message ***
Juanma Barranquero <lekktu@gmail.com>
parents: 79748
diff changeset
683 * The full valid syntax for a POP mailbox specification for movemail
26794
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
684 * 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
685 * 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
686 * 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
687 * off of the front of the mailbox name.
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
688 *
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
689 * 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
690 * 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
691 * null.
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
692 *
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
693 * 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
694 */
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
695
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
696 static int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
697 popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
699 int nmsgs, nbytes;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
700 register int i;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
701 int mbfi;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
702 FILE *mbf;
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
703 char *getenv (const char *);
9630
5410efcb7b6e PopServer renamed to popserver throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9612
diff changeset
704 popserver server;
23182
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
705 int start, end, increment;
26794
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
706 char *user, *hostname;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707
26794
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
708 user = mailbox;
109315
8f3464b85afb Use strchr, strrchr instead of index, rindex
Andreas Schwab <schwab@linux-m68k.org>
parents: 109150
diff changeset
709 if ((hostname = strchr (mailbox, ':')))
26794
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
710 *hostname++ = '\0';
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
711
535af4b15059 (popmail): Allow mailbox specifications of the
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
712 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
713 if (! server)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
714 {
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
715 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
716 return EXIT_FAILURE;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
719 if (pop_stat (server, &nmsgs, &nbytes))
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
720 {
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
721 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
722 return EXIT_FAILURE;
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
723 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
725 if (!nmsgs)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
726 {
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
727 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
728 return EXIT_SUCCESS;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
731 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
732 if (mbfi < 0)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
733 {
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
734 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
735 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
736 return EXIT_FAILURE;
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
737 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
738 fchown (mbfi, getuid (), -1);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
739
15101
f86169152e74 (access, unlink) [WINDOWSNT]: Macros undefined.
Richard M. Stallman <rms@gnu.org>
parents: 14649
diff changeset
740 if ((mbf = fdopen (mbfi, "wb")) == NULL)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
741 {
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
742 pop_close (server);
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
743 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
744 close (mbfi);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
745 unlink (outfile);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
746 return EXIT_FAILURE;
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
747 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
748
23182
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
749 if (reverse_order)
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
750 {
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
751 start = nmsgs;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
752 end = 1;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
753 increment = -1;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
754 }
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
755 else
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
756 {
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
757 start = 1;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
758 end = nmsgs;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
759 increment = 1;
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
760 }
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
761
0ba967162ee0 [MAIL_USE_POP]: Add the "-r" flag to reverse the
Karl Heuer <kwzh@gnu.org>
parents: 22316
diff changeset
762 for (i = start; i * increment <= end * increment; i += increment)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
763 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
764 mbx_delimit_begin (mbf);
17069
0b2b8a0f7570 (popmail): Remove some unnecessary function
Karl Heuer <kwzh@gnu.org>
parents: 16994
diff changeset
765 if (pop_retr (server, i, mbf) != OK)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
766 {
59775
d39551ad7f40 (popmail): Don't use Errmsg as format string.
Richard M. Stallman <rms@gnu.org>
parents: 55442
diff changeset
767 error ("%s", Errmsg, 0);
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
768 close (mbfi);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
769 return EXIT_FAILURE;
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
770 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
771 mbx_delimit_end (mbf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
772 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
773 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
774 {
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
775 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
776 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
777 close (mbfi);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
778 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
779 }
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
780 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
781
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
782 /* 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
783 * 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
784 * 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
785 * 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
786 * 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
787
16218
32f82ca8b41f Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents: 15105
diff changeset
788 #ifdef BSD_SYSTEM
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
789 if (fsync (mbfi) < 0)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
790 {
40683
580a1a573d3e (popmail): Always pass two args to `error'.
Richard M. Stallman <rms@gnu.org>
parents: 31376
diff changeset
791 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
792 return EXIT_FAILURE;
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
793 }
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 9490
diff changeset
794 #endif
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
795
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
796 if (close (mbfi) == -1)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
797 {
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
798 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
799 return EXIT_FAILURE;
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
800 }
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
801
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
802 if (! preserve)
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
803 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
804 {
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
805 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
806 {
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
807 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
808 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
809 return EXIT_FAILURE;
16909
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
810 }
d878e23bbfa6 (main): Do not display "[POP-password]" in the usage
Richard M. Stallman <rms@gnu.org>
parents: 16897
diff changeset
811 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
813 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
814 {
31233
77ed917b12ee (toplevel) [HAVE_STRING_H]: Include string.h.
Dave Love <fx@gnu.org>
parents: 31080
diff changeset
815 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
816 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
817 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48314
diff changeset
818
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
819 return EXIT_SUCCESS;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
822 static int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
823 pop_retr (popserver server, int msgno, FILE *arg)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 {
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
825 char *line;
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
826 int ret;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
828 if (pop_retrieve_first (server, msgno, &line))
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
829 {
23290
9917b9a0024d (popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents: 23182
diff changeset
830 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
831 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
832 Errmsg[sizeof (Errmsg)-1] = '\0';
23290
9917b9a0024d (popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents: 23182
diff changeset
833 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
834 return (NOTOK);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20387
diff changeset
837 while ((ret = pop_retrieve_next (server, &line)) >= 0)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
838 {
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
839 if (! line)
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
840 break;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20387
diff changeset
842 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
843 {
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
844 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
845 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
846 return (NOTOK);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
847 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
850 if (ret)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
851 {
23290
9917b9a0024d (popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents: 23182
diff changeset
852 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
853 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
854 Errmsg[sizeof (Errmsg)-1] = '\0';
23290
9917b9a0024d (popmail, pop_retr) [MAIL_USE_POP]: When displaying
Karl Heuer <kwzh@gnu.org>
parents: 23182
diff changeset
855 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
856 return (NOTOK);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 }
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
858
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
859 return (OK);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
862 /* 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
863 #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
864 && (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
865 && (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
866 && (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
867 && (a[4] == ' '))
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
869 static int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
870 mbx_write (char *line, int len, FILE *mbf)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871 {
20387
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
872 #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
873 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
874 {
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
875 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
876 return (NOTOK);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
877 }
20387
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
878 #endif
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
879 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
880 {
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
881 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
882 return (NOTOK);
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
883 line++;
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
884 len--;
4c524f5214ce (mbx_write) [MAIL_USE_POP]: Disable the code which quotes with a
Paul Eggert <eggert@twinsun.com>
parents: 18626
diff changeset
885 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48314
diff changeset
886 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
887 return (NOTOK);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
888 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
889 return (NOTOK);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
890 return (OK);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
893 static int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
894 mbx_delimit_begin (FILE *mbf)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 {
101936
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
896 time_t now;
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
897 struct tm *ltime;
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
898 char fromline[40] = "From movemail ";
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
899
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
900 now = time (NULL);
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
901 ltime = localtime (&now);
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
902
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
903 strcat (fromline, asctime (ltime));
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
904
696b3e7c297b (mbx_delimit_begin): Also write the current time.
Glenn Morris <rgm@gnu.org>
parents: 101915
diff changeset
905 if (fputs (fromline, mbf) == EOF)
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
906 return (NOTOK);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
907 return (OK);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909
109150
3f9a67cdf9f7 Clean up movemail source
Andreas Schwab <schwab@linux-m68k.org>
parents: 109149
diff changeset
910 static int
109111
52b76722152a Convert function definitions to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
911 mbx_delimit_end (FILE *mbf)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 {
101915
091a8cf73243 (mbx_delimit_begin, mbx_delimit_end): Write mbox rather than Babyl
Glenn Morris <rgm@gnu.org>
parents: 100958
diff changeset
913 if (putc ('\n', mbf) == EOF)
9157
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
914 return (NOTOK);
29f4cce05fa5 Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents: 8449
diff changeset
915 return (OK);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 #endif /* MAIL_USE_POP */
5532
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
919
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
920 #ifndef HAVE_STRERROR
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
921 char *
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
922 strerror (errnum)
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
923 int errnum;
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
924 {
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
925 extern char *sys_errlist[];
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
926 extern int sys_nerr;
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
927
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
928 if (errnum >= 0 && errnum < sys_nerr)
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
929 return sys_errlist[errnum];
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
930 return (char *) "Unknown error";
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
931 }
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
932
9c86c71e879d [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5524
diff changeset
933 #endif /* ! HAVE_STRERROR */
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
934
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
935
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
936 /* movemail.c ends here */