Mercurial > emacs
annotate lib-src/movemail.c @ 9157:29f4cce05fa5
Improve POP code, move most of it into a separate file.
(mbx_delimit_end, mbx_delimit_begin): Check for errors.
(mbx_write): Check for errors and for From line.
(pop_retr, popmail): Use subroutines in pop.c to do the real work.
(get_errmsg, multiline, getline, putline, pop_stat, pop_command)
(pop_init): Functions deleted.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Tue, 27 Sep 1994 19:45:00 +0000 |
| parents | 805f9284065b |
| children | 4e70299f958d |
| 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 * | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
49 * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
50 * |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
51 * Move all of the POP code into a separate file, "pop.c". |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
52 * Use strerror instead of get_errmsg. |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
53 * |
| 23 | 54 */ |
| 55 | |
|
8449
805f9284065b
Include config.h first thing.
Richard M. Stallman <rms@gnu.org>
parents:
6862
diff
changeset
|
56 #define NO_SHORTNAMES /* Tell config not to load remap.h */ |
|
805f9284065b
Include config.h first thing.
Richard M. Stallman <rms@gnu.org>
parents:
6862
diff
changeset
|
57 #include <../src/config.h> |
| 23 | 58 #include <sys/types.h> |
| 59 #include <sys/stat.h> | |
| 60 #include <sys/file.h> | |
| 61 #include <errno.h> | |
| 5435 | 62 #include <../src/syswait.h> |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
63 #ifdef MAIL_USE_POP |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
64 #include "pop.h" |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
65 #endif |
| 23 | 66 |
|
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
67 #ifdef MSDOS |
|
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
68 #undef access |
|
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
69 #endif /* MSDOS */ |
|
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
70 |
| 23 | 71 #ifdef USG |
| 72 #include <fcntl.h> | |
| 73 #include <unistd.h> | |
| 27 | 74 #ifndef F_OK |
| 75 #define F_OK 0 | |
| 76 #define X_OK 1 | |
| 77 #define W_OK 2 | |
| 78 #define R_OK 4 | |
| 79 #endif | |
| 23 | 80 #endif /* USG */ |
| 81 | |
|
6862
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
82 #ifdef HAVE_UNISTD_H |
|
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
83 #include <unistd.h> |
|
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
84 #endif |
|
653504b6b5dd
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
6813
diff
changeset
|
85 |
| 23 | 86 #ifdef XENIX |
| 87 #include <sys/locking.h> | |
| 88 #endif | |
| 89 | |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
90 #ifdef MAIL_USE_LOCKF |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
91 #define MAIL_USE_SYSTEM_LOCK |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
92 #endif |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
93 |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
94 #ifdef MAIL_USE_FLOCK |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
95 #define MAIL_USE_SYSTEM_LOCK |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
96 #endif |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
97 |
| 25 | 98 #ifdef MAIL_USE_MMDF |
| 99 extern int lk_open (), lk_close (); | |
| 100 #endif | |
| 101 | |
| 23 | 102 /* Cancel substitutions made by config.h for Emacs. */ |
| 103 #undef open | |
| 104 #undef read | |
| 105 #undef write | |
| 106 #undef close | |
| 107 | |
| 108 char *concat (); | |
| 571 | 109 char *xmalloc (); |
| 110 #ifndef errno | |
| 23 | 111 extern int errno; |
| 571 | 112 #endif |
| 23 | 113 |
| 114 /* Nonzero means this is name of a lock file to delete on fatal error. */ | |
| 115 char *delete_lockname; | |
| 116 | |
| 117 main (argc, argv) | |
| 118 int argc; | |
| 119 char **argv; | |
| 120 { | |
| 121 char *inname, *outname; | |
| 122 int indesc, outdesc; | |
| 123 int nread; | |
| 5435 | 124 WAITTYPE status; |
| 23 | 125 |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
126 #ifndef MAIL_USE_SYSTEM_LOCK |
| 23 | 127 struct stat st; |
| 128 long now; | |
| 129 int tem; | |
| 130 char *lockname, *p; | |
|
601
3db1540d4b97
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
580
diff
changeset
|
131 char *tempname; |
| 23 | 132 int desc; |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
133 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 23 | 134 |
| 135 delete_lockname = 0; | |
| 136 | |
| 137 if (argc < 3) | |
| 138 fatal ("two arguments required"); | |
| 139 | |
| 140 inname = argv[1]; | |
| 141 outname = argv[2]; | |
| 142 | |
| 25 | 143 #ifdef MAIL_USE_MMDF |
| 144 mmdf_init (argv[0]); | |
| 145 #endif | |
| 146 | |
| 120 | 147 /* Check access to output file. */ |
| 23 | 148 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) |
| 149 pfatal_with_name (outname); | |
| 150 | |
| 151 /* Also check that outname's directory is writeable to the real uid. */ | |
| 152 { | |
|
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
153 char *buf = (char *) xmalloc (strlen (outname) + 1); |
| 23 | 154 char *p, q; |
| 155 strcpy (buf, outname); | |
| 156 p = buf + strlen (buf); | |
| 157 while (p > buf && p[-1] != '/') | |
| 158 *--p = 0; | |
| 159 if (p == buf) | |
| 160 *p++ = '.'; | |
| 161 if (access (buf, W_OK) != 0) | |
| 162 pfatal_with_name (buf); | |
| 163 free (buf); | |
| 164 } | |
| 165 | |
| 166 #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
|
167 if (!strncmp (inname, "po:", 3)) |
| 23 | 168 { |
| 169 int status; char *user; | |
| 170 | |
|
3309
f00054d40753
* movemail.c [MAIL_USE_POP] (main): Don't use non-portable
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
171 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
|
172 if (*user == ':') |
|
f00054d40753
* movemail.c [MAIL_USE_POP] (main): Don't use non-portable
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
173 break; |
|
f00054d40753
* movemail.c [MAIL_USE_POP] (main): Don't use non-portable
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
174 |
| 23 | 175 status = popmail (user, outname); |
| 176 exit (status); | |
| 177 } | |
| 178 | |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
179 setuid (getuid ()); |
| 23 | 180 #endif /* MAIL_USE_POP */ |
| 181 | |
| 120 | 182 /* Check access to input file. */ |
| 183 if (access (inname, R_OK | W_OK) != 0) | |
| 184 pfatal_with_name (inname); | |
| 185 | |
| 25 | 186 #ifndef MAIL_USE_MMDF |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
187 #ifndef MAIL_USE_SYSTEM_LOCK |
| 23 | 188 /* Use a lock file named /usr/spool/mail/$USER.lock: |
| 189 If it exists, the mail file is locked. */ | |
|
351
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
190 /* Note: this locking mechanism is *required* by the mailer |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
191 (on systems which use it) to prevent loss of mail. |
|
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 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
|
194 WILL occasionally cause loss of mail due to timing errors! |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
195 |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
196 So, if creation of the lock file fails |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
197 due to access permission on /usr/spool/mail, |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
198 you simply MUST change the permission |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
199 and/or make movemail a setgid program |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
200 so it can create lock files properly. |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
201 |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
202 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
|
203 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
|
204 |
|
5729b1cc3942
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
127
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 |
| 23 | 211 lockname = concat (inname, ".lock", ""); |
|
5318
60fa1ee0c98c
(main): When making tempname, cast result of xmalloc.
Richard M. Stallman <rms@gnu.org>
parents:
4985
diff
changeset
|
212 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
|
213 strcpy (tempname, inname); |
| 23 | 214 p = tempname + strlen (tempname); |
| 215 while (p != tempname && p[-1] != '/') | |
| 216 p--; | |
| 217 *p = 0; | |
| 218 strcpy (p, "EXXXXXX"); | |
| 219 mktemp (tempname); | |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
220 unlink (tempname); |
| 23 | 221 |
| 222 while (1) | |
| 223 { | |
| 224 /* Create the lock file, but not under the lock file name. */ | |
| 225 /* Give up if cannot do that. */ | |
| 5435 | 226 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
| 23 | 227 if (desc < 0) |
| 5435 | 228 pfatal_with_name ("lock file--see source file lib-src/movemail.c"); |
| 23 | 229 close (desc); |
| 230 | |
| 231 tem = link (tempname, lockname); | |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
232 unlink (tempname); |
| 23 | 233 if (tem >= 0) |
| 234 break; | |
| 235 sleep (1); | |
| 236 | |
| 237 /* If lock file is a minute old, unlock it. */ | |
| 238 if (stat (lockname, &st) >= 0) | |
| 239 { | |
| 240 now = time (0); | |
| 241 if (st.st_ctime < now - 60) | |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
242 unlink (lockname); |
| 23 | 243 } |
| 244 } | |
| 245 | |
| 246 delete_lockname = lockname; | |
|
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 */ |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
248 #endif /* not MAIL_USE_MMDF */ |
| 23 | 249 |
| 5435 | 250 if (fork () == 0) |
| 251 { | |
|
6813
76f93e487956
(main): Use setuid, not seteuid.
Karl Heuer <kwzh@gnu.org>
parents:
6690
diff
changeset
|
252 setuid (getuid ()); |
| 5435 | 253 |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
254 #ifndef MAIL_USE_MMDF |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
255 #ifdef MAIL_USE_SYSTEM_LOCK |
| 5435 | 256 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
|
257 #else /* if not MAIL_USE_SYSTEM_LOCK */ |
| 5435 | 258 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
|
259 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 5435 | 260 #else /* MAIL_USE_MMDF */ |
| 261 indesc = lk_open (inname, O_RDONLY, 0, 0, 10); | |
| 25 | 262 #endif /* MAIL_USE_MMDF */ |
| 263 | |
| 5435 | 264 if (indesc < 0) |
| 265 pfatal_with_name (inname); | |
| 23 | 266 |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
267 #if defined (BSD) || defined (XENIX) |
| 5435 | 268 /* In case movemail is setuid to root, make sure the user can |
| 269 read the output file. */ | |
| 270 /* This is desirable for all systems | |
| 271 but I don't want to assume all have the umask system call */ | |
| 272 umask (umask (0) & 0333); | |
| 23 | 273 #endif /* BSD or Xenix */ |
| 5435 | 274 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); |
| 275 if (outdesc < 0) | |
| 276 pfatal_with_name (outname); | |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
277 #ifdef MAIL_USE_SYSTEM_LOCK |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
278 #ifdef MAIL_USE_LOCKF |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
279 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
|
280 #else /* not MAIL_USE_LOCKF */ |
| 23 | 281 #ifdef XENIX |
| 5435 | 282 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname); |
| 23 | 283 #else |
| 5435 | 284 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname); |
| 23 | 285 #endif |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
286 #endif /* not MAIL_USE_LOCKF */ |
|
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
287 #endif /* MAIL_USE_SYSTEM_LOCK */ |
| 23 | 288 |
| 5435 | 289 { |
| 290 char buf[1024]; | |
| 604 | 291 |
| 5435 | 292 while (1) |
| 604 | 293 { |
| 5435 | 294 nread = read (indesc, buf, sizeof buf); |
| 295 if (nread != write (outdesc, buf, nread)) | |
| 296 { | |
| 297 int saved_errno = errno; | |
| 298 unlink (outname); | |
| 299 errno = saved_errno; | |
| 300 pfatal_with_name (outname); | |
| 301 } | |
| 302 if (nread < sizeof buf) | |
| 303 break; | |
| 604 | 304 } |
| 305 } | |
| 23 | 306 |
| 307 #ifdef BSD | |
| 5435 | 308 if (fsync (outdesc) < 0) |
| 309 pfatal_and_delete (outname); | |
| 23 | 310 #endif |
| 311 | |
| 5435 | 312 /* Check to make sure no errors before we zap the inbox. */ |
| 313 if (close (outdesc) != 0) | |
| 314 pfatal_and_delete (outname); | |
| 23 | 315 |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
316 #ifdef MAIL_USE_SYSTEM_LOCK |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
317 #if defined (STRIDE) || defined (XENIX) |
| 5435 | 318 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ |
| 319 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); | |
| 23 | 320 #else |
| 5435 | 321 ftruncate (indesc, 0L); |
| 23 | 322 #endif /* STRIDE or XENIX */ |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
323 #endif /* MAIL_USE_SYSTEM_LOCK */ |
| 25 | 324 |
| 325 #ifdef MAIL_USE_MMDF | |
| 5435 | 326 lk_close (indesc, 0, 0, 0); |
| 25 | 327 #else |
| 5435 | 328 close (indesc); |
| 25 | 329 #endif |
| 23 | 330 |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
331 #ifndef MAIL_USE_SYSTEM_LOCK |
|
5532
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
332 /* 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
|
333 contents. */ |
| 571 | 334 #ifdef MAIL_UNLINK_SPOOL |
| 5435 | 335 /* This is generally bad to do, because it destroys the permissions |
| 336 that were set on the file. Better to just empty the file. */ | |
| 337 if (unlink (inname) < 0 && errno != ENOENT) | |
| 571 | 338 #endif /* MAIL_UNLINK_SPOOL */ |
| 5435 | 339 creat (inname, 0600); |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
340 #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 5435 | 341 |
| 342 exit (0); | |
| 343 } | |
| 344 | |
| 345 wait (&status); | |
| 346 if (!WIFEXITED (status)) | |
| 347 exit (1); | |
| 348 else if (WRETCODE (status) != 0) | |
| 349 exit (WRETCODE (status)); | |
| 350 | |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
351 #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK) |
| 25 | 352 unlink (lockname); |
|
6690
a1a42eefcc61
(main): Fix up MAIL_USE_MMDF conditional where
Richard M. Stallman <rms@gnu.org>
parents:
5532
diff
changeset
|
353 #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */ |
| 23 | 354 exit (0); |
| 355 } | |
| 356 | |
| 357 /* Print error message and exit. */ | |
| 358 | |
| 359 fatal (s1, s2) | |
| 360 char *s1, *s2; | |
| 361 { | |
| 362 if (delete_lockname) | |
| 363 unlink (delete_lockname); | |
| 364 error (s1, s2); | |
| 365 exit (1); | |
| 366 } | |
| 367 | |
| 368 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | |
| 369 | |
| 120 | 370 error (s1, s2, s3) |
| 371 char *s1, *s2, *s3; | |
| 23 | 372 { |
| 373 printf ("movemail: "); | |
| 120 | 374 printf (s1, s2, s3); |
| 23 | 375 printf ("\n"); |
| 376 } | |
| 377 | |
| 378 pfatal_with_name (name) | |
| 379 char *name; | |
| 380 { | |
|
5524
f14a0fe979d9
(get_errmsg, pfatal_with_name, pfatal_and_delete): Call strerror instead of
Roland McGrath <roland@gnu.org>
parents:
5446
diff
changeset
|
381 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
|
382 extern char *strerror (); |
| 23 | 383 char *s; |
| 384 | |
|
5524
f14a0fe979d9
(get_errmsg, pfatal_with_name, pfatal_and_delete): Call strerror instead of
Roland McGrath <roland@gnu.org>
parents:
5446
diff
changeset
|
385 s = concat ("", strerror (errno), " for %s"); |
| 23 | 386 fatal (s, name); |
| 387 } | |
| 388 | |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
389 pfatal_and_delete (name) |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
390 char *name; |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
391 { |
|
5524
f14a0fe979d9
(get_errmsg, pfatal_with_name, pfatal_and_delete): Call strerror instead of
Roland McGrath <roland@gnu.org>
parents:
5446
diff
changeset
|
392 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
|
393 extern char *strerror (); |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
394 char *s; |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
395 |
|
5524
f14a0fe979d9
(get_errmsg, pfatal_with_name, pfatal_and_delete): Call strerror instead of
Roland McGrath <roland@gnu.org>
parents:
5446
diff
changeset
|
396 s = concat ("", strerror (errno), " for %s"); |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
397 unlink (name); |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
398 fatal (s, name); |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
399 } |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
400 |
| 23 | 401 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ |
| 402 | |
| 403 char * | |
| 404 concat (s1, s2, s3) | |
| 405 char *s1, *s2, *s3; | |
| 406 { | |
| 407 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | |
| 408 char *result = (char *) xmalloc (len1 + len2 + len3 + 1); | |
| 409 | |
| 410 strcpy (result, s1); | |
| 411 strcpy (result + len1, s2); | |
| 412 strcpy (result + len1 + len2, s3); | |
| 413 *(result + len1 + len2 + len3) = 0; | |
| 414 | |
| 415 return result; | |
| 416 } | |
| 417 | |
| 418 /* Like malloc but get fatal error if memory is exhausted. */ | |
| 419 | |
| 571 | 420 char * |
| 23 | 421 xmalloc (size) |
| 571 | 422 unsigned size; |
| 23 | 423 { |
|
5446
726a3dc867a6
(malloc): Don't declare it.
Richard M. Stallman <rms@gnu.org>
parents:
5435
diff
changeset
|
424 char *result = (char *) malloc (size); |
| 23 | 425 if (!result) |
| 426 fatal ("virtual memory exhausted", 0); | |
| 427 return result; | |
| 428 } | |
| 429 | |
| 430 /* This is the guts of the interface to the Post Office Protocol. */ | |
| 431 | |
| 432 #ifdef MAIL_USE_POP | |
| 433 | |
| 434 #include <sys/socket.h> | |
| 435 #include <netinet/in.h> | |
| 436 #include <netdb.h> | |
| 437 #include <stdio.h> | |
|
634
52d0ff659265
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
604
diff
changeset
|
438 #include <pwd.h> |
| 23 | 439 |
| 440 #ifdef USG | |
| 441 #include <fcntl.h> | |
| 442 /* Cancel substitutions made by config.h for Emacs. */ | |
| 443 #undef open | |
| 444 #undef read | |
| 445 #undef write | |
| 446 #undef close | |
| 447 #endif /* USG */ | |
| 448 | |
| 449 #define NOTOK (-1) | |
| 450 #define OK 0 | |
| 451 #define DONE 1 | |
| 452 | |
| 453 char *progname; | |
| 454 FILE *sfi; | |
| 455 FILE *sfo; | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
456 char ibuffer[BUFSIZ]; |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
457 char obuffer[BUFSIZ]; |
| 23 | 458 char Errmsg[80]; |
| 459 | |
| 120 | 460 popmail (user, outfile) |
| 461 char *user; | |
| 462 char *outfile; | |
| 23 | 463 { |
| 120 | 464 int nmsgs, nbytes; |
| 465 register int i; | |
| 466 int mbfi; | |
| 467 FILE *mbf; | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
468 char *getenv (); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
469 int mbx_write (); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
470 PopServer server; |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
471 extern char *strerror (); |
| 23 | 472 |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
473 server = pop_open (0, user, 0, POP_NO_GETPASS); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
474 if (! server) |
| 120 | 475 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
476 error (pop_error); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
477 return (1); |
| 23 | 478 } |
| 479 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
480 if (pop_stat (server, &nmsgs, &nbytes)) |
| 120 | 481 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
482 error (pop_error); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
483 return (1); |
| 120 | 484 } |
| 23 | 485 |
| 120 | 486 if (!nmsgs) |
| 487 { | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
488 pop_close (server); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
489 return (0); |
| 23 | 490 } |
| 491 | |
| 120 | 492 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666); |
| 493 if (mbfi < 0) | |
| 494 { | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
495 pop_close (server); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
496 error ("Error in open: %s, %s", strerror (errno), outfile); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
497 return (1); |
| 120 | 498 } |
| 499 fchown (mbfi, getuid (), -1); | |
| 500 | |
| 501 if ((mbf = fdopen (mbfi, "w")) == NULL) | |
| 502 { | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
503 pop_close (server); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
504 error ("Error in fdopen: %s", strerror (errno)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
505 close (mbfi); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
506 unlink (outfile); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
507 return (1); |
| 120 | 508 } |
| 509 | |
| 510 for (i = 1; i <= nmsgs; i++) | |
| 511 { | |
| 512 mbx_delimit_begin (mbf); | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
513 if (pop_retr (server, i, mbx_write, mbf) != OK) |
| 120 | 514 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
515 error (Errmsg); |
| 120 | 516 close (mbfi); |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
517 return (1); |
| 120 | 518 } |
| 519 mbx_delimit_end (mbf); | |
| 520 fflush (mbf); | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
521 if (ferror (mbf)) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
522 { |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
523 error ("Error in fflush: %s", strerror (errno)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
524 pop_close (server); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
525 close (mbfi); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
526 return (1); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
527 } |
| 120 | 528 } |
| 529 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
530 /* On AFS, a call to write only modifies the file in the local |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
531 * workstation's AFS cache. The changes are not written to the server |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
532 * until a call to fsync or close is made. Users with AFS home |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
533 * directories have lost mail when over quota because these checks were |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
534 * not made in previous versions of movemail. */ |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
535 |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
536 if (fsync (mbfi) < 0) |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
537 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
538 error ("Error in fsync: %s", strerror (errno)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
539 return (1); |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
540 } |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
541 |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
542 if (close (mbfi) == -1) |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
543 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
544 error ("Error in close: %s", strerror (errno)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
545 return (1); |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
546 } |
|
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
547 |
| 120 | 548 for (i = 1; i <= nmsgs; i++) |
| 549 { | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
550 if (pop_delete (server, i)) |
| 120 | 551 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
552 error (pop_error); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
553 pop_close (server); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
554 return (1); |
| 23 | 555 } |
| 556 } | |
| 557 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
558 if (pop_quit (server)) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
559 { |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
560 error (pop_error); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
561 return (1); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
562 } |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
563 |
|
447
2e226dcdaf0f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
351
diff
changeset
|
564 return (0); |
| 23 | 565 } |
| 566 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
567 pop_retr (server, msgno, action, arg) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
568 PopServer server; |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
569 int (*action)(); |
| 23 | 570 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
571 extern char *strerror (); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
572 char *line; |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
573 int ret; |
| 23 | 574 |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
575 if (pop_retrieve_first (server, msgno, &line)) |
| 120 | 576 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
577 strncpy (Errmsg, pop_error, sizeof (Errmsg)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
578 Errmsg[sizeof (Errmsg)-1] = '\0'; |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
579 return (NOTOK); |
| 23 | 580 } |
| 581 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
582 while (! (ret = pop_retrieve_next (server, &line))) |
| 120 | 583 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
584 if (! line) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
585 break; |
| 23 | 586 |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
587 if ((*action)(line, arg) != OK) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
588 { |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
589 strcpy (Errmsg, strerror (errno)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
590 pop_close (server); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
591 return (NOTOK); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
592 } |
| 23 | 593 } |
| 594 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
595 if (ret) |
| 120 | 596 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
597 strncpy (Errmsg, pop_error, sizeof (Errmsg)); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
598 Errmsg[sizeof (Errmsg)-1] = '\0'; |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
599 return (NOTOK); |
| 23 | 600 } |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
601 |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
602 return (OK); |
| 23 | 603 } |
| 604 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
605 /* Do this as a macro instead of using strcmp to save on execution time. */ |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
606 #define IS_FROM_LINE(a) ((a[0] == 'F') \ |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
607 && (a[1] == 'r') \ |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
608 && (a[2] == 'o') \ |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
609 && (a[3] == 'm') \ |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
610 && (a[4] == ' ')) |
| 23 | 611 |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
612 int |
| 120 | 613 mbx_write (line, mbf) |
| 614 char *line; | |
| 615 FILE *mbf; | |
| 23 | 616 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
617 if (IS_FROM_LINE (line)) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
618 { |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
619 if (fputc ('>', mbf) == EOF) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
620 return (NOTOK); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
621 } |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
622 if (fputs (line, mbf) == EOF) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
623 return (NOTOK); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
624 if (fputc (0x0a, mbf) == EOF) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
625 return (NOTOK); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
626 return (OK); |
| 23 | 627 } |
| 628 | |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
629 int |
| 120 | 630 mbx_delimit_begin (mbf) |
| 631 FILE *mbf; | |
| 23 | 632 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
633 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
634 return (NOTOK); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
635 return (OK); |
| 23 | 636 } |
| 637 | |
| 120 | 638 mbx_delimit_end (mbf) |
| 639 FILE *mbf; | |
| 23 | 640 { |
|
9157
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
641 if (putc ('\037', mbf) == EOF) |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
642 return (NOTOK); |
|
29f4cce05fa5
Improve POP code, move most of it into a separate file.
Richard M. Stallman <rms@gnu.org>
parents:
8449
diff
changeset
|
643 return (OK); |
| 23 | 644 } |
| 645 | |
| 646 #endif /* MAIL_USE_POP */ | |
|
5532
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
647 |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
648 #ifndef HAVE_STRERROR |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
649 char * |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
650 strerror (errnum) |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
651 int errnum; |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
652 { |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
653 extern char *sys_errlist[]; |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
654 extern int sys_nerr; |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
655 |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
656 if (errnum >= 0 && errnum < sys_nerr) |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
657 return sys_errlist[errnum]; |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
658 return (char *) "Unknown error"; |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
659 } |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
660 |
|
9c86c71e879d
[! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents:
5524
diff
changeset
|
661 #endif /* ! HAVE_STRERROR */ |
