annotate lib-src/movemail.c @ 5555:a39cd9dc92ba

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