0
|
1 /* inc.c - incorporate messages from a maildrop into a folder */
|
|
2 #ifndef lint
|
12
|
3 static char ident[] = "@(#)$Id: inc.c,v 1.2 2006/12/05 18:18:13 kono Exp $";
|
0
|
4 #endif /* lint */
|
|
5
|
|
6 #ifdef MAILGROUP
|
|
7 /* Revised: Sat Apr 14 17:08:17 PDT 1990 (marvit@hplabs)
|
|
8 * Added hpux hacks to set and reset gid to be "mail" as needed. The reset
|
|
9 * is necessary so inc'ed mail is the group of the inc'er, rather than
|
|
10 * "mail". We setgid to egid only when [un]locking the mail file. This
|
|
11 * is also a major security precaution which will not be explained here.
|
|
12 *
|
|
13 * Fri Feb 7 16:04:57 PST 1992 John Romine <bug-mh@ics.uci.edu>
|
|
14 * NB: I'm not 100% sure that this setgid stuff is secure even now.
|
|
15 */
|
|
16 #endif
|
|
17
|
|
18 #include "../h/mh.h"
|
|
19 #ifdef POP
|
|
20 #include "../h/dropsbr.h"
|
|
21 #endif
|
|
22 #ifdef KPOP
|
|
23 #include <krb.h>
|
|
24 #endif
|
|
25 #ifdef HESIOD
|
|
26 #include <hesiod.h>
|
|
27 #endif
|
|
28 #include "../h/formatsbr.h"
|
|
29 #include "../h/scansbr.h"
|
|
30 #include "../zotnet/tws.h"
|
|
31 #include <stdio.h>
|
|
32 #include "../zotnet/mts.h"
|
|
33 #include <errno.h>
|
|
34 #include <signal.h>
|
|
35 #include <sys/types.h>
|
|
36 #include <sys/stat.h>
|
|
37 #ifdef LOCALE
|
|
38 #include <locale.h>
|
|
39 #endif
|
|
40 #ifdef UNISTD
|
|
41 #include <unistd.h>
|
|
42 #endif
|
|
43
|
|
44 /* */
|
|
45
|
|
46 #ifndef MF
|
|
47 #define MFminc(a) (a)
|
|
48 #else /* MF */
|
|
49 #define MFminc(a) 0
|
|
50 #endif /* MF */
|
|
51
|
|
52 #ifndef POP
|
|
53 #define POPminc(a) (a)
|
|
54 #else /* POP */
|
|
55 #define POPminc(a) 0
|
|
56 #endif /* POP */
|
|
57
|
|
58 #ifndef RPOP
|
|
59 #define RPOPminc(a) (a)
|
|
60 #else /* RPOP */
|
|
61 #define RPOPminc(a) 0
|
|
62 #endif /* RPOP */
|
|
63
|
|
64 #ifndef APOP
|
|
65 #define APOPminc(a) (a)
|
|
66 #else
|
|
67 #define APOPminc(a) 0
|
|
68 #endif /* APOP */
|
|
69
|
|
70 #ifndef TMA
|
|
71 #define TMAminc(a) (a)
|
|
72 #else /* TMA */
|
|
73 #define TMAminc(a) 0
|
|
74 #endif /* TMA */
|
|
75
|
|
76 static struct swit switches[] = {
|
|
77 #define AUDSW 0
|
|
78 "audit audit-file", 0,
|
|
79 #define NAUDSW 1
|
|
80 "noaudit", 0,
|
|
81
|
|
82 #define CHGSW 2
|
|
83 "changecur", 0,
|
|
84 #define NCHGSW 3
|
|
85 "nochangecur", 0,
|
|
86
|
|
87 #define DECRSW 4
|
|
88 "decrypt", TMAminc (-7),
|
|
89 #define NDECRSW 5
|
|
90 "nodecrypt", TMAminc (-9),
|
|
91
|
|
92 #define MSW 6
|
|
93 "file name", 0,
|
|
94
|
|
95 #define FORMSW 7
|
|
96 "form formatfile", 0,
|
|
97 #define FMTSW 8
|
|
98 "format string", 5,
|
|
99
|
|
100 #define HOSTSW 9
|
|
101 "host host", POPminc (-4),
|
|
102 #define USERSW 10
|
|
103 "user user", POPminc (-4),
|
|
104 #define PACKSW 11
|
|
105 "pack file", POPminc (-4),
|
|
106 #define NPACKSW 12
|
|
107 "nopack", POPminc (-6),
|
|
108
|
|
109 #define APOPSW 13
|
|
110 "apop", APOPminc (-4),
|
|
111 #define NAPOPSW 14
|
|
112 "noapop", APOPminc (-6),
|
|
113
|
|
114 #define RPOPSW 15
|
|
115 "rpop", RPOPminc (-4),
|
|
116 #define NRPOPSW 16
|
|
117 "norpop", RPOPminc (-6),
|
|
118
|
|
119 #define SILSW 17
|
|
120 "silent", 0,
|
|
121 #define NSILSW 18
|
|
122 "nosilent", 0,
|
|
123
|
|
124 #define TRNCSW 19
|
|
125 "truncate", 0,
|
|
126 #define NTRNCSW 20
|
|
127 "notruncate", 0,
|
|
128
|
|
129 #define UUCPSW 21
|
|
130 "uucp", MFminc (-4),
|
|
131 #define NUUCPSW 22
|
|
132 "nouucp", MFminc (-6),
|
|
133
|
|
134 #define WIDSW 23
|
|
135 "width columns", 0,
|
|
136
|
|
137 #define HELPSW 24
|
|
138 "help", 4,
|
|
139
|
|
140 NULL, 0
|
|
141 };
|
|
142
|
|
143 /* */
|
|
144
|
|
145
|
|
146 #ifdef POP
|
|
147 int snoop = 0;
|
|
148 extern char response[];
|
|
149
|
|
150 static char *file = NULL;
|
|
151 static int size;
|
|
152 static long pos;
|
|
153 static long start;
|
|
154 static long stop;
|
|
155
|
|
156 static int pd = NOTOK;
|
|
157 static FILE *pf = NULL;
|
|
158
|
|
159 static int pop_action (), pop_pack ();
|
|
160 static int map_count();
|
|
161 #endif /* POP */
|
|
162
|
|
163 /* * /
|
|
164
|
|
165 /* ARGSUSED */
|
|
166
|
|
167 #ifdef POP
|
|
168 static int real_uid;
|
|
169 #endif /* POP */
|
|
170 #ifdef MAILGROUP /* For setting and returning to "mail" gid */
|
|
171 static int return_gid;
|
|
172 #endif /* MAILGROUP */
|
|
173
|
|
174 /* these variables have to be globals so that done() can correctly clean up the lockfile */
|
|
175 static int locked = 0;
|
|
176 static char *newmail;
|
|
177 static FILE *in;
|
|
178
|
|
179 main (argc, argv)
|
|
180 int argc;
|
|
181 char *argv[];
|
|
182 {
|
|
183 int chgflag = 1,
|
|
184 trnflag = 1,
|
|
185 decflag = 1,
|
|
186 noisy = 1,
|
|
187 width = 0,
|
|
188 #ifdef MF
|
|
189 uucp = 1,
|
|
190 #endif /* MF */
|
|
191 #ifdef POP
|
|
192 nmsgs,
|
|
193 nbytes,
|
|
194 p = 0,
|
|
195 #endif /* POP */
|
|
196 #if !defined(RPOP) && !defined(APOP)
|
|
197 rpop = 0,
|
|
198 #else /* RPOP || APOP */
|
|
199 #if defined(APOP)
|
|
200 rpop = -1,
|
|
201 #else /* RPOP */
|
|
202 rpop = 1,
|
|
203 #endif /* APOP */
|
|
204 #endif /* !RPOP && !APOP */
|
|
205 i,
|
|
206 hghnum,
|
|
207 msgnum;
|
|
208 char *cp,
|
|
209 *maildir,
|
|
210 *folder = NULL,
|
|
211 *form = NULL,
|
|
212 *format = NULL,
|
|
213 *audfile = NULL,
|
|
214 *from = NULL,
|
|
215 *host = NULL,
|
|
216 #ifdef POP
|
|
217 *pass = NULL,
|
|
218 #endif /* POP */
|
|
219 buf[100],
|
|
220 **ap,
|
|
221 **argp,
|
|
222 *nfs,
|
|
223 *arguments[MAXARGS];
|
|
224 char *user = NULL;
|
|
225 struct msgs *mp;
|
|
226 struct stat st,
|
|
227 s1;
|
|
228 FILE *aud = NULL;
|
|
229 #ifdef MHE
|
|
230 FILE *mhe = NULL;
|
|
231 #endif /* MHE */
|
|
232 #ifdef HESIOD
|
|
233 struct hes_postoffice *po;
|
|
234 char *tmphost;
|
|
235 #endif
|
|
236
|
|
237 /* absolutely the first thing we do is save our privileges,
|
|
238 * and drop them if we can.
|
|
239 */
|
|
240 #ifdef POP
|
|
241 /*
|
|
242 * On some system, we can regain the root privileges
|
|
243 * even after switching to normal privileges.
|
|
244 */
|
|
245 real_uid = getuid();
|
|
246 #ifdef hpux
|
|
247 setresuid(-1, real_uid, -1);
|
|
248 #else
|
|
249 #ifdef SETEUID
|
|
250 seteuid(real_uid);
|
|
251 #else
|
|
252 #ifdef SETREUID
|
|
253 getusr();
|
|
254 setreuid(0, real_uid);
|
|
255 #endif /* SETREUID */
|
|
256 #endif /* SETEUID */
|
|
257 #endif /* hpux */
|
|
258 #endif /* POP */
|
|
259 #ifdef MAILGROUP
|
|
260 return_gid = getegid(); /* Save effective gid, assuming we'll use it */
|
|
261
|
|
262 #ifdef todo
|
|
263 /*
|
|
264 * TODO: On some system, setgid() changes saved gid even when it is called
|
|
265 * by non-privileged user. We should use setegid() on such a system.
|
|
266 */
|
|
267 #define setgid setegid
|
|
268 #endif
|
|
269 #ifdef POP
|
|
270 /*
|
|
271 * with MAILGROUP and POP both defined the setgid() call ran as root,
|
|
272 * and saved gid would be lost. At first, we must check the effective uid.
|
|
273 * (cf. 93/12/17 bsa@kf8nh.wariat.org)
|
|
274 */
|
|
275 if (geteuid() != 0)
|
|
276 setgid(getgid()); /* Turn off extraordinary privileges */
|
|
277 #else /* POP */
|
|
278 setgid(getgid()); /* Turn off extraordinary privileges */
|
|
279 #endif /* POP */
|
|
280 #endif /* MAILGROUP */
|
|
281
|
|
282 #ifdef LOCALE
|
|
283 setlocale(LC_ALL, "");
|
|
284 #endif
|
|
285 #ifdef JAPAN
|
|
286 ml_init();
|
|
287 #endif /* JAPAN */
|
|
288 invo_name = r1bindex (argv[0], '/');
|
|
289 if (strlen(invo_name) > NAMESZ) {
|
|
290 fprintf(stderr, "%s: argv[0] too long\n", invo_name);
|
|
291 exit(1);
|
|
292 }
|
|
293 mts_init (invo_name);
|
|
294
|
|
295 #ifdef MH_PLUS
|
|
296 if (rpop_default && *rpop_default)
|
|
297 rpop = atoi(rpop_default);
|
|
298 #endif /* MH_PLUS */
|
|
299 #ifdef POP
|
|
300 #ifdef HESIOD
|
|
301 /*
|
|
302 * Scheme is:
|
|
303 * use MAILHOST environment variable if present,
|
|
304 * else try Hesiod.
|
|
305 * If that fails, use the default (if any)
|
|
306 * provided by mtstailor in mts_init()
|
|
307 */
|
|
308 if ((tmphost = getenv("MAILHOST")) != NULL && strlen(tmphost) < BUFSIZ / 4)
|
|
309 pophost = tmphost;
|
|
310 else if ((po = hes_getmailhost(getusr())) != NULL &&
|
|
311 strcmp(po->po_type, "POP") == 0)
|
|
312 pophost = po->po_host;
|
|
313 #endif /* HESIOD */
|
|
314 if (pophost && *pophost)
|
|
315 host = pophost;
|
|
316
|
|
317 if ((cp = getenv ("MHPOPDEBUG")) && *cp)
|
|
318 snoop++;
|
|
319 #endif
|
|
320
|
|
321 if ((cp = m_find (invo_name)) != NULL) {
|
|
322 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
323 ap = copyip (ap, arguments);
|
|
324 }
|
|
325 else
|
|
326 ap = arguments;
|
|
327 if (argc > MAXARGS - (ap - arguments))
|
|
328 adios (NULLCP, "too many arguments.");
|
|
329 (void) copyip (argv + 1, ap);
|
|
330 for (argp = arguments; *argp; argp++)
|
|
331 if (strlen(*argp) >= BUFSIZ / 4)
|
|
332 adios (NULLCP, "argument too long");
|
|
333 argp = arguments;
|
|
334
|
|
335 /* */
|
|
336
|
|
337 while (cp = *argp++) {
|
|
338 if (*cp == '-')
|
|
339 switch (smatch (++cp, switches)) {
|
|
340 case AMBIGSW:
|
|
341 ambigsw (cp, switches);
|
|
342 done (1);
|
|
343 case UNKWNSW:
|
|
344 adios (NULLCP, "-%s unknown", cp);
|
|
345 case HELPSW:
|
|
346 (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
|
|
347 help (buf, switches);
|
|
348 done (1);
|
|
349
|
|
350 case AUDSW:
|
|
351 if (!(cp = *argp++) || *cp == '-')
|
|
352 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
353 audfile = getcpy (m_maildir (cp));
|
|
354 continue;
|
|
355 case NAUDSW:
|
|
356 audfile = NULL;
|
|
357 continue;
|
|
358
|
|
359 case CHGSW:
|
|
360 chgflag++;
|
|
361 continue;
|
|
362 case NCHGSW:
|
|
363 chgflag = 0;
|
|
364 continue;
|
|
365
|
|
366 case TRNCSW:
|
|
367 trnflag = 2;
|
|
368 continue;
|
|
369 case MSW:
|
|
370 if (!(cp = *argp++) || *cp == '-')
|
|
371 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
372 from = path (cp, TFILE);/* fall */
|
|
373 if (trnflag == 2)
|
|
374 continue;
|
|
375 case NTRNCSW:
|
|
376 trnflag = 0;
|
|
377 continue;
|
|
378
|
|
379 case SILSW:
|
|
380 noisy = 0;
|
|
381 continue;
|
|
382 case NSILSW:
|
|
383 noisy++;
|
|
384 continue;
|
|
385
|
|
386 case FORMSW:
|
|
387 if (!(form = *argp++) || *form == '-')
|
|
388 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
389 format = NULL;
|
|
390 continue;
|
|
391 case FMTSW:
|
|
392 if (!(format = *argp++) || *format == '-')
|
|
393 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
394 form = NULL;
|
|
395 continue;
|
|
396
|
|
397 case WIDSW:
|
|
398 if (!(cp = *argp++) || *cp == '-')
|
|
399 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
400 width = atoi (cp);
|
|
401 continue;
|
|
402
|
|
403 case DECRSW:
|
|
404 decflag++;
|
|
405 continue;
|
|
406 case NDECRSW:
|
|
407 decflag = 0;
|
|
408 continue;
|
|
409
|
|
410 case UUCPSW:
|
|
411 #ifdef MF
|
|
412 uucp++;
|
|
413 #endif /* MF */
|
|
414 continue;
|
|
415 case NUUCPSW:
|
|
416 #ifdef MF
|
|
417 uucp = 0;
|
|
418 #endif /* MF */
|
|
419 continue;
|
|
420
|
|
421 case HOSTSW:
|
|
422 if (!(host = *argp++) || *host == '-')
|
|
423 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
424 continue;
|
|
425 case USERSW:
|
|
426 if (!(user = *argp++) || *user == '-')
|
|
427 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
428 continue;
|
|
429 case PACKSW:
|
|
430 #ifndef POP
|
|
431 if (!(cp = *argp++) || *cp == '-')
|
|
432 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
433 #else /* POP */
|
|
434 if (!(file = *argp++) || *file == '-')
|
|
435 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
436 #endif /* POP */
|
|
437 continue;
|
|
438 case NPACKSW:
|
|
439 #ifdef POP
|
|
440 file = NULLCP;
|
|
441 #endif /* POP */
|
|
442 continue;
|
|
443 case APOPSW:
|
|
444 rpop = -1;
|
|
445 continue;
|
|
446 case RPOPSW:
|
|
447 rpop = 1;
|
|
448 continue;
|
|
449 case NAPOPSW:
|
|
450 case NRPOPSW:
|
|
451 rpop = 0;
|
|
452 continue;
|
|
453 }
|
|
454 if (*cp == '+' || *cp == '@') {
|
|
455 if (folder)
|
|
456 adios (NULLCP, "only one folder at a time!");
|
|
457 else
|
|
458 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
|
|
459 }
|
|
460 else
|
|
461 adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
|
|
462 }
|
|
463
|
|
464 /* */
|
|
465
|
|
466 #ifdef POP
|
|
467 if (host && !*host)
|
|
468 host = NULL;
|
|
469 if (from || !host || rpop <= 0)
|
|
470 #ifndef SETREUID
|
|
471 (void) setuid (real_uid);
|
|
472 #else
|
|
473 {
|
|
474 setreuid(-1, 0);
|
|
475 setreuid(real_uid, real_uid);
|
|
476 }
|
|
477 #endif /* SETREUID */
|
|
478 #endif /* POP */
|
|
479
|
|
480 #ifdef MAILGROUP
|
|
481 setgid(getgid()); /* Turn off extraordinary privileges */
|
|
482 #endif /* MAILGROUP */
|
|
483
|
|
484 if (from) {
|
|
485 newmail = from;
|
|
486 #ifdef POP
|
|
487 host = NULL;
|
|
488 #endif /* POP */
|
|
489 if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
|
|
490 adios (NULLCP, "no mail to incorporate");
|
|
491 }
|
|
492 #ifdef POP
|
|
493 else if (host) {
|
|
494 int status;
|
|
495
|
|
496 if (user == NULL)
|
|
497 user = getusr ();
|
|
498 if (rpop > 0)
|
|
499 pass = getusr ();
|
|
500 else
|
|
501 ruserpass (host, &user, &pass);
|
|
502
|
|
503 /* Regain root privileges to open a privileged port for RPOP. */
|
|
504 #ifdef hpux
|
|
505 if (rpop > 0)
|
|
506 setresuid(-1, 0, -1);
|
|
507 #else
|
|
508 #ifdef SETEUID
|
|
509 if (rpop > 0)
|
|
510 seteuid(0);
|
|
511 #else
|
|
512 #ifdef SETREUID
|
|
513 if (rpop > 0) {
|
|
514 setreuid(-1, 0);
|
|
515 setreuid(real_uid, 0);
|
|
516 }
|
|
517 #endif /* SETREUID */
|
|
518 #endif /* SETEUID */
|
|
519 #endif /* hpux */
|
|
520 status = pop_init (host, user, pass, snoop, rpop);
|
|
521 if (rpop > 0)
|
|
522 (void) setuid (real_uid);
|
|
523 if (status == NOTOK || pop_stat (&nmsgs, &nbytes) == NOTOK)
|
|
524 adios (NULLCP, "%s", response);
|
|
525 if (nmsgs == 0) {
|
|
526 (void) pop_quit ();
|
|
527 adios (NULLCP, "no mail to incorporate");
|
|
528 }
|
|
529 }
|
|
530 #endif /* POP */
|
|
531 else {
|
|
532 if (((newmail = getenv ("MAILDROP")) && *newmail)
|
|
533 || ((newmail = m_find ("maildrop")) && *newmail)) {
|
|
534 if (strlen(newmail) >= BUFSIZ / 4)
|
|
535 adios (NULLCP, "Maildrop name too long");
|
|
536 newmail = m_mailpath (newmail);
|
|
537 } else {
|
|
538 #ifdef MF
|
|
539 if (uucp && umincproc && *umincproc)
|
|
540 get_uucp_mail ();
|
|
541 #endif /* MF */
|
|
542 newmail = concat (MAILDIR, "/", MAILFIL, NULLCP);
|
|
543 }
|
|
544 if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
|
|
545 adios (NULLCP, "no mail to incorporate");
|
|
546 }
|
|
547
|
|
548 #ifdef POP
|
|
549 if (host && file)
|
|
550 goto go_to_it;
|
|
551 #endif /* POP */
|
|
552 if (!m_find ("path"))
|
|
553 free (path ("./", TFOLDER));
|
|
554 if (!folder && !(folder = m_find (inbox)))
|
|
555 folder = defalt;
|
|
556 if (strlen(folder) >= BUFSIZ / 4)
|
|
557 adios (NULLCP, "Inbox name too long");
|
|
558 maildir = m_maildir (folder);
|
|
559
|
|
560 if (stat (maildir, &st) == NOTOK) {
|
|
561 if (errno != ENOENT)
|
|
562 adios (maildir, "error on folder");
|
|
563 cp = concat ("Create folder \"", maildir, "\"? ", NULLCP);
|
|
564 if (noisy && !getanswer (cp))
|
|
565 done (1);
|
|
566 free (cp);
|
|
567 if (!makedir (maildir))
|
|
568 adios (NULLCP, "unable to create folder %s", maildir);
|
|
569 }
|
|
570
|
|
571 if (chdir (maildir) == NOTOK)
|
|
572 adios (maildir, "unable to change directory to");
|
|
573 if (!(mp = m_gmsg (folder)))
|
|
574 adios (NULLCP, "unable to read folder %s", folder);
|
|
575
|
|
576 /* */
|
|
577
|
|
578 #ifdef POP
|
|
579 go_to_it: ;
|
|
580 if (host == NULL)
|
|
581 #endif /* POP */
|
|
582 if (access (newmail, 02) == NOTOK) {
|
|
583 trnflag = 0;
|
|
584 if ((in = fopen (newmail, "r")) == NULL)
|
|
585 adios (newmail, "unable to read");
|
|
586 }
|
|
587 else {
|
|
588 locked++;
|
|
589 if (trnflag) {
|
|
590 (void) signal (SIGHUP, SIG_IGN);
|
|
591 (void) signal (SIGINT, SIG_IGN);
|
|
592 (void) signal (SIGQUIT, SIG_IGN);
|
|
593 (void) signal (SIGTERM, SIG_IGN);
|
|
594 }
|
|
595
|
|
596 #ifdef MAILGROUP
|
|
597 setgid(return_gid); /* Reset gid to lock mail file */
|
|
598 #endif /* MAILGROUP */
|
|
599 in = lkfopen (newmail, "r");
|
|
600 #ifdef MAILGROUP
|
|
601 setgid(getgid()); /* Return us to normal privileges */
|
|
602 #endif /* MAILGROUP */
|
|
603 if (in == NULL)
|
|
604 adios (NULLCP, "unable to lock and fopen %s", newmail);
|
|
605 (void) fstat (fileno(in), &s1);
|
|
606 }
|
|
607
|
|
608 #ifdef MAILGROUP
|
|
609 setgid(getgid()); /* Return us to normal privileges */
|
|
610 #endif /* MAILGROUP */
|
|
611
|
|
612 if (audfile) {
|
|
613 if ((i = stat (audfile, &st)) == NOTOK)
|
|
614 advise (NULLCP, "Creating Receive-Audit: %s", audfile);
|
|
615 if ((aud = fopen (audfile, "a")) == NULL)
|
|
616 adios (audfile, "unable to append to");
|
|
617 else
|
|
618 if (i == NOTOK)
|
|
619 (void) chmod (audfile, m_gmprot ());
|
|
620 #ifndef POP
|
|
621 fprintf (aud, from ? "<<inc>> %s -ms %s\n" : "<<inc>> %s\n",
|
|
622 dtimenow (), from);
|
|
623 #else /* POP */
|
|
624 fprintf (aud, from ? "<<inc>> %s -ms %s\n"
|
|
625 : host ? "<<inc>> %s -host %s -user %s%s\n"
|
|
626 : "<<inc>> %s\n",
|
|
627 dtimenow (), from ? from : host, user,
|
|
628 rpop < 0 ? " -apop" : rpop > 0 ? " -rpop" : "");
|
|
629 #endif /* POP */
|
|
630 }
|
|
631
|
|
632 #ifdef MHE
|
|
633 if (m_find ("mhe")) {
|
|
634 cp = concat (maildir, "/++", NULLCP);
|
|
635 i = stat (cp, &st);
|
|
636 if ((mhe = fopen (cp, "a")) == NULL)
|
|
637 admonish (cp, "unable to append to");
|
|
638 else
|
|
639 if (i == NOTOK)
|
|
640 (void) chmod (cp, m_gmprot ());
|
|
641 free (cp);
|
|
642 }
|
|
643 #endif /* MHE */
|
|
644
|
|
645 nfs = new_fs (form, format, FORMAT);
|
|
646
|
|
647 if (noisy) {
|
|
648 printf ("Incorporating new mail into %s...\n\n", folder);
|
|
649 (void) fflush (stdout);
|
|
650 }
|
|
651
|
|
652 /* */
|
|
653
|
|
654 #ifdef POP
|
|
655 if (host) {
|
|
656 if (file) {
|
|
657 file = path (file, TFILE);
|
|
658 if (stat (file, &st) == NOTOK) {
|
|
659 if (errno != ENOENT)
|
|
660 adios (file, "error on file");
|
|
661 cp = concat ("Create file \"", file, "\"? ", NULLCP);
|
|
662 if (noisy && !getanswer (cp))
|
|
663 done (1);
|
|
664 free (cp);
|
|
665 }
|
|
666 msgnum = map_count ();
|
|
667 if ((pd = mbx_open (file, getuid (), getgid (), m_gmprot ()))
|
|
668 == NOTOK)
|
|
669 adios (file, "unable to open");
|
|
670 if ((pf = fdopen (pd, "w+")) == NULL)
|
|
671 adios (NULLCP, "unable to fdopen %s", file);
|
|
672 }
|
|
673 else {
|
|
674 hghnum = msgnum = mp -> hghmsg;
|
|
675 if ((mp = m_remsg (mp, 0, mp -> hghmsg + nmsgs)) == NULL)
|
|
676 adios (NULLCP, "unable to allocate folder storage");
|
|
677 }
|
|
678
|
|
679 for (i = 1; i <= nmsgs; i++) {
|
|
680 msgnum++;
|
|
681 if (file) {
|
|
682 (void) fseek (pf, 0L, 1);
|
|
683 pos = ftell (pf);
|
|
684 size = 0;
|
|
685 (void) fwrite (mmdlm1, 1, strlen (mmdlm1), pf);
|
|
686 start = ftell (pf);
|
|
687
|
|
688 if (pop_retr (i, pop_pack) == NOTOK)
|
|
689 adios (NULLCP, "%s", response);
|
|
690
|
|
691 (void) fseek (pf, 0L, 1);
|
|
692 stop = ftell (pf);
|
|
693 if (fflush (pf))
|
|
694 adios (file, "write error on");
|
|
695 (void) fseek (pf, start, 0);
|
|
696 }
|
|
697 else {
|
|
698 cp = getcpy (m_name (msgnum));
|
|
699 if ((pf = fopen (cp, "w+")) == NULL)
|
|
700 adios (cp, "unable to write");
|
|
701 (void) chmod (cp, m_gmprot ());
|
|
702 start = stop = 0L;
|
|
703
|
|
704 if (pop_retr (i, pop_action) == NOTOK)
|
|
705 adios (NULLCP, "%s", response);
|
|
706
|
|
707 if (fflush (pf))
|
|
708 adios (cp, "write error on");
|
|
709 (void) fseek (pf, 0L, 0);
|
|
710 }
|
|
711 switch (p = scan (pf, msgnum, 0, nfs, width,
|
|
712 file ? 0 : msgnum == mp -> hghmsg + 1 && chgflag,
|
|
713 1, /* check UNSEEN? */
|
|
714 0, 0, stop - start, noisy)) {
|
|
715 case SCNEOF:
|
|
716 printf ("%*d empty\n", DMAXFOLDER, msgnum);
|
|
717 break;
|
|
718
|
|
719 case SCNFAT:
|
|
720 trnflag = 0;
|
|
721 noisy++;
|
|
722 /* advise (cp, "unable to read"); already advised */
|
|
723 /* fall thru */
|
|
724
|
|
725 case SCNERR:
|
|
726 case SCNNUM:
|
|
727 break;
|
|
728
|
|
729 case SCNMSG:
|
|
730 case SCNENC:
|
|
731 default:
|
|
732 if (aud)
|
|
733 #ifdef JAPAN
|
|
734 ml_fputs (scanl, aud);
|
|
735 #else /* JAPAN */
|
|
736 fputs (scanl, aud);
|
|
737 #endif /* JAPAN */
|
|
738 #ifdef MHE
|
|
739 if (mhe)
|
|
740 #ifdef JAPAN
|
|
741 ml_fputs (scanl, mhe);
|
|
742 #else /* JAPAN */
|
|
743 fputs (scanl, mhe);
|
|
744 #endif /* JAPAN */
|
|
745 #endif /* MHE */
|
|
746 if (noisy)
|
|
747 (void) fflush (stdout);
|
|
748 if (!file) {
|
|
749 mp -> msgstats[msgnum] = EXISTS;
|
|
750 #ifdef TMA
|
|
751 if (p == SCNENC) {
|
|
752 if (mp -> lowsel == 0 || msgnum < mp -> lowsel)
|
|
753 mp -> lowsel = msgnum;
|
|
754 if (mp -> hghsel == 0 || msgnum > mp -> hghsel)
|
|
755 mp -> hghsel = msgnum;
|
|
756 mp -> numsel++;
|
|
757 mp -> msgstats[msgnum] |= SELECTED;
|
|
758 }
|
|
759 #endif /* TMA */
|
|
760 mp -> msgstats[msgnum] |= UNSEEN;
|
|
761 mp -> msgflags |= SEQMOD;
|
|
762 }
|
|
763 break;
|
|
764 }
|
|
765 if (file) {
|
|
766 (void) fseek (pf, stop, 0);
|
|
767 (void) fwrite (mmdlm2, 1, strlen (mmdlm2), pf);
|
|
768 if (fflush (pf) || ferror (pf)) {
|
|
769 int e = errno;
|
|
770 (void) pop_quit ();
|
|
771 errno = e;
|
|
772 adios (file, "write error on");
|
|
773 }
|
|
774 (void) map_write (file, pd, 0, 0L, start, stop, pos, size,
|
|
775 noisy);
|
|
776 }
|
|
777 else {
|
|
778 if (ferror(pf) || fclose (pf)) {
|
|
779 int e = errno;
|
|
780 (void) unlink (cp);
|
|
781 (void) pop_quit ();
|
|
782 errno = e;
|
|
783 adios (cp, "write error on");
|
|
784 }
|
|
785 free (cp);
|
|
786 }
|
|
787
|
|
788 if (trnflag && pop_dele (i) == NOTOK)
|
|
789 adios (NULLCP, "%s", response);
|
|
790 }
|
|
791 if (pop_quit () == NOTOK)
|
|
792 adios (NULLCP, "%s", response);
|
|
793 if (file) {
|
|
794 (void) mbx_close (file, pd);
|
|
795 pd = NOTOK;
|
|
796 }
|
|
797 }
|
|
798 else {
|
|
799 #endif /* POP */
|
|
800
|
|
801 /* */
|
|
802
|
|
803 m_unknown (in); /* the MAGIC invocation... */
|
|
804 hghnum = msgnum = mp -> hghmsg;
|
|
805 for (i = 0;;) {
|
|
806 if (msgnum >= mp -> hghoff)
|
|
807 if ((mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER)) == NULL) {
|
|
808 advise (NULLCP, "unable to allocate folder storage");
|
|
809 i = NOTOK;
|
|
810 break;
|
|
811 }
|
|
812
|
|
813 switch (i = scan (in, msgnum + 1, msgnum + 1, nfs, width,
|
|
814 msgnum == hghnum && chgflag,
|
|
815 1, /* check UNSEEN? */
|
|
816 0, 0, 0L, noisy)) {
|
|
817 case SCNFAT:
|
|
818 case SCNEOF:
|
|
819 break;
|
|
820
|
|
821 case SCNERR:
|
|
822 if (aud)
|
|
823 fputs ("inc aborted!\n", aud);
|
|
824 advise (NULLCP, "aborted!"); /* doesn't clean up locks! */
|
|
825 break;
|
|
826
|
|
827 case SCNNUM:
|
|
828 advise (NULLCP,
|
|
829 "more than %d messages in folder %s, %s not zero'd",
|
|
830 MAXFOLDER, folder, newmail);
|
|
831 break;
|
|
832
|
|
833 default:
|
|
834 advise (NULLCP, "scan() botch (%d)", i);
|
|
835 break;
|
|
836
|
|
837 case SCNMSG:
|
|
838 case SCNENC:
|
|
839 if (aud)
|
|
840 #ifdef JAPAN
|
|
841 ml_fputs (scanl, aud);
|
|
842 #else /* JAPAN */
|
|
843 fputs (scanl, aud);
|
|
844 #endif /* JAPAN */
|
|
845 #ifdef MHE
|
|
846 if (mhe)
|
|
847 #ifdef JAPAN
|
|
848 ml_fputs (scanl, mhe);
|
|
849 #else /* JAPAN */
|
|
850 fputs (scanl, mhe);
|
|
851 #endif /* JAPAN */
|
|
852 #endif /* MHE */
|
|
853 if (noisy)
|
|
854 (void) fflush (stdout);
|
|
855
|
|
856 msgnum++, mp -> hghmsg++;
|
|
857 mp -> msgstats[msgnum] = EXISTS;
|
|
858 #ifdef TMA
|
|
859 if (i == SCNENC) {
|
|
860 if (mp -> lowsel == 0 || mp -> lowsel > msgnum)
|
|
861 mp -> lowsel = msgnum;
|
|
862 if (mp -> hghsel == 0 || mp -> hghsel < msgnum)
|
|
863 mp -> hghsel = msgnum;
|
|
864 mp -> numsel++;
|
|
865 mp -> msgstats[msgnum] |= SELECTED;
|
|
866 }
|
|
867 #endif /* TMA */
|
|
868 mp -> msgstats[msgnum] |= UNSEEN;
|
|
869 mp -> msgflags |= SEQMOD;
|
|
870 continue;
|
|
871 }
|
|
872 break;
|
|
873 }
|
|
874 #ifdef POP
|
|
875 }
|
|
876 #endif /* POP */
|
|
877 #ifndef POP
|
|
878 if (i < 0) { /* error } */
|
|
879 #else
|
|
880 if (p < 0) { /* error */
|
|
881 #endif
|
|
882 if (locked)
|
|
883 #ifdef MAILGROUP
|
|
884 {
|
|
885 setgid(return_gid); /* Be sure we can unlock mail file */
|
|
886 #endif /* MAILGROUP */
|
|
887
|
|
888 if (! lkfclose (in, newmail))
|
|
889 locked = 0;
|
|
890 #ifdef MAILGROUP
|
|
891 setgid(getgid()); /* And then return us to normal privileges */
|
|
892 }
|
|
893 #endif /* MAILGROUP */
|
|
894 else
|
|
895 (void) fclose (in);
|
|
896 adios (NULLCP, "failed");
|
|
897 }
|
|
898
|
|
899 if (aud)
|
|
900 (void) fclose (aud);
|
|
901 #ifdef MHE
|
|
902 if (mhe)
|
|
903 (void) fclose (mhe);
|
|
904 #endif /* MHE */
|
|
905 if (noisy)
|
|
906 (void) fflush (stdout);
|
|
907 #ifdef POP
|
|
908 if (host && file)
|
|
909 done (0);
|
|
910 #endif /* POP */
|
|
911
|
|
912 /* */
|
|
913
|
|
914 #ifdef POP
|
|
915 if (host == NULL)
|
|
916 #endif /* POP */
|
|
917 if (trnflag) {
|
|
918 if (stat (newmail, &st) != NOTOK && s1.st_mtime != st.st_mtime)
|
|
919 advise (NULLCP, "new messages have arrived!\007");
|
|
920 else {
|
|
921 if ((i = creat (newmail, 0600)) != NOTOK)
|
|
922 (void) close (i);
|
|
923 else
|
|
924 admonish (newmail, "error zero'ing");
|
|
925 (void) unlink (map_name (newmail));
|
|
926 }
|
|
927 }
|
|
928 else
|
|
929 if (noisy)
|
|
930 printf ("%s not zero'd\n", newmail);
|
|
931
|
|
932 if (msgnum == hghnum)
|
|
933 admonish (NULLCP, "no messages incorporated");
|
|
934 else {
|
|
935 m_replace (pfolder, folder);
|
|
936 if (chgflag)
|
|
937 mp -> curmsg = hghnum + 1;
|
|
938 mp -> hghmsg = msgnum;
|
|
939 if (mp -> lowmsg == 0)
|
|
940 mp -> lowmsg = 1;
|
|
941 if (chgflag) /* sigh... */
|
|
942 m_setcur (mp, mp -> curmsg);
|
|
943 }
|
|
944
|
|
945 #ifdef POP
|
|
946 if (host == NULL)
|
|
947 #endif /* POP */
|
|
948 if (locked)
|
|
949 #ifdef MAILGROUP
|
|
950 {
|
|
951 setgid(return_gid); /* Be sure we can unlock mail file */
|
|
952 #endif /* MAILGROUP */
|
|
953
|
|
954 if (! lkfclose (in, newmail))
|
|
955 locked = 0;
|
|
956 #ifdef MAILGROUP
|
|
957 setgid(getgid()); /* And then return us to normal privileges */
|
|
958 }
|
|
959 #endif /* MAILGROUP */
|
|
960 else
|
|
961 (void) fclose (in);
|
|
962
|
|
963 m_setvis (mp, 0);
|
|
964 m_sync (mp);
|
|
965 m_update ();
|
|
966
|
|
967 #ifdef TMA
|
|
968 if (decflag && mp -> numsel > 0) {
|
|
969 if (noisy) {
|
|
970 printf ("\nIncorporating encrypted mail into %s...\n\n", folder);
|
|
971 (void) fflush (stdout);
|
|
972 }
|
|
973
|
|
974 tmastart (0);
|
|
975 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
|
|
976 if (mp -> msgstats[msgnum] & SELECTED && decipher (msgnum) == OK) {
|
|
977 if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) {
|
|
978 admonish (cp, "unable to open message");
|
|
979 free (cp);
|
|
980 continue;
|
|
981 }
|
|
982 switch (scan (in, msgnum, 0, nfs, width,
|
|
983 msgnum == mp -> curmsg,
|
|
984 1, /* check UNSEEN? */
|
|
985 0, 0,
|
|
986 fstat (fileno (in), &st) != NOTOK ? (long) st.st_size
|
|
987 : 0L,
|
|
988 noisy)) {
|
|
989 case SCNEOF:
|
|
990 printf ("%*d empty\n", DMAXFOLDER, msgnum);
|
|
991 break;
|
|
992
|
|
993 default:
|
|
994 break;
|
|
995 }
|
|
996 (void) fclose (in);
|
|
997 free (cp);
|
|
998 }
|
|
999 tmastop ();
|
|
1000
|
|
1001 if (noisy)
|
|
1002 (void) fflush (stdout);
|
|
1003 }
|
|
1004 #endif /* TMA */
|
|
1005
|
|
1006 done (0);
|
|
1007 }
|
|
1008
|
|
1009 /* */
|
|
1010
|
|
1011 void done (status)
|
|
1012 int status;
|
|
1013 {
|
|
1014 #ifdef POP
|
|
1015 if (file && pd != NOTOK)
|
|
1016 (void) mbx_close (file, pd);
|
|
1017 #endif /* POP */
|
|
1018
|
|
1019 if (locked)
|
|
1020 #ifdef MAILGROUP
|
|
1021 {
|
|
1022 setgid(return_gid);
|
|
1023 #endif /* MAILGROUP */
|
|
1024
|
|
1025 if (! lkfclose (in, newmail))
|
|
1026 locked = 0;
|
|
1027 #ifdef MAILGROUP
|
|
1028 setgid(getgid());
|
|
1029 }
|
|
1030 #endif /* MAILGROUP */
|
|
1031 exit (status);
|
|
1032 }
|
|
1033 /* */
|
|
1034
|
|
1035 #ifdef MF
|
|
1036 get_uucp_mail () {
|
|
1037 int child_id;
|
|
1038 char buffer[BUFSIZ];
|
|
1039 struct stat st;
|
|
1040
|
|
1041 (void) sprintf (buffer, "%s/%s", UUCPDIR, UUCPFIL);
|
|
1042 if (stat (buffer, &st) == NOTOK || st.st_size == 0)
|
|
1043 return;
|
|
1044
|
|
1045 switch (child_id = vfork ()) {
|
|
1046 case NOTOK:
|
|
1047 admonish ("fork", "unable to");
|
|
1048 break;
|
|
1049
|
|
1050 case OK:
|
|
1051 execlp (umincproc, r1bindex (umincproc, '/'), NULLCP);
|
|
1052 fprintf (stderr, "unable to exec ");
|
|
1053 perror (umincproc);
|
|
1054 _exit (-1);
|
|
1055
|
|
1056 default:
|
|
1057 (void) pidXwait (child_id, umincproc);
|
|
1058 break;
|
|
1059 }
|
|
1060 }
|
|
1061 #endif /* MF */
|
|
1062
|
|
1063 /* */
|
|
1064
|
|
1065 #ifdef POP
|
|
1066 static int pop_action (s)
|
|
1067 register char *s;
|
|
1068 {
|
|
1069 fprintf (pf, "%s\n", s);
|
|
1070 stop += strlen (s) + 1;
|
|
1071 }
|
|
1072
|
|
1073
|
|
1074 static int pop_pack (s)
|
|
1075 register char *s;
|
|
1076 {
|
|
1077 register int j;
|
|
1078 char buffer[BUFSIZ];
|
|
1079
|
|
1080 (void) sprintf (buffer, "%s\n", s);
|
|
1081 for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
|
|
1082 continue;
|
|
1083 for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
|
|
1084 continue;
|
|
1085 fputs (buffer, pf);
|
|
1086 size += strlen (buffer) + 1;
|
|
1087 }
|
|
1088
|
|
1089 static int map_count () {
|
|
1090 int md;
|
|
1091 char *cp;
|
|
1092 struct drop d;
|
|
1093 struct stat st;
|
|
1094
|
|
1095 if (stat (file, &st) == NOTOK)
|
|
1096 return 0;
|
|
1097 if ((md = open (cp = map_name (file), 0)) == NOTOK
|
|
1098 || map_chk (cp, md, &d, (long) st.st_size, 1)) {
|
|
1099 if (md != NOTOK)
|
|
1100 (void) close (md);
|
|
1101 return 0;
|
|
1102 }
|
|
1103 (void) close (md);
|
|
1104 return (d.d_id);
|
|
1105 }
|
|
1106 #endif /* POP */
|