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