annotate lib-src/movemail.c @ 464:4ddaee1a9029

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