annotate lib-src/movemail.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents d883f39b8495
children bbff43aa5eb7
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.
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
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
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
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 *
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
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 *
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
50 * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
51 *
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
52 * Move all of the POP code into a separate file, "pop.c".
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
53 * Use strerror instead of get_errmsg.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
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>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
62 #include <stdio.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include <errno.h>
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
64 #include "../src/syswait.h"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
65 #include "../src/systime.h"
122
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
66 #include <stdlib.h>
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
67 #include <string.h>
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
68 #include "getopt.h"
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
69 #ifdef MAIL_USE_POP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
70 #include "pop.h"
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
71 #include "../src/regex.h"
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
72 #endif
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
73
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
74 extern char *optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
75 extern int optind, opterr;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
76
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
77 #ifndef HAVE_STRERROR
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 331
diff changeset
78 static char * strerror (int errnum);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
79 #endif /* HAVE_STRERROR */
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
80
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #undef access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
85 #ifndef DIRECTORY_SEP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
86 #define DIRECTORY_SEP '/'
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
87 #endif
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
88 #ifndef IS_DIRECTORY_SEP
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
89 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
90 #endif
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
91
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
92 #ifdef WINDOWSNT
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
93 #undef access
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
94 #undef unlink
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
95 #define fork() 0
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
96 #define sys_wait(var) (*(var) = 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
97 /* Unfortunately, Samba doesn't seem to properly lock Unix files even
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
98 though the locking call succeeds (and indeed blocks local access from
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
99 other NT programs). If you have direct file access using an NFS
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
100 client or something other than Samba, the locking call might work
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
101 properly - make sure it does before you enable this! */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
102 #define DISABLE_DIRECT_ACCESS
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 272
diff changeset
103 #include <io.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
104 #endif /* WINDOWSNT */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
105
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
106 #if defined (HAVE_UNISTD_H) || defined (USG)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #include <unistd.h>
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
108 #endif /* unistd.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #ifndef F_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #define F_OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #define X_OK 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #define W_OK 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #define R_OK 4
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
114 #endif /* No F_OK */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
116 #if defined (HAVE_FCNTL_H) || defined (USG)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
117 #include <fcntl.h>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
118 #endif /* fcntl.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
120 #if defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #include <sys/locking.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 #ifdef MAIL_USE_FLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 extern int lk_open (), lk_close ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 /* Cancel substitutions made by config.h for Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 #undef open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 #undef read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #undef write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 #undef close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
142 static void fatal (char *, char*);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
143 static void error (char *, char *, char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
144 static void pfatal_with_name (char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
145 static void pfatal_and_delete (char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
146 static char *concat (char *, char *, char *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
147 static long *xmalloc (unsigned int);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
148 #ifdef MAIL_USE_POP
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
149 static int popmail (char *, char *, char *);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
150 static int pop_retr (popserver server, int msgno, int (*action)(), void *arg);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
151 static int mbx_write (char *, FILE *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
152 static int mbx_delimit_begin (FILE *);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
153 static int mbx_delimit_end (FILE *);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
154 static struct re_pattern_buffer* compile_regex (char* regexp_pattern);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
155 static int pop_search_top (popserver server, int msgno, int lines,
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
156 struct re_pattern_buffer* regexp);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
157 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* 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
160 char *delete_lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
162 int verbose=0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
163 #ifdef MAIL_USE_POP
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
164 int reverse=0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
165 int keep_messages=0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
166 struct re_pattern_buffer* regexp_pattern=0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
167 int match_lines=10;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
168 #endif
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
169
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
170 #define VERBOSE(x) if (verbose) { printf x; fflush(stdout); }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
171
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
172 struct option longopts[] =
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
173 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
174 { "inbox", required_argument, NULL, 'i' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
175 { "outfile", required_argument, NULL, 'o' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
176 #ifdef MAIL_USE_POP
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
177 { "password", required_argument, NULL, 'p' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
178 { "reverse-pop-order", no_argument, NULL, 'x' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
179 { "keep-messages", no_argument, NULL, 'k' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
180 { "regex", required_argument, NULL, 'r' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
181 { "match-lines", required_argument, NULL, 'l' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
182 #endif
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
183 { "verbose", no_argument, NULL, 'v' },
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
184 { 0 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
185 };
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
186
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
187 int
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
188 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
190 char *inname=0, *outname=0, *poppass=0;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 272
diff changeset
191 #ifndef DISABLE_DIRECT_ACCESS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 int indesc, outdesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 int nread;
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
194 int status;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 272
diff changeset
195 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 long now;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 char *lockname, *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 char *tempname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 int desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 delete_lockname = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
208 while (1)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
209 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
210 #ifdef MAIL_USE_POP
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
211 char* optstring = "i:o:p:l:r:xvk";
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
212 #else
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
213 char* optstring = "i:o:v";
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
214 #endif
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
215 int opt = getopt_long (argc, argv, optstring, longopts, 0);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
216
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
217 if (opt == EOF)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
218 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
219
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
220 switch (opt)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
221 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
222 case 0:
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
223 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
224 case 1: /* one of the standard arguments seen */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
225 if (!inname)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
226 inname = optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
227 else if (!outname)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
228 outname = optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
229 else
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
230 poppass = optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
231 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
232
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
233 case 'i': /* infile */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
234 inname = optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
235 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
236
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
237 case 'o': /* outfile */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
238 outname = optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
239 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
240 #ifdef MAIL_USE_POP
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
241 case 'p': /* pop password */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
242 poppass = optarg;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
243 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
244 case 'k': keep_messages=1; break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
245 case 'x': reverse = 1; break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
246 case 'l': /* lines to match */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
247 match_lines = atoi (optarg);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
248 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
249
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
250 case 'r': /* regular expression */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
251 regexp_pattern = compile_regex (optarg);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
252 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
253 #endif
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
254 case 'v': verbose = 1; break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
255 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
256 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
257
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
258 while (optind < argc)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
259 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
260 if (!inname)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
261 inname = argv[optind];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
262 else if (!outname)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
263 outname = argv[optind];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
264 else
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
265 poppass = argv[optind];
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
266 optind++;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
267 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
268
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
269 if (!inname || !outname)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
270 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
271 fprintf (stderr, "Usage: movemail [-rvxk] [-l lines ] [-i] inbox [-o] destfile [[-p] POP-password]\n");
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 331
diff changeset
272 exit(1);
321
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 288
diff changeset
273 }
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 288
diff changeset
274
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 mmdf_init (argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
279 if (*outname == 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
280 fatal ("Destination file name is empty", 0);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
281
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 /* Check access to output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
286 /* Also check that outname's directory is writable to the real uid. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 char *buf = (char *) xmalloc (strlen (outname) + 1);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
289 char *cp;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 strcpy (buf, outname);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
291 cp = buf + strlen (buf);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
292 while (cp > buf && !IS_DIRECTORY_SEP (cp[-1]))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
293 *--cp = 0;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
294 if (cp == buf)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
295 *cp++ = '.';
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (access (buf, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 pfatal_with_name (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 free (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 #ifdef MAIL_USE_POP
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
302 if (!strncmp (inname, "po:", 3))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
304 int retcode = popmail (inname + 3, outname, poppass);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
305 exit (retcode);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
311 #ifndef DISABLE_DIRECT_ACCESS
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
312
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 /* Check access to input file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 if (access (inname, R_OK | W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 #ifndef MAIL_USE_SYSTEM_LOCK
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
319 /* Use a lock file named after our first argument with .lock appended:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 If it exists, the mail file is locked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 /* Note: this locking mechanism is *required* by the mailer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (on systems which use it) to prevent loss of mail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 On systems that use a lock file, extracting the mail without locking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 WILL occasionally cause loss of mail due to timing errors!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 So, if creation of the lock file fails
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
328 due to access permission on the mail spool directory,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 you simply MUST change the permission
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 and/or make movemail a setgid program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 so it can create lock files properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 You might also wish to verify that your system is one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 which uses lock files for this purpose. Some systems use other methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 If your system uses the `flock' system call for mail locking,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 and recompile movemail. If the s- file for your system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 lockname = concat (inname, ".lock", "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 strcpy (tempname, inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 p = tempname + strlen (tempname);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
346 while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 p--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 *p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 strcpy (p, "EXXXXXX");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 mktemp (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 /* Create the lock file, but not under the lock file name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 /* Give up if cannot do that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 if (desc < 0)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
359 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
360 char *message = (char *) xmalloc (strlen (tempname) + 50);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
361 sprintf (message, "%s--see source file lib-src/movemail.c",
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
362 tempname);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
363 pfatal_with_name (message);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
364 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 close (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 tem = link (tempname, lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 if (tem >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
373 /* If lock file is five minutes old, unlock it.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
374 Five minutes should be good enough to cope with crashes
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
375 and wedgitude, and long enough to avoid being fooled
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
376 by time differences between machines. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 if (stat (lockname, &st) >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 now = time (0);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
380 if (st.st_ctime < now - 300)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
381 unlink (lockname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 delete_lockname = lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 #endif /* not MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 if (fork () == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 indesc = open (inname, O_RDWR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 #else /* if not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 indesc = open (inname, O_RDONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 #else /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 #endif /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 if (indesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 #if defined (BSD) || defined (XENIX)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 /* In case movemail is setuid to root, make sure the user can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 read the output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 /* This is desirable for all systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 but I don't want to assume all have the umask system call */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 umask (umask (0) & 0333);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 #endif /* BSD or Xenix */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 if (outdesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 if (lockf (indesc, F_LOCK, 0) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 #else /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 #ifdef XENIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 #else
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
423 #ifdef WINDOWSNT
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
424 if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
425 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 #endif
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
428 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 #endif /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 char buf[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 nread = read (indesc, buf, sizeof buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 if (nread != write (outdesc, buf, nread))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 int saved_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 unlink (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 errno = saved_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 if (nread < sizeof buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 if (fsync (outdesc) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 /* Check to make sure no errors before we zap the inbox. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 if (close (outdesc) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 #ifdef MAIL_USE_SYSTEM_LOCK
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
460 #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ftruncate (indesc, 0L);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 #endif /* STRIDE or XENIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 lk_close (indesc, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 close (indesc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 /* 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
476 contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 #ifdef MAIL_UNLINK_SPOOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 /* This is generally bad to do, because it destroys the permissions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 that were set on the file. Better to just empty the file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 if (unlink (inname) < 0 && errno != ENOENT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #endif /* MAIL_UNLINK_SPOOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 creat (inname, 0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 wait (&status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 if (!WIFEXITED (status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 exit (1);
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
491 else if (WEXITSTATUS (status) != 0)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 149
diff changeset
492 exit (WEXITSTATUS (status));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 unlink (lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
497
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
498 #endif /* ! DISABLE_DIRECT_ACCESS */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
499
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
500 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
505 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
506 fatal (char *s1, char *s2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 if (delete_lockname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 unlink (delete_lockname);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
510 error (s1, s2, NULL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
516 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
517 error (char *s1, char *s2, char *s3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
519 fprintf (stderr, "movemail: ");
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
520 fprintf (stderr, s1, s2, s3);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
521 fprintf (stderr, "\n");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
524 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
525 pfatal_with_name (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
527 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
531 static void
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
532 pfatal_and_delete (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
534 char *s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 unlink (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
541 static char *
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
542 concat (char *s1, char *s2, char *s3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 strcpy (result, s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 strcpy (result + len1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 strcpy (result + len1 + len2, s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 *(result + len1 + len2 + len3) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
557 static long *
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
558 xmalloc (unsigned int size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
560 long *result = (long *) malloc (size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 if (!result)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
562 fatal ("virtual memory exhausted", 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 /* This is the guts of the interface to the Post Office Protocol. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 #ifdef MAIL_USE_POP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
570 #ifndef WINDOWSNT
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 #include <netinet/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 #include <netdb.h>
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
574 #else
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
575 #undef _WINSOCKAPI_
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
576 #include <winsock.h>
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
577 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 #include <pwd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
581 #define POP_ERROR (-1)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
582 #define POP_RETRIEVED (0)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
583 #define POP_DONE (1)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 FILE *sfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 FILE *sfo;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
588 char ibuffer[BUFSIZ];
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
589 char obuffer[BUFSIZ];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 char Errmsg[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
592 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
593 popmail (char *user, char *outfile, char *password)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 int nmsgs, nbytes;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
596 register int i, idx;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 int mbfi;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
598 short* retrieved_list;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 FILE *mbf;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
600 popserver server;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
602 VERBOSE(("opening server\r"));
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
603 server = pop_open (0, user, password, POP_NO_GETPASS);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
604 if (! server)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
606 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
607 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
610 VERBOSE(("stat'ing messages\r"));
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
611 if (pop_stat (server, &nmsgs, &nbytes))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
613 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
614 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 if (!nmsgs)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
618 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
619 VERBOSE(("closing server\n"));
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
620 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
621 return (0);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
622 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
624 /* build a retrieved table */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
625 retrieved_list = (short*) xmalloc (sizeof (short) * (nmsgs+1));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
626 memset (retrieved_list, 0, sizeof (short) * (nmsgs+1));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
627
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 if (mbfi < 0)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
630 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
631 pop_close (server);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
632 error ("Error in open: %s, %s", strerror (errno), outfile);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
633 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
634 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 213
diff changeset
635 #ifndef __CYGWIN32__
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 fchown (mbfi, getuid (), -1);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 213
diff changeset
637 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
639 if ((mbf = fdopen (mbfi, "wb")) == NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
641 pop_close (server);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
642 error ("Error in fdopen: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
643 close (mbfi);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
644 unlink (outfile);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
645 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
648 for (idx = 0; idx < nmsgs; idx++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
650 i = reverse ? nmsgs - idx : idx + 1;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
651 VERBOSE(("checking message %d \r", i));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
652
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
653 if (!regexp_pattern
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
654 ||
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
655 pop_search_top (server, i, match_lines, regexp_pattern) == POP_RETRIEVED)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
656 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
657 VERBOSE(("retrieving message %d \r", i));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
658 mbx_delimit_begin (mbf);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
659 if (pop_retr (server, i, mbx_write, mbf) != POP_RETRIEVED)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
660 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
661 error (Errmsg, NULL, NULL);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
662 close (mbfi);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
663 return (1);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
664 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
665
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
666 retrieved_list[i]=1;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
667
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
668 mbx_delimit_end (mbf);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
669 fflush (mbf);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
670 if (ferror (mbf))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
671 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
672 error ("Error in fflush: %s", strerror (errno), NULL);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
673 pop_close (server);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
674 close (mbfi);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
675 return (1);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
676 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
677 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
680 /* On AFS, a call to write only modifies the file in the local
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
681 * workstation's AFS cache. The changes are not written to the server
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
682 * until a call to fsync or close is made. Users with AFS home
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
683 * directories have lost mail when over quota because these checks were
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
684 * not made in previous versions of movemail. */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
685
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
686 #ifdef BSD
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 if (fsync (mbfi) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
689 error ("Error in fsync: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
690 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
692 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 if (close (mbfi) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
696 error ("Error in close: %s", strerror (errno), NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
697 return (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
700 if (!keep_messages)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
702 for (i = 1; i <= nmsgs; i++)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
703 {
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
704 if (retrieved_list[i] == 1)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
705 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
706 VERBOSE(("deleting message %d \r", i));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
707 if (pop_delete (server, i))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
708 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
709 error (pop_error, NULL, NULL);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
710 pop_close (server);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
711 return (1);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
712 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
713 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
714 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
717 VERBOSE(("closing server \n"));
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
718 if (pop_quit (server))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
719 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
720 error (pop_error, NULL, NULL);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
721 return (1);
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
722 }
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
723
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
727 static int
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 175
diff changeset
728 pop_retr (popserver server, int msgno, int (*action)(), void *arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
730 char *line;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
731 int ret;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
732
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
733 if (pop_retrieve_first (server, msgno, &line))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
734 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
735 strncpy (Errmsg, pop_error, sizeof (Errmsg));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
736 Errmsg[sizeof (Errmsg)-1] = '\0';
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
737 return (POP_ERROR);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
739
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
740 while (! (ret = pop_retrieve_next (server, &line)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
741 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
742 if (! line)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
743 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
745 if ((*action)(line, arg) != POP_RETRIEVED)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
746 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
747 strcpy (Errmsg, strerror (errno));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
748 pop_close (server);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
749 return (POP_ERROR);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
750 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
751 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
752
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
753 if (ret)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
754 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
755 strncpy (Errmsg, pop_error, sizeof (Errmsg));
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
756 Errmsg[sizeof (Errmsg)-1] = '\0';
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
757 return (POP_ERROR);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
758 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
759
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
760 return (POP_RETRIEVED);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
761 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
762
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
763 /* search the top lines of each message looking for a match */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
764 static int
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
765 pop_search_top (popserver server, int msgno, int lines, struct re_pattern_buffer* regexp)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
766 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
767 char *line;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
768 int ret;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
769 int match = POP_DONE;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
770
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
771 if (pop_top_first (server, msgno, lines, &line))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
772 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
773 strncpy (Errmsg, pop_error, sizeof (Errmsg));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
774 Errmsg[sizeof (Errmsg)-1] = '\0';
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
775 return (POP_ERROR);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
776 }
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
777
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
778 while (! (ret = pop_top_next (server, &line)))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
779 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
780 if (! line)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
781 break;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
782
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
783 /* VERBOSE (("checking %s\n", line));*/
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
784 if (match != POP_RETRIEVED)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
785 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
786 if ((ret = re_match (regexp, line, strlen (line), 0, 0)) == -2 )
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
787 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
788 strcpy (Errmsg, "error in regular expression");
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
789 pop_close (server);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
790 return (POP_ERROR);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
791 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
792 else if (ret >=0)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
793 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
794 match = POP_RETRIEVED;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
795 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
796 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
797 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
798
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
799 if (ret)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
800 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
801 strncpy (Errmsg, pop_error, sizeof (Errmsg));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
802 Errmsg[sizeof (Errmsg)-1] = '\0';
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
803 return (POP_ERROR);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
804 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
805
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
806 return match;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
809 /* Do this as a macro instead of using strcmp to save on execution time. */
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
810 #define IS_FROM_LINE(a) ((a[0] == 'F') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
811 && (a[1] == 'r') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
812 && (a[2] == 'o') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
813 && (a[3] == 'm') \
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
814 && (a[4] == ' '))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
816 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
817 mbx_write (char *line, FILE *mbf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
818 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
819 if (IS_FROM_LINE (line))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
820 {
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
821 if (fputc ('>', mbf) == EOF)
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
822 return (POP_ERROR);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
823 }
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
824 if (fputs (line, mbf) == EOF)
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
825 return (POP_ERROR);
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
826 if (fputc (0x0a, mbf) == EOF)
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
827 return (POP_ERROR);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
828 return (POP_RETRIEVED);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
829 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
830
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
831 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
832 mbx_delimit_begin (FILE *mbf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
833 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
834 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
835 return (POP_ERROR);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
836 return (POP_RETRIEVED);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
837 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
838
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
839 static int
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
840 mbx_delimit_end (FILE *mbf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
841 {
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 70
diff changeset
842 if (putc ('\037', mbf) == EOF)
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
843 return (POP_ERROR);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
844 return (POP_RETRIEVED);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
847 /* Turn a name, which is an ed-style (but Emacs syntax) regular
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
848 expression, into a real regular expression by compiling it. */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
849 static struct re_pattern_buffer*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
850 compile_regex (char* pattern)
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
851 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
852 char *err;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
853 struct re_pattern_buffer *patbuf=0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
854
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
855 patbuf = (struct re_pattern_buffer*) xmalloc (sizeof (struct re_pattern_buffer));
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
856 patbuf->translate = NULL;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
857 patbuf->fastmap = NULL;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
858 patbuf->buffer = NULL;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
859 patbuf->allocated = 0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
860
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
861 err = (char*) re_compile_pattern (pattern, strlen (pattern), patbuf);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
862 if (err != NULL)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
863 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
864 error ("%s while compiling pattern", err, NULL);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
865 return 0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
866 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
867
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
868 return patbuf;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
869 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
870
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
871
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
872
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 #ifndef HAVE_STRERROR
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 331
diff changeset
876 static char *
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
877 strerror (int errnum)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 return (char *) "Unknown error";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 #endif /* ! HAVE_STRERROR */