annotate lib-src/movemail.c @ 400:a86b2b5e0111 r21-2-30

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