annotate lib-src/movemail.c @ 54:05472e90ae02 r19-16-pre2

Import from CVS: tag r19-16-pre2
author cvs
date Mon, 13 Aug 2007 08:57:55 +0200
parents 56c54cf7c5b6
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* movemail foo bar -- move file foo to file bar,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 locking file foo the way /bin/mail respects.
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
3 Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 cause loss of mail* if you do it on a system that does not normally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 use flock as its way of interlocking access to inbox files. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 system's own conventions. It is not a choice that is up to you.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 So, if your system uses lock files rather than flock, then the only way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 you can get proper operation is to enable movemail to write lockfiles there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 This means you must either give that directory access modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 that permit everyone to write lockfiles in it, or you must make movemail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 a setuid or setgid program. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 *
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
37 * Added POP (Post Office Protocol) service. When compiled -DMAIL_USE_POP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 * movemail will accept input filename arguments of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 * "po:username". This will cause movemail to open a connection to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 * a pop server running on $MAILHOST (environment variable). Movemail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 * must be setuid to root in order to work with POP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * New module: popmail.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 * Modified routines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * after POP code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * New routines in movemail.c:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * get_errmsg - return pointer to system error message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 *
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
50 * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
51 *
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
52 * Move all of the POP code into a separate file, "pop.c".
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
53 * Use strerror instead of get_errmsg.
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
54 *
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #define NO_SHORTNAMES /* Tell config not to load remap.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include <../src/config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #include <sys/file.h>
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
62 #include <stdio.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include <errno.h>
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
64 #include "../src/syswait.h"
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
65 #include "../src/systime.h"
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
66 #include <stdlib.h>
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
67 #include <string.h>
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
68 #ifdef MAIL_USE_POP
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
69 #include "pop.h"
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
70 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
72 #ifndef HAVE_STRERROR
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
73 static char * strerror (int errnum);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
74 #endif /* HAVE_STRERROR */
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
75
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 #undef access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
80 #ifndef DIRECTORY_SEP
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
81 #define DIRECTORY_SEP '/'
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
82 #endif
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
83 #ifndef IS_DIRECTORY_SEP
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
84 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
85 #endif
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
86
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
87 #ifdef WINDOWSNT
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
88 #undef access
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
89 #undef unlink
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
90 #define fork() 0
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
91 #define sys_wait(var) (*(var) = 0)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
92 /* Unfortunately, Samba doesn't seem to properly lock Unix files even
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
93 though the locking call succeeds (and indeed blocks local access from
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
94 other NT programs). If you have direct file access using an NFS
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
95 client or something other than Samba, the locking call might work
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
96 properly - make sure it does before you enable this! */
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
97 #define DISABLE_DIRECT_ACCESS
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
98 #endif /* WINDOWSNT */
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
99
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
100 #if defined (HAVE_UNISTD_H) || defined (USG)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #include <unistd.h>
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
102 #endif /* unistd.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #ifndef F_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #define F_OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #define X_OK 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #define W_OK 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #define R_OK 4
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
108 #endif /* No F_OK */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
110 #if defined (HAVE_FCNTL_H) || defined (USG)
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
111 #include <fcntl.h>
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
112 #endif /* fcntl.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
114 #if defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 #include <sys/locking.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #ifdef MAIL_USE_FLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 extern int lk_open (), lk_close ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 /* Cancel substitutions made by config.h for Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 #undef open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #undef read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #undef write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #undef close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
136 static void fatal (char *, char*);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
137 static void error (char *, char *, char *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
138 static void pfatal_with_name (char *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
139 static void pfatal_and_delete (char *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
140 static char *concat (char *, char *, char *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
141 static long *xmalloc (unsigned int);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
142 static int popmail (char *, char *, char *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
143 #ifdef MAIL_USE_POP
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
144 static int pop_retr (popserver server, int msgno, int (*action)(), int arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 #endif
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
146 static int mbx_write (char *, FILE *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
147 static int mbx_delimit_begin (FILE *);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
148 static int mbx_delimit_end (FILE *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* Nonzero means this is name of a lock file to delete on fatal error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 char *delete_lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
153 int
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
154 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 char *inname, *outname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 int indesc, outdesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 int nread;
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
159 int status;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 long now;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 char *lockname, *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 char *tempname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 int desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 delete_lockname = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 if (argc < 3)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
173 {
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
174 fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n");
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
175 exit(1);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
176 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 inname = argv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 outname = argv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 mmdf_init (argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
185 if (*outname == 0)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
186 fatal ("Destination file name is empty", 0);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
187
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 /* Check access to output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
192 /* Also check that outname's directory is writable to the real uid. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 char *buf = (char *) xmalloc (strlen (outname) + 1);
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
195 char *cp;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 strcpy (buf, outname);
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
197 cp = buf + strlen (buf);
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
198 while (cp > buf && !IS_DIRECTORY_SEP (cp[-1]))
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
199 *--cp = 0;
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
200 if (cp == buf)
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
201 *cp++ = '.';
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (access (buf, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 pfatal_with_name (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 free (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 #ifdef MAIL_USE_POP
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
208 if (!strncmp (inname, "po:", 3))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
210 int status;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
212 status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 exit (status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
219 #ifndef DISABLE_DIRECT_ACCESS
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
220
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 /* Check access to input file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (access (inname, R_OK | W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #ifndef MAIL_USE_SYSTEM_LOCK
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
227 /* Use a lock file named after our first argument with .lock appended:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 If it exists, the mail file is locked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 /* Note: this locking mechanism is *required* by the mailer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (on systems which use it) to prevent loss of mail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 On systems that use a lock file, extracting the mail without locking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 WILL occasionally cause loss of mail due to timing errors!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 So, if creation of the lock file fails
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
236 due to access permission on the mail spool directory,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 you simply MUST change the permission
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 and/or make movemail a setgid program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 so it can create lock files properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 You might also wish to verify that your system is one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 which uses lock files for this purpose. Some systems use other methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 If your system uses the `flock' system call for mail locking,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 and recompile movemail. If the s- file for your system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 lockname = concat (inname, ".lock", "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 strcpy (tempname, inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 p = tempname + strlen (tempname);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
254 while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 p--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 *p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 strcpy (p, "EXXXXXX");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 mktemp (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 /* Create the lock file, but not under the lock file name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 /* Give up if cannot do that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 if (desc < 0)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
267 {
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
268 char *message = (char *) xmalloc (strlen (tempname) + 50);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
269 sprintf (message, "%s--see source file lib-src/movemail.c",
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
270 tempname);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
271 pfatal_with_name (message);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
272 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 close (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 tem = link (tempname, lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 if (tem >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
281 /* If lock file is five minutes old, unlock it.
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
282 Five minutes should be good enough to cope with crashes
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
283 and wedgitude, and long enough to avoid being fooled
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
284 by time differences between machines. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 if (stat (lockname, &st) >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 now = time (0);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
288 if (st.st_ctime < now - 300)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
289 unlink (lockname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 delete_lockname = lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 #endif /* not MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 if (fork () == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 indesc = open (inname, O_RDWR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 #else /* if not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 indesc = open (inname, O_RDONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 #else /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 #endif /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 if (indesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 #if defined (BSD) || defined (XENIX)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 /* In case movemail is setuid to root, make sure the user can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 read the output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 /* This is desirable for all systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 but I don't want to assume all have the umask system call */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 umask (umask (0) & 0333);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 #endif /* BSD or Xenix */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 if (outdesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 if (lockf (indesc, F_LOCK, 0) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 #else /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 #ifdef XENIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 #else
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
331 #ifdef WINDOWSNT
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
332 if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
333 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 #endif
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
336 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 #endif /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 char buf[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 nread = read (indesc, buf, sizeof buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 if (nread != write (outdesc, buf, nread))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 int saved_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 unlink (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 errno = saved_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 if (nread < sizeof buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 if (fsync (outdesc) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 /* Check to make sure no errors before we zap the inbox. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 if (close (outdesc) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 #ifdef MAIL_USE_SYSTEM_LOCK
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
368 #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ftruncate (indesc, 0L);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 #endif /* STRIDE or XENIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 lk_close (indesc, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 close (indesc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* Delete the input file; if we can't, at least get rid of its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 #ifdef MAIL_UNLINK_SPOOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 /* This is generally bad to do, because it destroys the permissions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 that were set on the file. Better to just empty the file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 if (unlink (inname) < 0 && errno != ENOENT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 #endif /* MAIL_UNLINK_SPOOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 creat (inname, 0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 wait (&status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 if (!WIFEXITED (status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 exit (1);
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
399 else if (WEXITSTATUS (status) != 0)
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
400 exit (WEXITSTATUS (status));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 unlink (lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
405
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
406 #endif /* ! DISABLE_DIRECT_ACCESS */
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
407
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
408 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
413 static void
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
414 fatal (char *s1, char *s2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 if (delete_lockname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 unlink (delete_lockname);
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
418 error (s1, s2, NULL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
424 static void
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
425 error (char *s1, char *s2, char *s3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
427 fprintf (stderr, "movemail: ");
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
428 fprintf (stderr, s1, s2, s3);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
429 fprintf (stderr, "\n");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
432 static void
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
433 pfatal_with_name (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
435 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
439 static void
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
440 pfatal_and_delete (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
442 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 unlink (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
449 static char *
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
450 concat (char *s1, char *s2, char *s3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 strcpy (result, s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 strcpy (result + len1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 strcpy (result + len1 + len2, s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 *(result + len1 + len2 + len3) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
465 static long *
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
466 xmalloc (unsigned int size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
468 long *result = (long *) malloc (size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 if (!result)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
470 fatal ("virtual memory exhausted", 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 /* This is the guts of the interface to the Post Office Protocol. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 #ifdef MAIL_USE_POP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
478 #ifndef WINDOWSNT
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 #include <netinet/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #include <netdb.h>
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
482 #else
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
483 #undef _WINSOCKAPI_
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
484 #include <winsock.h>
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
485 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #include <pwd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 #define NOTOK (-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 #define OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 #define DONE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 FILE *sfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 FILE *sfo;
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
496 char ibuffer[BUFSIZ];
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
497 char obuffer[BUFSIZ];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 char Errmsg[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
500 static int
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
501 popmail (char *user, char *outfile, char *password)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 int nmsgs, nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 register int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 int mbfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 FILE *mbf;
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
507 char *getenv ();
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
508 int mbx_write ();
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
509 popserver server;
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
510 extern char *strerror ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
512 server = pop_open (0, user, password, POP_NO_GETPASS);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
513 if (! server)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
515 error (pop_error, NULL, NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
516 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
519 if (pop_stat (server, &nmsgs, &nbytes))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
521 error (pop_error, NULL, NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
522 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 if (!nmsgs)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
526 {
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
527 pop_close (server);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
528 return (0);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
529 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 if (mbfi < 0)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
533 {
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
534 pop_close (server);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
535 error ("Error in open: %s, %s", strerror (errno), outfile);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
536 return (1);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
537 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 fchown (mbfi, getuid (), -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
540 if ((mbf = fdopen (mbfi, "wb")) == NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
542 pop_close (server);
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
543 error ("Error in fdopen: %s", strerror (errno), NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
544 close (mbfi);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
545 unlink (outfile);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
546 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
549 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 mbx_delimit_begin (mbf);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
552 if (pop_retr (server, i, mbx_write, mbf) != OK)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
553 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
554 error (Errmsg, NULL, NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
555 close (mbfi);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
556 return (1);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
557 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 mbx_delimit_end (mbf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 fflush (mbf);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
560 if (ferror (mbf))
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
561 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
562 error ("Error in fflush: %s", strerror (errno), NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
563 pop_close (server);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
564 close (mbfi);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
565 return (1);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
566 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
569 /* On AFS, a call to write only modifies the file in the local
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
570 * workstation's AFS cache. The changes are not written to the server
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
571 * until a call to fsync or close is made. Users with AFS home
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
572 * directories have lost mail when over quota because these checks were
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
573 * not made in previous versions of movemail. */
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
574
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
575 #ifdef BSD
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 if (fsync (mbfi) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
578 error ("Error in fsync: %s", strerror (errno), NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
579 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
581 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 if (close (mbfi) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
585 error ("Error in close: %s", strerror (errno), NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
586 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
589 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
591 if (pop_delete (server, i))
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
592 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
593 error (pop_error, NULL, NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
594 pop_close (server);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
595 return (1);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
596 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
599 if (pop_quit (server))
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
600 {
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
601 error (pop_error, NULL, NULL);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
602 return (1);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
603 }
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
604
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
608 static int
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
609 pop_retr (popserver server, int msgno, int (*action)(), int arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
611 char *line;
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
612 int ret;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
614 if (pop_retrieve_first (server, msgno, &line))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
616 strncpy (Errmsg, pop_error, sizeof (Errmsg));
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
617 Errmsg[sizeof (Errmsg)-1] = '\0';
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
618 return (NOTOK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
621 while (! (ret = pop_retrieve_next (server, &line)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
623 if (! line)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
624 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
626 if ((*action)(line, arg) != OK)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
627 {
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
628 strcpy (Errmsg, strerror (errno));
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
629 pop_close (server);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
630 return (NOTOK);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
631 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
634 if (ret)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
636 strncpy (Errmsg, pop_error, sizeof (Errmsg));
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
637 Errmsg[sizeof (Errmsg)-1] = '\0';
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
638 return (NOTOK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
640
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
641 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
644 /* Do this as a macro instead of using strcmp to save on execution time. */
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
645 #define IS_FROM_LINE(a) ((a[0] == 'F') \
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
646 && (a[1] == 'r') \
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
647 && (a[2] == 'o') \
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
648 && (a[3] == 'm') \
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
649 && (a[4] == ' '))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
651 static int
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
652 mbx_write (char *line, FILE *mbf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
654 if (IS_FROM_LINE (line))
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
655 {
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
656 if (fputc ('>', mbf) == EOF)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
657 return (NOTOK);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
658 }
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
659 if (fputs (line, mbf) == EOF)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
660 return (NOTOK);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
661 if (fputc (0x0a, mbf) == EOF)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
662 return (NOTOK);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
663 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
666 static int
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
667 mbx_delimit_begin (FILE *mbf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
669 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
670 return (NOTOK);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
671 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
674 static int
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
675 mbx_delimit_end (FILE *mbf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 {
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
677 if (putc ('\037', mbf) == EOF)
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
678 return (NOTOK);
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
679 return (OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 #ifndef HAVE_STRERROR
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
685 static char *
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
686 strerror (int errnum)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 return (char *) "Unknown error";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 #endif /* ! HAVE_STRERROR */