annotate lib-src/movemail.c @ 5389:09148c696fa2

(save-some-buffers): Reinsert lost code to save abbrevs.
author Richard M. Stallman <rms@gnu.org>
date Fri, 31 Dec 1993 12:50:12 +0000
parents 60fa1ee0c98c
children d7408b99b88f
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.
580
c8860f81ccf7 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 571
diff changeset
3 Copyright (C) 1986, 1992 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
056b931d312b *** empty log message ***
Joseph Arceneaux <jla@gnu.org>
parents: 27
diff changeset
9 the Free Software Foundation; either version 1, or (at your option)
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
510
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
21 /* Important notice: defining MAIL_USE_FLOCK *will cause loss of mail*
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
22 if you do it on a system that does not normally use flock as its way of
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
23 interlocking access to inbox files. The setting of MAIL_USE_FLOCK
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
24 *must agree* with the system's own conventions.
4eaef1578a15 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 447
diff changeset
25 It is not a choice that is up to you.
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 *
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 #include <sys/types.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 #include <sys/stat.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 #include <sys/file.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 #include <errno.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 #define NO_SHORTNAMES /* Tell config not to load remap.h */
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3309
diff changeset
56 #include <../src/config.h>
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 #ifdef USG
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 #include <fcntl.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 #include <unistd.h>
27
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
61 #ifndef F_OK
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
62 #define F_OK 0
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
63 #define X_OK 1
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
64 #define W_OK 2
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
65 #define R_OK 4
f60b88b46f97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 25
diff changeset
66 #endif
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 #endif /* USG */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 #ifdef XENIX
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 #include <sys/locking.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 #endif
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
73 #ifdef MAIL_USE_MMDF
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
74 extern int lk_open (), lk_close ();
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
75 #endif
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
76
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 /* Cancel substitutions made by config.h for Emacs. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 #undef open
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 #undef read
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 #undef write
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 #undef close
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
83 char *malloc ();
733
62dd28940dc6 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 634
diff changeset
84 char *strcpy ();
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 char *concat ();
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
86 char *xmalloc ();
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
87 #ifndef errno
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 extern int errno;
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
89 #endif
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 /* 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
92 char *delete_lockname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 main (argc, argv)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 int argc;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 char **argv;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 char *inname, *outname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 int indesc, outdesc;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 int nread;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 #ifndef MAIL_USE_FLOCK
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 struct stat st;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 long now;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 int tem;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 char *lockname, *p;
601
3db1540d4b97 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 580
diff changeset
107 char *tempname;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 int desc;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 #endif /* not MAIL_USE_FLOCK */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 delete_lockname = 0;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 if (argc < 3)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 fatal ("two arguments required");
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 inname = argv[1];
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 outname = argv[2];
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
119 #ifdef MAIL_USE_MMDF
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
120 mmdf_init (argv[0]);
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
121 #endif
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
122
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
123 /* Check access to output file. */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 pfatal_with_name (outname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 /* Also check that outname's directory is writeable to the real uid. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 char *buf = (char *) malloc (strlen (outname) + 1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 char *p, q;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 strcpy (buf, outname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 p = buf + strlen (buf);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 while (p > buf && p[-1] != '/')
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 *--p = 0;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 if (p == buf)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 *p++ = '.';
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 if (access (buf, W_OK) != 0)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 pfatal_with_name (buf);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 free (buf);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 #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
143 if (!strncmp (inname, "po:", 3))
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 int status; char *user;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
3309
f00054d40753 * movemail.c [MAIL_USE_POP] (main): Don't use non-portable
Jim Blandy <jimb@redhat.com>
parents: 733
diff changeset
147 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
148 if (*user == ':')
f00054d40753 * movemail.c [MAIL_USE_POP] (main): Don't use non-portable
Jim Blandy <jimb@redhat.com>
parents: 733
diff changeset
149 break;
f00054d40753 * movemail.c [MAIL_USE_POP] (main): Don't use non-portable
Jim Blandy <jimb@redhat.com>
parents: 733
diff changeset
150
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 status = popmail (user, outname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 exit (status);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
155 setuid (getuid ());
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 #endif /* MAIL_USE_POP */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
158 /* Check access to input file. */
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
159 if (access (inname, R_OK | W_OK) != 0)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
160 pfatal_with_name (inname);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
161
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
162 #ifndef MAIL_USE_MMDF
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 #ifndef MAIL_USE_FLOCK
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 /* Use a lock file named /usr/spool/mail/$USER.lock:
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 If it exists, the mail file is locked. */
351
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
166 /* Note: this locking mechanism is *required* by the mailer
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
167 (on systems which use it) to prevent loss of mail.
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
168
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
169 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
170 WILL occasionally cause loss of mail due to timing errors!
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
171
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
172 So, if creation of the lock file fails
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
173 due to access permission on /usr/spool/mail,
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
174 you simply MUST change the permission
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
175 and/or make movemail a setgid program
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
176 so it can create lock files properly.
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
177
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
178 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
179 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
180
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
181 If your system uses the `flock' system call for mail locking,
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
182 define MAIL_USE_FLOCK in config.h or the s-*.h file
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
183 and recompile movemail. If the s- file for your system
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
184 should define MAIL_USE_FLOCK but does not, send a bug report
5729b1cc3942 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 127
diff changeset
185 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
186
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 lockname = concat (inname, ".lock", "");
5318
60fa1ee0c98c (main): When making tempname, cast result of xmalloc.
Richard M. Stallman <rms@gnu.org>
parents: 4985
diff changeset
188 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
189 strcpy (tempname, inname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 p = tempname + strlen (tempname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 while (p != tempname && p[-1] != '/')
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 p--;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 *p = 0;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 strcpy (p, "EXXXXXX");
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 mktemp (tempname);
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
196 unlink (tempname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 while (1)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 /* Create the lock file, but not under the lock file name. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 /* Give up if cannot do that. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 desc = open (tempname, O_WRONLY | O_CREAT, 0666);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 if (desc < 0)
4985
623be452ebb8 (main): Fix error message text.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
204 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
205 close (desc);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 tem = link (tempname, lockname);
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
208 unlink (tempname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 if (tem >= 0)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 break;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 sleep (1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 /* If lock file is a minute old, unlock it. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 if (stat (lockname, &st) >= 0)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 now = time (0);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 if (st.st_ctime < now - 60)
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
218 unlink (lockname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 delete_lockname = lockname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 #endif /* not MAIL_USE_FLOCK */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 #ifdef MAIL_USE_FLOCK
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 indesc = open (inname, O_RDWR);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 #else /* if not MAIL_USE_FLOCK */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 indesc = open (inname, O_RDONLY);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 #endif /* not MAIL_USE_FLOCK */
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
230 #else /* MAIL_USE_MMDF */
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
231 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
232 #endif /* MAIL_USE_MMDF */
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
233
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 if (indesc < 0)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 pfatal_with_name (inname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
237 #if defined (BSD) || defined (XENIX)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 /* In case movemail is setuid to root, make sure the user can
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 read the output file. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 /* This is desirable for all systems
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 but I don't want to assume all have the umask system call */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 umask (umask (0) & 0333);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 #endif /* BSD or Xenix */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 if (outdesc < 0)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 pfatal_with_name (outname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 #ifdef MAIL_USE_FLOCK
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 #ifdef XENIX
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 #else
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 #endif
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 #endif /* MAIL_USE_FLOCK */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
604
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
255 {
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
256 char buf[1024];
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
257
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
258 while (1)
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
259 {
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
260 nread = read (indesc, buf, sizeof buf);
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
261 if (nread != write (outdesc, buf, nread))
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
262 {
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
263 int saved_errno = errno;
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
264 unlink (outname);
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
265 errno = saved_errno;
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
266 pfatal_with_name (outname);
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
267 }
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
268 if (nread < sizeof buf)
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
269 break;
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
270 }
63a8e7b3c547 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 601
diff changeset
271 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 #ifdef BSD
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
274 if (fsync (outdesc) < 0)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
275 pfatal_and_delete (outname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 #endif
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 /* Check to make sure no errors before we zap the inbox. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 if (close (outdesc) != 0)
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
280 pfatal_and_delete (outname);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 #ifdef MAIL_USE_FLOCK
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
283 #if defined (STRIDE) || defined (XENIX)
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
285 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 #else
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
287 ftruncate (indesc, 0L);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 #endif /* STRIDE or XENIX */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 #endif /* MAIL_USE_FLOCK */
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
290
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
291 #ifdef MAIL_USE_MMDF
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
292 lk_close (indesc, 0, 0, 0);
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
293 #else
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 close (indesc);
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
295 #endif
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 #ifndef MAIL_USE_FLOCK
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 /* Delete the input file; if we can't, at least get rid of its contents. */
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
299 #ifdef MAIL_UNLINK_SPOOL
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
300 /* This is generally bad to do, because it destroys the permissions
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
301 that were set on the file. Better to just empty the file. */
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
302 if (unlink (inname) < 0 && errno != ENOENT)
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
303 #endif /* MAIL_UNLINK_SPOOL */
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
304 creat (inname, 0600);
25
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
305 #ifndef MAIL_USE_MMDF
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
306 unlink (lockname);
b446124cdf5a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 23
diff changeset
307 #endif /* not MAIL_USE_MMDF */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 #endif /* not MAIL_USE_FLOCK */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 exit (0);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 /* Print error message and exit. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 fatal (s1, s2)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 char *s1, *s2;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 if (delete_lockname)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 unlink (delete_lockname);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 error (s1, s2);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 exit (1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 /* 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
324
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
325 error (s1, s2, s3)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
326 char *s1, *s2, *s3;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 printf ("movemail: ");
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
329 printf (s1, s2, s3);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 printf ("\n");
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 pfatal_with_name (name)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 char *name;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 extern int errno, sys_nerr;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 extern char *sys_errlist[];
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 char *s;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 if (errno < sys_nerr)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 s = concat ("", sys_errlist[errno], " for %s");
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 else
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 s = "cannot open %s";
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 fatal (s, name);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
347 pfatal_and_delete (name)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
348 char *name;
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
349 {
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
350 extern int errno, sys_nerr;
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
351 extern char *sys_errlist[];
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
352 char *s;
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
353
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
354 if (errno < sys_nerr)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
355 s = concat ("", sys_errlist[errno], " for %s");
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
356 else
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
357 s = "cannot open %s";
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
358
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
359 unlink (name);
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
360 fatal (s, name);
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
361 }
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
362
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 /* 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
364
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 char *
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 concat (s1, s2, s3)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 char *s1, *s2, *s3;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 {
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 strcpy (result, s1);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 strcpy (result + len1, s2);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 strcpy (result + len1 + len2, s3);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 *(result + len1 + len2 + len3) = 0;
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 return result;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 /* Like malloc but get fatal error if memory is exhausted. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
382 char *
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 xmalloc (size)
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
384 unsigned size;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 {
571
3dfecf91a09b *** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents: 510
diff changeset
386 char *result = malloc (size);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 if (!result)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 fatal ("virtual memory exhausted", 0);
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 return result;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 /* This is the guts of the interface to the Post Office Protocol. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 #ifdef MAIL_USE_POP
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 #include <sys/socket.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 #include <netinet/in.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 #include <netdb.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 #include <stdio.h>
634
52d0ff659265 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 604
diff changeset
400 #include <pwd.h>
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 #ifdef USG
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 #include <fcntl.h>
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 /* Cancel substitutions made by config.h for Emacs. */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 #undef open
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 #undef read
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 #undef write
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 #undef close
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 #endif /* USG */
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 #define NOTOK (-1)
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 #define OK 0
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 #define DONE 1
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 char *progname;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 FILE *sfi;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 FILE *sfo;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 char Errmsg[80];
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 static int debug = 0;
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
422 char *get_errmsg ();
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
423 char *getenv ();
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
424 int mbx_write ();
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
425
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
426 popmail (user, outfile)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
427 char *user;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
428 char *outfile;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
430 char *host;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
431 int nmsgs, nbytes;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
432 char response[128];
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
433 register int i;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
434 int mbfi;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
435 FILE *mbf;
634
52d0ff659265 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 604
diff changeset
436 struct passwd *pw = (struct passwd *) getpwuid (getuid ());
52d0ff659265 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 604
diff changeset
437 if (pw == NULL)
52d0ff659265 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 604
diff changeset
438 fatal ("cannot determine user name");
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
440 host = getenv ("MAILHOST");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
441 if (host == NULL)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
442 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
443 fatal ("no MAILHOST defined");
23
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
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
446 if (pop_init (host) == NOTOK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
447 {
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
448 fatal (Errmsg);
23
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
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
451 if (getline (response, sizeof response, sfi) != OK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
452 {
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
453 fatal (response);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
456 if (pop_command ("USER %s", user) == NOTOK
634
52d0ff659265 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 604
diff changeset
457 || pop_command ("RPOP %s", pw->pw_name) == NOTOK)
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
458 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
459 pop_command ("QUIT");
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
460 fatal (Errmsg);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
463 if (pop_stat (&nmsgs, &nbytes) == NOTOK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
464 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
465 pop_command ("QUIT");
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
466 fatal (Errmsg);
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
467 }
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
469 if (!nmsgs)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
470 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
471 pop_command ("QUIT");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
472 return 0;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
475 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
476 if (mbfi < 0)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
477 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
478 pop_command ("QUIT");
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
479 pfatal_and_delete (outfile);
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
480 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
481 fchown (mbfi, getuid (), -1);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
482
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
483 if ((mbf = fdopen (mbfi, "w")) == NULL)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
484 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
485 pop_command ("QUIT");
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
486 pfatal_and_delete (outfile);
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
487 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
488
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
489 for (i = 1; i <= nmsgs; i++)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
490 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
491 mbx_delimit_begin (mbf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
492 if (pop_retr (i, mbx_write, mbf) != OK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
493 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
494 pop_command ("QUIT");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
495 close (mbfi);
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
496 unlink (outfile);
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
497 fatal (Errmsg);
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
498 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
499 mbx_delimit_end (mbf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
500 fflush (mbf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
501 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
502
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
503 if (fsync (mbfi) < 0)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
504 {
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
505 pop_command ("QUIT");
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
506 pfatal_and_delete (outfile);
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
507 }
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
508
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
509 if (close (mbfi) == -1)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
510 {
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
511 pop_command ("QUIT");
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
512 pfatal_and_delete (outfile);
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
513 }
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
514
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
515 for (i = 1; i <= nmsgs; i++)
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 (pop_command ("DELE %d", i) == NOTOK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
518 {
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
519 /* Better to ignore this failure. */
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
523 pop_command ("QUIT");
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
524 return (0);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
527 pop_init (host)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
528 char *host;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
530 register struct hostent *hp;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
531 register struct servent *sp;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
532 int lport = IPPORT_RESERVED - 1;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
533 struct sockaddr_in sin;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
534 register int s;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
536 hp = gethostbyname (host);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
537 if (hp == NULL)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
538 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
539 sprintf (Errmsg, "MAILHOST unknown: %s", host);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
540 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
543 sp = getservbyname ("pop", "tcp");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
544 if (sp == 0)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
545 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
546 strcpy (Errmsg, "tcp/pop: unknown service");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
547 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
550 sin.sin_family = hp->h_addrtype;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
551 bcopy (hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
552 sin.sin_port = sp->s_port;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
553 s = rresvport (&lport);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
554 if (s < 0)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
555 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
556 sprintf (Errmsg, "error creating socket: %s", get_errmsg ());
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
557 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
560 if (connect (s, (char *)&sin, sizeof sin) < 0)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
561 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
562 sprintf (Errmsg, "error during connect: %s", get_errmsg ());
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
563 close (s);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
564 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
567 sfi = fdopen (s, "r");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
568 sfo = fdopen (s, "w");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
569 if (sfi == NULL || sfo == NULL)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
570 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
571 sprintf (Errmsg, "error in fdopen: %s", get_errmsg ());
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
572 close (s);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
573 return NOTOK;
23
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
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
576 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
579 pop_command (fmt, a, b, c, d)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
580 char *fmt;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
582 char buf[128];
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
583 char errmsg[64];
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
584
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
585 sprintf (buf, fmt, a, b, c, d);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
587 if (debug) fprintf (stderr, "---> %s\n", buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
588 if (putline (buf, Errmsg, sfo) == NOTOK) return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
590 if (getline (buf, sizeof buf, sfi) != OK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
591 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
592 strcpy (Errmsg, buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
593 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
596 if (debug)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
597 fprintf (stderr, "<--- %s\n", buf);
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
598 if (*buf != '+')
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
599 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
600 strcpy (Errmsg, buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
601 return NOTOK;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
602 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
603 else
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
604 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
605 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
610 pop_stat (nmsgs, nbytes)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
611 int *nmsgs, *nbytes;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
613 char buf[128];
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
615 if (debug)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
616 fprintf (stderr, "---> STAT\n");
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
617 if (putline ("STAT", Errmsg, sfo) == NOTOK)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
618 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
620 if (getline (buf, sizeof buf, sfi) != OK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
621 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
622 strcpy (Errmsg, buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
623 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
626 if (debug) fprintf (stderr, "<--- %s\n", buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
627 if (*buf != '+')
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
628 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
629 strcpy (Errmsg, buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
630 return NOTOK;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
631 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
632 else
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
633 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
634 sscanf (buf, "+OK %d %d", nmsgs, nbytes);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
635 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
639 pop_retr (msgno, action, arg)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
640 int (*action)();
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
642 char buf[128];
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
644 sprintf (buf, "RETR %d", msgno);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
645 if (debug) fprintf (stderr, "%s\n", buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
646 if (putline (buf, Errmsg, sfo) == NOTOK) return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
648 if (getline (buf, sizeof buf, sfi) != OK)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
649 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
650 strcpy (Errmsg, buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
651 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
654 while (1)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
655 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
656 switch (multiline (buf, sizeof buf, sfi))
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
657 {
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 case OK:
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
659 (*action)(buf, arg);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
660 break;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 case DONE:
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
662 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 case NOTOK:
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
664 strcpy (Errmsg, buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
665 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
670 getline (buf, n, f)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
671 char *buf;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
672 register int n;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
673 FILE *f;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
675 register char *p;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
676 int c;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
678 p = buf;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
679 while (--n > 0 && (c = fgetc (f)) != EOF)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
680 if ((*p++ = c) == '\n') break;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
682 if (ferror (f))
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
683 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
684 strcpy (buf, "error on connection");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
685 return NOTOK;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
686 }
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
687
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
688 if (c == EOF && p == buf)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
689 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
690 strcpy (buf, "connection closed by foreign host");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
691 return DONE;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
694 *p = NULL;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
695 if (*--p == '\n') *p = NULL;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
696 if (*--p == '\r') *p = NULL;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
697 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
700 multiline (buf, n, f)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
701 char *buf;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
702 register int n;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
703 FILE *f;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 {
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
705 if (getline (buf, n, f) != OK)
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
706 return NOTOK;
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
707 if (*buf == '.')
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
708 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
709 if (*(buf+1) == NULL)
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
710 return DONE;
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
711 else
447
2e226dcdaf0f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 351
diff changeset
712 strcpy (buf, buf+1);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 }
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
714 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 char *
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
718 get_errmsg ()
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
720 extern int errno, sys_nerr;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
721 extern char *sys_errlist[];
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
722 char *s;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
724 if (errno < sys_nerr)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
725 s = sys_errlist[errno];
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
726 else
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
727 s = "unknown error";
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
728 return (s);
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 putline (buf, err, f)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
732 char *buf;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
733 char *err;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
734 FILE *f;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
736 fprintf (f, "%s\r\n", buf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
737 fflush (f);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
738 if (ferror (f))
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
739 {
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
740 strcpy (err, "lost connection");
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
741 return NOTOK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 }
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
743 return OK;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
746 mbx_write (line, mbf)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
747 char *line;
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
748 FILE *mbf;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
750 fputs (line, mbf);
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
751 fputc (0x0a, mbf);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
754 mbx_delimit_begin (mbf)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
755 FILE *mbf;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 {
127
762710f7381a *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 120
diff changeset
757 fputs ("\f\n0, unseen,,\n", mbf);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
760 mbx_delimit_end (mbf)
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
761 FILE *mbf;
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 {
120
86f080a3d883 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 38
diff changeset
763 putc ('\037', mbf);
23
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 }
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765
b437d0778a66 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 #endif /* MAIL_USE_POP */