annotate lib-src/movemail.c @ 9107:46461644055b

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