annotate lib-src/movemail.c @ 450:98528da0b7fc r21-2-40

Import from CVS: tag r21-2-40
author cvs
date Mon, 13 Aug 2007 11:39:20 +0200
parents abe6d1db359e
children 4a2749e56f92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* movemail foo bar -- move file foo to file bar,
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
2 locking file foo.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
5 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
8 under the terms of the GNU General Public License as published by the
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
10 later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
15 for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
20 Boston, MA 02111-1307, USA.
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
21
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
22 Please mail bugs and suggestions to the XEmacs maintainer.
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
23 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
25 /* Important notice:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
26 *
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
27 * You *must* coordinate the locking method used by movemail with that
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
28 * used by your mail delivery agent, as well as that of the other mail
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
29 * user agents on your system. movemail allows you to do this at run
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
30 * time via the -m flag. Moreover, it uses a default determined by
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
31 * the MAIL_LOCK_DOT, MAIL_LOCK_LOCKF, MAIL_LOCK_FLOCK,
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
32 * MAIL_LOCK_LOCKING, and MAIL_LOCK_MMDF preprocessor settings.
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
33 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
35 /*
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
36 * Mike Sperber <sperber@informatik.uni-tuebingen.de> reorganized
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
37 * everything that has to with locking in December 1999.
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
38 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 * Added POP (Post Office Protocol) service. When compiled -DMAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 * movemail will accept input filename arguments of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 * "po:username". This will cause movemail to open a connection to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * a pop server running on $MAILHOST (environment variable). Movemail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 * must be setuid to root in order to work with POP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * New module: popmail.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 * Modified routines:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 * after POP code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 * New routines in movemail.c:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 * get_errmsg - return pointer to system error message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 * Move all of the POP code into a separate file, "pop.c".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 * Use strerror instead of get_errmsg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #define NO_SHORTNAMES /* Tell config not to load remap.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #define DONT_ENCAPSULATE
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
65 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <sys/stat.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #include "../src/sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #include "../src/syswait.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
72 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #include "../src/systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #include "getopt.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #include "pop.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #include "../src/regex.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 extern char *optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 extern int optind, opterr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #ifndef HAVE_STRERROR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 char * strerror (int errnum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #endif /* HAVE_STRERROR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #ifndef DIRECTORY_SEP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #define DIRECTORY_SEP '/'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #ifndef IS_DIRECTORY_SEP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
97 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #undef access
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 #undef unlink
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #define fork() 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 #define sys_wait(var) (*(var) = 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* Unfortunately, Samba doesn't seem to properly lock Unix files even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 though the locking call succeeds (and indeed blocks local access from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 other NT programs). If you have direct file access using an NFS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 client or something other than Samba, the locking call might work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 properly - make sure it does before you enable this! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #define DISABLE_DIRECT_ACCESS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #include <io.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
109 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
111 #if defined (HAVE_UNISTD_H)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #endif /* unistd.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 #ifndef F_OK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #define F_OK 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #define X_OK 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #define W_OK 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #define R_OK 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 #endif /* No F_OK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
121 #if defined (HAVE_FCNTL_H)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #include <fcntl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #endif /* fcntl.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
125 #ifdef HAVE_LOCKING
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #include <sys/locking.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
129 #ifdef HAVE_MMDF
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 extern int lk_open (), lk_close ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 /* Cancel substitutions made by config.h for Emacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #undef open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 #undef read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #undef write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 #undef close
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 static void fatal (char *, char*);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 static void error (char *, char *, char *);
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
141 static void usage(int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 static void pfatal_with_name (char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 static void pfatal_and_delete (char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 static char *concat (char *, char *, char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 static long *xmalloc (unsigned int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 static int popmail (char *, char *, char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 static int pop_retr (popserver server, int msgno,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
149 int (*action)(char *, FILE *), FILE *arg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 static int mbx_write (char *, FILE *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 static int mbx_delimit_begin (FILE *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 static int mbx_delimit_end (FILE *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 static struct re_pattern_buffer* compile_regex (char* regexp_pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 static int pop_search_top (popserver server, int msgno, int lines,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 struct re_pattern_buffer* regexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 int verbose=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 int reverse=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 int keep_messages=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 struct re_pattern_buffer* regexp_pattern=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 int match_lines=10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 #define VERBOSE(x) if (verbose) { printf x; fflush(stdout); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 struct option longopts[] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 { "inbox", required_argument, NULL, 'i' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 { "outfile", required_argument, NULL, 'o' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 { "password", required_argument, NULL, 'p' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 { "reverse-pop-order", no_argument, NULL, 'x' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 { "keep-messages", no_argument, NULL, 'k' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 { "regex", required_argument, NULL, 'r' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 { "match-lines", required_argument, NULL, 'l' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 #endif
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
179 { "lock-method", required_argument, NULL, 'm' },
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
180 { "help", no_argument, NULL, 'h' },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 { "verbose", no_argument, NULL, 'v' },
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 { 0 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
185 #define DOTLOCKING 0
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
186 #define FLOCKING 1
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
187 #define LOCKFING 2
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
188 #define MMDF 3
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
189 #define LOCKING 4
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
190
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
191 #if defined(MAIL_LOCK_FLOCK) && defined(HAVE_FLOCK)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
192 #define DEFAULT_LOCKING FLOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
193 #elif defined(MAIL_LOCK_LOCKF) && defined(HAVE_LOCKF)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
194 #define DEFAULT_LOCKING LOCKFING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
195 #elif defined(MAIL_LOCK_MMDF) && defined(HAVE_MMDF)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
196 #define DEFAULT_LOCKING MMDF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
197 #elif defined(MAIL_LOCK_LOCKING) && defined(HAVE_LOCKING)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
198 #define DEFAULT_LOCKING LOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
199 #else
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
200 #define DEFAULT_LOCKING DOTLOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
201 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
202
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
203 #ifndef DISABLE_DIRECT_ACCESS
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
204 static void lock_dot(char *);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
205 #endif
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
206 static void unlock_dot(char *);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
207 static int parse_lock_method(char *);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
208 static char *unparse_lock_method(int);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
209
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 char *inname=0, *outname=0, *poppass=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 #ifndef DISABLE_DIRECT_ACCESS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 int indesc, outdesc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 int nread;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 int status;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
220 int lock_method = DEFAULT_LOCKING;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
221
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
222 char *maybe_lock_env;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
224 maybe_lock_env = getenv("EMACSLOCKMETHOD");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
225 if (maybe_lock_env)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
226 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
227 printf("maybe-lock_env: %s\n", maybe_lock_env);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
228 lock_method = parse_lock_method(maybe_lock_env);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
229 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
231 for (;;)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 #ifdef MAIL_USE_POP
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
234 char* optstring = "i:o:m:p:l:r:xvhk";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 #else
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
236 char* optstring = "i:o:m:vh";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 int opt = getopt_long (argc, argv, optstring, longopts, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 if (opt == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 switch (opt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 case 1: /* one of the standard arguments seen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 if (!inname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 inname = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 else if (!outname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 outname = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 poppass = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 case 'i': /* infile */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 inname = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 case 'o': /* outfile */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 outname = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 case 'p': /* pop password */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 poppass = optarg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 case 'k': keep_messages=1; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 case 'x': reverse = 1; break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 case 'l': /* lines to match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 match_lines = atoi (optarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 case 'r': /* regular expression */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 regexp_pattern = compile_regex (optarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 #endif
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
277
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
278 case 'm':
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
279 lock_method = parse_lock_method(optarg);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
280 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
281 case 'h':
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
282 usage(lock_method);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
283 exit(0);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
284 case 'v':
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
285 verbose = 1;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
286 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 while (optind < argc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if (!inname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 inname = argv[optind];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 else if (!outname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 outname = argv[optind];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 poppass = argv[optind];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 optind++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 if (!inname || !outname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
303 usage(lock_method);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
307 #ifdef HAVE_MMDF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
308 if (lock_method == MMDF)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
309 mmdf_init (argv[0]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if (*outname == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 fatal ("Destination file name is empty", 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
315 VERBOSE(("checking access to output file\n"));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 /* Check access to output file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 pfatal_with_name (outname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 /* Also check that outname's directory is writable to the real uid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 char *buf = (char *) xmalloc (strlen (outname) + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 strcpy (buf, outname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 cp = buf + strlen (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 while (cp > buf && !IS_DIRECTORY_SEP (cp[-1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 *--cp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 if (cp == buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 *cp++ = '.';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 if (access (buf, W_OK) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 pfatal_with_name (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 free (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 if (!strncmp (inname, "po:", 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 int retcode = popmail (inname + 3, outname, poppass);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 exit (retcode);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
342 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 setuid (getuid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 #endif /* MAIL_USE_POP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 #ifndef DISABLE_DIRECT_ACCESS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 /* Check access to input file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 if (access (inname, R_OK | W_OK) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 pfatal_with_name (inname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
353
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
354 if (fork () == 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
355 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
356 setuid (getuid ());
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
357
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
358 VERBOSE(("opening input file\n"));
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
359
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
360 switch (lock_method)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
361 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
362 case DOTLOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
363 indesc = open (inname, O_RDONLY);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
364 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
365 #ifdef HAVE_LOCKF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
366 case LOCKFING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
367 indesc = open (inname, O_RDWR);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
368 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
369 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
370 #ifdef HAVE_FLOCK
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
371 case FLOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
372 indesc = open (inname, O_RDWR);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
373 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
374 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
375 #ifdef HAVE_LOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
376 case LOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
377 indesc = open (inname, O_RDWR);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
378 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
379 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
380 #ifdef HAVE_MMDF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
381 case MMDF:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
382 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
383 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
384 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
385 default: abort();
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
386 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
387
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
388 if (indesc < 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
389 pfatal_with_name (inname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
390
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
391 #ifdef HAVE_UMASK
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
392 /* In case movemail is setuid to root, make sure the user can
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
393 read the output file. */
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
394 umask (umask (0) & 0333);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
395 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
396
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
397 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
398 if (outdesc < 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
399 pfatal_with_name (outname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
400
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
401 VERBOSE(("locking input file\n"));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
403 switch (lock_method)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
404 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
405 #ifdef HAVE_LOCKF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
406 case LOCKFING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
407 if (lockf (indesc, F_LOCK, 0) < 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
408 pfatal_with_name (inname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
409 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
410 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
411 #ifdef HAVE_FLOCK
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
412 case FLOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
413 if (flock (indesc, LOCK_EX) < 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
414 pfatal_with_name (inname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
415 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
416 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
417 #ifdef HAVE_LOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
418 case LOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
419 if (locking (indesc, LK_RLCK, -1L) < 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
420 pfatal_with_name (inname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
421 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
422 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
423 case DOTLOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
424 lock_dot(inname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
425 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
426 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
427
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
428 VERBOSE(("copying input file to output file\n"));
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
429
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
430 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
431 char buf[1024];
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
432
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
433 while (1)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
434 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
435 nread = read (indesc, buf, sizeof buf);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
436 if (nread != write (outdesc, buf, nread))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
437 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
438 int saved_errno = errno;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
439 unlink (outname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
440 errno = saved_errno;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
441 pfatal_with_name (outname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
442 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
443 if (nread < sizeof buf)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
444 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
445 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
446 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
447
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
448 #ifdef HAVE_FSYNC
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
449 if (fsync (outdesc) < 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
450 pfatal_and_delete (outname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
451 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
452
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
453 /* Check to make sure no errors before we zap the inbox. */
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
454 if (close (outdesc) != 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
455 pfatal_and_delete (outname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
456
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
457 VERBOSE(("deleting or truncating input file\n"));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
459 switch (lock_method)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
460 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
461 case LOCKFING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
462 case FLOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
463 case LOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
464 #ifdef HAVE_FTRUNCATE
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
465 ftruncate (indesc, 0L);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
466 #else
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
467 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
468 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
469 close (indesc);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
470 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
471 #ifdef HAVE_MMDF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
472 case MMDF:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
473 lk_close (indesc, 0, 0, 0);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
474 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
475 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
476 case DOTLOCKING:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
477 creat (inname, 0600);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
478 break;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
479 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
480
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
481 exit (0);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
482 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
484 wait (&status);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
485 if (!WIFEXITED (status))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
486 exit (1);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
487 else if (WEXITSTATUS (status) != 0)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
488 exit (WEXITSTATUS (status));
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
489
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
490 if (lock_method == DOTLOCKING)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
491 unlock_dot(inname);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
492
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
493 #endif /* not DISABLE_DIRECT_ACCESS */
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
494
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
495 return 0;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
496 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
497
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
498 static void
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
499 usage(int lock_method)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
500 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
501 printf ("Usage: movemail [-rvxkh] [-l lines ] [-m method ] [-i] inbox [-o] destfile [[-p] POP-password]\n");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
502 printf("where method is one of: dot");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
503 #ifdef HAVE_LOCKF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
504 printf(", lockf");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
505 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
506 #ifdef HAVE_FLOCK
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
507 printf(", flock");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
508 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
509 #ifdef HAVE_MMDF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
510 printf(", mmdf");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
511 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
512 #ifdef HAVE_LOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
513 printf(", locking");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
514 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
515 printf("\nDefault is: %s\n", unparse_lock_method(lock_method));
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
516
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
517 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
519 static char *
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
520 unparse_lock_method(int lock_method)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
521 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
522 switch (lock_method)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
523 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
524 case DOTLOCKING: return "dot";
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
525 case FLOCKING: return "flock";
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
526 case LOCKFING: return "lockf";
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
527 case LOCKING: return "locking";
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
528 case MMDF: return "mmdf";
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
529 default: abort();return 0;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
530 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
531 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
533 static int
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
534 parse_lock_method(char *method_name)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
535 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
536 if (!strcmp("dot", method_name) || !strcmp("file", method_name))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
537 return DOTLOCKING;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
538 #ifdef HAVE_LOCKF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
539 else if (!strcmp("lockf", method_name))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
540 return LOCKFING;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
541 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
542 #ifdef HAVE_FLOCK
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
543 else if (!strcmp("flock", method_name))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
544 return FLOCKING;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
545 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
546 #ifdef HAVE_MMDF
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
547 else if (!strcmp("mmdf", method_name))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
548 return MMDF;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
549 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
550 #ifdef HAVE_LOCKING
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
551 else if (!strcmp("locking", method_name))
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
552 return LOCKING;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
553 #endif
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
554 else
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
555 fatal("invalid lock method: %s", method_name);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
556 return 0; /* unreached */
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
557 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
558
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
559 static char *
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
560 dot_filename(char *filename)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
561 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
562 return concat (filename, ".lock", "");
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
563 }
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
564
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
565 static char *dotlock_filename = NULL;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
566
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
567 #ifndef DISABLE_DIRECT_ACCESS
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
568 static void
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
569 lock_dot(char *filename)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
570 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
571 struct stat st;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
572 long now;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
573 int tem;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
574 char *lockname, *p;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
575 char *tempname;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
576 int desc;
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
577
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
578 dotlock_filename = (char *) xmalloc(strlen(filename) + 1);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
579
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
580 /* Use a lock file named after our first argument with .lock appended:
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
581 If it exists, the mail file is locked. */
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
582
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
583 lockname = dot_filename(filename);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
584 tempname = (char *) xmalloc (strlen (filename) + strlen ("EXXXXXX") + 1);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
585 strcpy (tempname, filename);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 p = tempname + strlen (tempname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 p--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 *p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 strcpy (p, "EXXXXXX");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 mktemp (tempname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 unlink (tempname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
594 for (;;)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 /* Create the lock file, but not under the lock file name. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 /* Give up if cannot do that. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 if (desc < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 char *message = (char *) xmalloc (strlen (tempname) + 50);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 sprintf (message, "%s--see source file lib-src/movemail.c",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 tempname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 pfatal_with_name (message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 close (desc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 tem = link (tempname, lockname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 unlink (tempname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 if (tem >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 sleep (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 /* If lock file is five minutes old, unlock it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 Five minutes should be good enough to cope with crashes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 and wedgitude, and long enough to avoid being fooled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 by time differences between machines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 if (stat (lockname, &st) >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 now = time (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 if (st.st_ctime < now - 300)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 unlink (lockname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 }
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
625 strcpy(dotlock_filename, filename);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
626 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
627 #endif /* not DISABLE_DIRECT_ACCESS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
629 static void
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
630 unlock_dot(char *filename)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
631 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
632 unlink(dot_filename(filename));
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
633 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
635 static void
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
636 maybe_unlock_dot(void)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
637 {
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
638 if (dotlock_filename)
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
639 unlock_dot(dotlock_filename);
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
640 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 /* Print error message and exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 fatal (char *s1, char *s2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
647 maybe_unlock_dot();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 error (s1, s2, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 error (char *s1, char *s2, char *s3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 fprintf (stderr, "movemail: ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 fprintf (stderr, s1, s2, s3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 fprintf (stderr, "\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 pfatal_with_name (char *name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 char *s = concat ("", strerror (errno), " for %s");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 fatal (s, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 pfatal_and_delete (char *name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 char *s = concat ("", strerror (errno), " for %s");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 unlink (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 fatal (s, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 concat (char *s1, char *s2, char *s3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 strcpy (result, s1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 strcpy (result + len1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 strcpy (result + len1 + len2, s3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 *(result + len1 + len2 + len3) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 static long *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 xmalloc (unsigned int size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 long *result = (long *) malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 if (!result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 fatal ("virtual memory exhausted", 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 }
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
703
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 /* This is the guts of the interface to the Post Office Protocol. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
708 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 #include <sys/socket.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 #include <netinet/in.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 #include <netdb.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 #undef _WINSOCKAPI_
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 #include <winsock.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 #include <stdio.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
717 #include "../src/syspwd.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 #define POP_ERROR (-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 #define POP_RETRIEVED (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 #define POP_DONE (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 char *progname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 FILE *sfi;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 FILE *sfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 char ibuffer[BUFSIZ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 char obuffer[BUFSIZ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 char Errmsg[80];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 popmail (char *user, char *outfile, char *password)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 int nmsgs, nbytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 register int i, idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 int mbfi;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 short* retrieved_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 FILE *mbf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 popserver server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
740 VERBOSE(("opening server\n"));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 server = pop_open (0, user, password, POP_NO_GETPASS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 if (! server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 error (pop_error, NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
748 VERBOSE(("stat'ing messages\n"));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 if (pop_stat (server, &nmsgs, &nbytes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 error (pop_error, NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 if (!nmsgs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 VERBOSE(("closing server\n"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 /* build a retrieved table */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 retrieved_list = (short*) xmalloc (sizeof (short) * (nmsgs+1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 memset (retrieved_list, 0, sizeof (short) * (nmsgs+1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 if (mbfi < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 error ("Error in open: %s, %s", strerror (errno), outfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
773 #if !defined(CYGWIN) && !defined(WIN32_NATIVE)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
774 fchown (mbfi, getuid (), (gid_t) -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 if ((mbf = fdopen (mbfi, "wb")) == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 error ("Error in fdopen: %s", strerror (errno), NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 close (mbfi);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 unlink (outfile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 for (idx = 0; idx < nmsgs; idx++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 i = reverse ? nmsgs - idx : idx + 1;
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
789 VERBOSE(("checking message %d \n", i));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 if (!regexp_pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 pop_search_top (server, i, match_lines, regexp_pattern) == POP_RETRIEVED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
795 VERBOSE(("retrieving message %d \n", i));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 mbx_delimit_begin (mbf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 if (pop_retr (server, i, mbx_write, mbf) != POP_RETRIEVED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 error (Errmsg, NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 close (mbfi);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 retrieved_list[i]=1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 mbx_delimit_end (mbf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 fflush (mbf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 if (ferror (mbf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 error ("Error in fflush: %s", strerror (errno), NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 close (mbfi);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 /* On AFS, a call to write only modifies the file in the local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 * workstation's AFS cache. The changes are not written to the server
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 * until a call to fsync or close is made. Users with AFS home
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 * directories have lost mail when over quota because these checks were
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 * not made in previous versions of movemail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
824 #ifdef HAVE_FSYNC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 if (fsync (mbfi) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 error ("Error in fsync: %s", strerror (errno), NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 if (close (mbfi) == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 error ("Error in close: %s", strerror (errno), NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 if (!keep_messages)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 for (i = 1; i <= nmsgs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 if (retrieved_list[i] == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
844 VERBOSE(("deleting message %d \n", i));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 if (pop_delete (server, i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 error (pop_error, NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 VERBOSE(("closing server \n"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 if (pop_quit (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 error (pop_error, NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 static int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
866 pop_retr (popserver server, int msgno, int (*action)(char *, FILE *), FILE *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 char *line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 if (pop_retrieve_first (server, msgno, &line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 strncpy (Errmsg, pop_error, sizeof (Errmsg));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 Errmsg[sizeof (Errmsg)-1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 while (! (ret = pop_retrieve_next (server, &line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 if (! line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 if ((*action)(line, arg) != POP_RETRIEVED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 strcpy (Errmsg, strerror (errno));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 if (ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 strncpy (Errmsg, pop_error, sizeof (Errmsg));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 Errmsg[sizeof (Errmsg)-1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 return (POP_RETRIEVED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 /* search the top lines of each message looking for a match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 pop_search_top (popserver server, int msgno, int lines, struct re_pattern_buffer* regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 char *line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 int match = POP_DONE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 if (pop_top_first (server, msgno, lines, &line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 strncpy (Errmsg, pop_error, sizeof (Errmsg));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 Errmsg[sizeof (Errmsg)-1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 while (! (ret = pop_top_next (server, &line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 if (! line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 /* VERBOSE (("checking %s\n", line));*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 if (match != POP_RETRIEVED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 if ((ret = re_match (regexp, line, strlen (line), 0, 0)) == -2 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 strcpy (Errmsg, "error in regular expression");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 else if (ret >=0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 match = POP_RETRIEVED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 if (ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 strncpy (Errmsg, pop_error, sizeof (Errmsg));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 Errmsg[sizeof (Errmsg)-1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 return match;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 /* Do this as a macro instead of using strcmp to save on execution time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 #define IS_FROM_LINE(a) ((a[0] == 'F') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 && (a[1] == 'r') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 && (a[2] == 'o') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 && (a[3] == 'm') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 && (a[4] == ' '))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 mbx_write (char *line, FILE *mbf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 if (IS_FROM_LINE (line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 if (fputc ('>', mbf) == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 if (fputs (line, mbf) == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 if (fputc (0x0a, mbf) == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 return (POP_RETRIEVED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 mbx_delimit_begin (FILE *mbf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 return (POP_RETRIEVED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 mbx_delimit_end (FILE *mbf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 if (putc ('\037', mbf) == EOF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 return (POP_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 return (POP_RETRIEVED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 /* Turn a name, which is an ed-style (but Emacs syntax) regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 expression, into a real regular expression by compiling it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 static struct re_pattern_buffer*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 compile_regex (char* pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 char *err;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 struct re_pattern_buffer *patbuf=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 patbuf = (struct re_pattern_buffer*) xmalloc (sizeof (struct re_pattern_buffer));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 patbuf->translate = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 patbuf->fastmap = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 patbuf->buffer = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 patbuf->allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 err = (char*) re_compile_pattern (pattern, strlen (pattern), patbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 if (err != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 error ("%s while compiling pattern", err, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 return patbuf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 #endif /* MAIL_USE_POP */
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
1012
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 #ifndef HAVE_STRERROR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 strerror (int errnum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 extern char *sys_errlist[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 extern int sys_nerr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 if (errnum >= 0 && errnum < sys_nerr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 return sys_errlist[errnum];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 return (char *) "Unknown error";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 #endif /* ! HAVE_STRERROR */