annotate lib-src/movemail.c @ 384:bbff43aa5eb7 r21-2-7

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