annotate lib-src/movemail.c @ 4623:a9f83990e6bf

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