annotate lib-src/movemail.c @ 12144:12720a817d83

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