Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / inc.c,v
1 head    1.24;
2 access;
3 symbols;
4 locks
5         shettich:1.24; strict;
6 comment @ * @;
7
8
9 1.24
10 date    94.04.21.18.22.06;      author jromine; state Exp;
11 branches;
12 next    1.23;
13
14 1.23
15 date    94.04.21.18.20.50;      author jromine; state Exp;
16 branches;
17 next    1.22;
18
19 1.22
20 date    93.09.01.21.41.48;      author jromine; state Exp;
21 branches;
22 next    1.21;
23
24 1.21
25 date    93.08.20.15.50.13;      author jromine; state Exp;
26 branches;
27 next    1.20;
28
29 1.20
30 date    92.12.15.00.20.22;      author jromine; state Exp;
31 branches;
32 next    1.19;
33
34 1.19
35 date    92.11.04.00.43.53;      author jromine; state Exp;
36 branches;
37 next    1.18;
38
39 1.18
40 date    92.10.16.16.51.35;      author jromine; state Exp;
41 branches;
42 next    1.17;
43
44 1.17
45 date    92.10.15.15.47.32;      author jromine; state Exp;
46 branches;
47 next    1.16;
48
49 1.16
50 date    92.05.12.21.56.01;      author jromine; state Exp;
51 branches;
52 next    1.15;
53
54 1.15
55 date    92.02.11.00.37.53;      author jromine; state Exp;
56 branches;
57 next    1.14;
58
59 1.14
60 date    92.02.10.19.20.02;      author jromine; state Exp;
61 branches;
62 next    1.13;
63
64 1.13
65 date    92.02.08.00.06.14;      author jromine; state Exp;
66 branches;
67 next    1.12;
68
69 1.12
70 date    92.02.08.00.04.32;      author jromine; state Exp;
71 branches;
72 next    1.11;
73
74 1.11
75 date    92.02.05.07.26.30;      author jromine; state Exp;
76 branches;
77 next    1.10;
78
79 1.10
80 date    92.02.04.21.59.06;      author jromine; state Exp;
81 branches;
82 next    1.9;
83
84 1.9
85 date    92.02.04.19.25.38;      author jromine; state Exp;
86 branches;
87 next    1.8;
88
89 1.8
90 date    92.02.04.00.03.05;      author jromine; state Exp;
91 branches;
92 next    1.7;
93
94 1.7
95 date    92.02.04.00.02.47;      author jromine; state Exp;
96 branches;
97 next    1.6;
98
99 1.6
100 date    92.01.31.22.49.20;      author jromine; state Exp;
101 branches;
102 next    1.5;
103
104 1.5
105 date    92.01.31.22.11.32;      author jromine; state Exp;
106 branches;
107 next    1.4;
108
109 1.4
110 date    90.04.05.14.57.51;      author sources; state Exp;
111 branches;
112 next    1.3;
113
114 1.3
115 date    90.02.06.13.19.35;      author sources; state Exp;
116 branches;
117 next    1.2;
118
119 1.2
120 date    89.11.17.16.11.58;      author sources; state Exp;
121 branches;
122 next    1.1;
123
124 1.1
125 date    89.11.17.16.10.26;      author sources; state Exp;
126 branches;
127 next    ;
128
129
130 desc
131 @@
132
133
134 1.24
135 log
136 @typo
137 @
138 text
139 @/* inc.c - incorporate messages from a maildrop into a folder */
140 #ifndef lint
141 static char ident[] = "@@(#)$Id: inc.c,v 1.23 1994/04/21 18:20:50 jromine Exp jromine $";
142 #endif  /* lint */
143
144 #ifdef  MAILGROUP
145 /* Revised: Sat Apr 14 17:08:17 PDT 1990 (marvit@@hplabs)
146  *    Added hpux hacks to set and reset gid to be "mail" as needed. The reset
147  *    is necessary so inc'ed mail is the group of the inc'er, rather than
148  *    "mail". We setgid to egid only when [un]locking the mail file. This
149  *    is also a major security precaution which will not be explained here.
150  *
151  * Fri Feb  7 16:04:57 PST 1992         John Romine <bug-mh@@ics.uci.edu>
152  *   NB: I'm not 100% sure that this setgid stuff is secure even now.
153  */
154 #endif
155
156 #include "../h/mh.h"
157 #ifdef  POP
158 #include "../h/dropsbr.h"
159 #endif
160 #ifdef KPOP
161 #include <krb.h>
162 #endif
163 #ifdef HESIOD
164 #include <hesiod.h>
165 #endif
166 #include "../h/formatsbr.h"
167 #include "../h/scansbr.h"
168 #include "../zotnet/tws.h"
169 #include <stdio.h>
170 #include "../zotnet/mts.h"
171 #include <errno.h>
172 #include <signal.h>
173 #include <sys/types.h>
174 #include <sys/stat.h>
175 #ifdef LOCALE
176 #include        <locale.h>
177 #endif
178
179 /* \f */
180
181 #ifndef MF
182 #define MFminc(a)       (a)
183 #else   /* MF */
184 #define MFminc(a)       0
185 #endif  /* MF */
186
187 #ifndef POP
188 #define POPminc(a)      (a)
189 #else   /* POP */
190 #define POPminc(a)      0
191 #endif  /* POP */
192
193 #ifndef RPOP
194 #define RPOPminc(a)     (a)
195 #else   /* RPOP */
196 #define RPOPminc(a)     0
197 #endif  /* RPOP */
198
199 #ifndef APOP
200 #define APOPminc(a)     (a)
201 #else
202 #define APOPminc(a)     0
203 #endif  /* APOP */
204
205 #ifndef TMA
206 #define TMAminc(a)      (a)
207 #else   /* TMA */
208 #define TMAminc(a)      0
209 #endif  /* TMA */
210
211 static struct swit  switches[] = {
212 #define AUDSW   0
213     "audit audit-file", 0,
214 #define NAUDSW  1
215     "noaudit", 0,
216
217 #define CHGSW   2
218     "changecur", 0,
219 #define NCHGSW  3
220     "nochangecur", 0,
221
222 #define DECRSW  4
223     "decrypt", TMAminc (-7),
224 #define NDECRSW 5
225     "nodecrypt", TMAminc (-9),
226
227 #define MSW     6
228     "file name", 0,
229
230 #define FORMSW  7
231     "form formatfile", 0,
232 #define FMTSW   8
233     "format string", 5,
234
235 #define HOSTSW  9
236     "host host", POPminc (-4),
237 #define USERSW  10
238     "user user", POPminc (-4),
239 #define PACKSW  11
240     "pack file", POPminc (-4),
241 #define NPACKSW 12
242     "nopack", POPminc (-6),
243
244 #define APOPSW  13
245     "apop", APOPminc (-4),
246 #define NAPOPSW 14
247     "noapop", APOPminc (-6),
248
249 #define RPOPSW  15
250     "rpop", RPOPminc (-4),
251 #define NRPOPSW 16
252     "norpop", RPOPminc (-6),
253
254 #define SILSW   17
255     "silent", 0,
256 #define NSILSW  18
257     "nosilent", 0,
258
259 #define TRNCSW  19
260     "truncate", 0,
261 #define NTRNCSW 20
262     "notruncate", 0,
263
264 #define UUCPSW  21
265     "uucp", MFminc (-4),
266 #define NUUCPSW 22
267     "nouucp", MFminc (-6),
268
269 #define WIDSW   23
270     "width columns", 0,
271
272 #define HELPSW  24
273     "help", 4,
274
275     NULL, 0
276 };
277
278 /* \f */
279
280 extern int  errno;
281
282 #ifdef  POP
283 int  snoop = 0;
284 extern char response[];
285
286 static  char *file = NULL;
287 static int  size;
288 static long pos;
289 static long start;
290 static long stop;
291
292 static  int   pd = NOTOK;
293 static  FILE *pf = NULL;
294
295 static int      pop_action (), pop_pack ();
296 static int      map_count();
297 #endif  /* POP */
298
299 /* \f * /
300
301 /* ARGSUSED */
302
303 #ifdef MAILGROUP        /* For setting and returning to "mail" gid */
304 static int return_gid;
305 #endif  /* MAILGROUP */
306
307 main (argc, argv)
308 int     argc;
309 char   *argv[];
310 {
311     int     chgflag = 1,
312             trnflag = 1,
313             decflag = 1,
314             noisy = 1,
315             width = 0,
316 #ifdef  MF
317             uucp = 1,
318 #endif  /* MF */
319             locked = 0,
320 #ifdef  POP
321             nmsgs,
322             nbytes,
323             p = 0,
324 #endif  /* POP */
325             rpop = 1,
326             i,
327             hghnum,
328             msgnum;
329     char   *cp,
330            *maildir,
331            *folder = NULL,
332            *form = NULL,
333            *format = NULL,
334            *audfile = NULL,
335            *from = NULL,
336            *host = NULL,
337 #ifdef  POP
338            *pass = NULL,
339 #endif  /* POP */
340            *newmail,
341             buf[100],
342           **ap,
343           **argp,
344            *nfs,
345            *arguments[MAXARGS];
346     char *user = NULL;
347     struct msgs *mp;
348     struct stat st,
349                 s1;
350     FILE *in, *aud = NULL;
351 #ifdef  MHE
352     FILE *mhe = NULL;
353 #endif  /* MHE */
354 #ifdef HESIOD
355     struct hes_postoffice *po;
356     char *tmphost;
357 #endif
358
359 #ifdef LOCALE
360         setlocale(LC_ALL, "");
361 #endif
362     invo_name = r1bindex (argv[0], '/');
363     mts_init (invo_name);
364
365 #ifdef  POP
366 #ifdef HESIOD
367     /*
368      * Scheme is:
369      *        use MAILHOST environment variable if present,
370      *  else try Hesiod.
371      *  If that fails, use the default (if any)
372      *  provided by mtstailor in mts_init()
373      */
374     if ((tmphost = getenv("MAILHOST")) != NULL)
375         pophost = tmphost;
376     else if ((po = hes_getmailhost(getusr())) != NULL &&
377             strcmp(po->po_type, "POP") == 0)
378         pophost = po->po_host;
379 #endif /* HESIOD */
380     if (pophost && *pophost)
381         host = pophost;
382
383     if ((cp = getenv ("MHPOPDEBUG")) && *cp)
384         snoop++;
385 #endif
386
387     if ((cp = m_find (invo_name)) != NULL) {
388         ap = brkstring (cp = getcpy (cp), " ", "\n");
389         ap = copyip (ap, arguments);
390     }
391     else
392         ap = arguments;
393     (void) copyip (argv + 1, ap);
394     argp = arguments;
395
396 /* \f */
397
398     while (cp = *argp++) {
399         if (*cp == '-')
400             switch (smatch (++cp, switches)) {
401                 case AMBIGSW: 
402                     ambigsw (cp, switches);
403                     done (1);
404                 case UNKWNSW: 
405                     adios (NULLCP, "-%s unknown", cp);
406                 case HELPSW: 
407                     (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
408                     help (buf, switches);
409                     done (1);
410
411                 case AUDSW: 
412                     if (!(cp = *argp++) || *cp == '-')
413                         adios (NULLCP, "missing argument to %s", argp[-2]);
414                     audfile = getcpy (m_maildir (cp));
415                     continue;
416                 case NAUDSW: 
417                     audfile = NULL;
418                     continue;
419
420                 case CHGSW: 
421                     chgflag++;
422                     continue;
423                 case NCHGSW: 
424                     chgflag = 0;
425                     continue;
426
427                 case TRNCSW: 
428                     trnflag++;
429                     continue;
430                 case MSW: 
431                     if (!(cp = *argp++) || *cp == '-')
432                         adios (NULLCP, "missing argument to %s", argp[-2]);
433                     from = path (cp, TFILE);/* fall */
434                 case NTRNCSW: 
435                     trnflag = 0;
436                     continue;
437
438                 case SILSW: 
439                     noisy = 0;
440                     continue;
441                 case NSILSW: 
442                     noisy++;
443                     continue;
444
445                 case FORMSW: 
446                     if (!(form = *argp++) || *form == '-')
447                         adios (NULLCP, "missing argument to %s", argp[-2]);
448                     format = NULL;
449                     continue;
450                 case FMTSW: 
451                     if (!(format = *argp++) || *format == '-')
452                         adios (NULLCP, "missing argument to %s", argp[-2]);
453                     form = NULL;
454                     continue;
455
456                 case WIDSW: 
457                     if (!(cp = *argp++) || *cp == '-')
458                         adios (NULLCP, "missing argument to %s", argp[-2]);
459                     width = atoi (cp);
460                     continue;
461
462                 case DECRSW:
463                     decflag++;
464                     continue;
465                 case NDECRSW:
466                     decflag = 0;
467                     continue;
468
469                 case UUCPSW: 
470 #ifdef  MF
471                     uucp++;
472 #endif  /* MF */
473                     continue;
474                 case NUUCPSW: 
475 #ifdef  MF
476                     uucp = 0;
477 #endif  /* MF */
478                     continue;
479
480                 case HOSTSW:
481                     if (!(host = *argp++) || *host == '-')
482                         adios (NULLCP, "missing argument to %s", argp[-2]);
483                     continue;
484                 case USERSW:
485                     if (!(user = *argp++) || *user == '-')
486                         adios (NULLCP, "missing argument to %s", argp[-2]);
487                     continue;
488                 case PACKSW:
489 #ifndef POP
490                     if (!(cp = *argp++) || *cp == '-')
491                         adios (NULLCP, "missing argument to %s", argp[-2]);
492 #else   /* POP */
493                     if (!(file = *argp++) || *file == '-')
494                         adios (NULLCP, "missing argument to %s", argp[-2]);
495 #endif  /* POP */
496                     continue;
497                 case NPACKSW:
498 #ifdef  POP
499                     file = NULLCP;
500 #endif  /* POP */
501                     continue;
502                 case APOPSW:
503                     rpop = -1;
504                     continue;
505                 case RPOPSW:
506                     rpop = 1;
507                     continue;
508                 case NAPOPSW:
509                 case NRPOPSW:
510                     rpop = 0;
511                     continue;
512             }
513         if (*cp == '+' || *cp == '@@') {
514             if (folder)
515                 adios (NULLCP, "only one folder at a time!");
516             else
517                 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
518         }
519         else
520             adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
521     }
522
523 /* \f */
524
525 #ifdef MAILGROUP
526     return_gid = getegid();     /* Save effective gid, assuming we'll use it */
527     setgid(getgid());           /* Turn off extraordinary privileges */
528 #endif  /* MAILGROUP */
529
530 #ifdef  POP
531     if (host && !*host)
532         host = NULL;
533     if (from || !host || rpop <= 0)
534         (void) setuid (getuid ());
535 #endif /* POP */
536     if (from) {
537         newmail = from;
538 #ifdef  POP
539         host = NULL;
540 #endif  /* POP */
541         if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
542             adios (NULLCP, "no mail to incorporate");
543     }
544 #ifdef  POP
545     else if (host) {
546         if (user == NULL)
547             user = getusr ();
548         if (rpop > 0)
549             pass = getusr ();
550         else
551             ruserpass (host, &user, &pass);
552
553         if (pop_init (host, user, pass, snoop, rpop) == NOTOK
554                 || pop_stat (&nmsgs, &nbytes) == NOTOK)
555             adios (NULLCP, "%s", response);
556         if (rpop > 0)
557             (void) setuid (getuid ());
558         if (nmsgs == 0) {
559             (void) pop_quit ();
560             adios (NULLCP, "no mail to incorporate");
561         }
562     }
563 #endif  /* POP */
564     else {
565         if (((newmail = getenv ("MAILDROP")) && *newmail)
566                 || ((newmail = m_find ("maildrop")) && *newmail))
567             newmail = m_mailpath (newmail);
568         else {
569 #ifdef  MF
570             if (uucp && umincproc && *umincproc)
571                 get_uucp_mail ();
572 #endif  /* MF */
573             newmail = concat (MAILDIR, "/", MAILFIL, NULLCP);
574         }
575         if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
576             adios (NULLCP, "no mail to incorporate");
577     }
578
579 #ifdef  POP
580     if (host && file)
581         goto go_to_it;
582 #endif  /* POP */
583     if (!m_find ("path"))
584         free (path ("./", TFOLDER));
585     if (!folder && !(folder = m_find (inbox)))
586         folder = defalt;
587     maildir = m_maildir (folder);
588
589     if (stat (maildir, &st) == NOTOK) {
590         if (errno != ENOENT)
591             adios (maildir, "error on folder");
592         cp = concat ("Create folder \"", maildir, "\"? ", NULLCP);
593         if (noisy && !getanswer (cp))
594             done (1);
595         free (cp);
596         if (!makedir (maildir))
597             adios (NULLCP, "unable to create folder %s", maildir);
598     }
599
600     if (chdir (maildir) == NOTOK)
601         adios (maildir, "unable to change directory to");
602     if (!(mp = m_gmsg (folder)))
603         adios (NULLCP, "unable to read folder %s", folder);
604
605 /* \f */
606
607 #ifdef  POP
608 go_to_it: ;
609     if (host == NULL)
610 #endif  /* POP */
611     if (access (newmail, 02) == NOTOK) {
612         trnflag = 0;
613         if ((in = fopen (newmail, "r")) == NULL)
614             adios (newmail, "unable to read");
615     }
616     else {
617         locked++;
618         if (trnflag) {
619             (void) signal (SIGHUP, SIG_IGN);
620             (void) signal (SIGINT, SIG_IGN);
621             (void) signal (SIGQUIT, SIG_IGN);
622             (void) signal (SIGTERM, SIG_IGN);
623         }
624
625 #ifdef MAILGROUP
626         setgid(return_gid);     /* Reset gid to lock mail file */
627 #endif  /* MAILGROUP */
628         if ((in = lkfopen (newmail, "r")) == NULL)
629             adios (NULLCP, "unable to lock and fopen %s", newmail);
630 #ifdef MAILGROUP
631         setgid(getgid());       /* Return us to normal privileges */
632 #endif  /* MAILGROUP */
633         (void) fstat (fileno(in), &s1);
634     }
635
636 #ifdef MAILGROUP
637         setgid(getgid());       /* Return us to normal privileges */
638 #endif  /* MAILGROUP */
639
640     if (audfile) {
641         if ((i = stat (audfile, &st)) == NOTOK)
642             advise (NULLCP, "Creating Receive-Audit: %s", audfile);
643         if ((aud = fopen (audfile, "a")) == NULL)
644             adios (audfile, "unable to append to");
645         else
646             if (i == NOTOK)
647                 (void) chmod (audfile, m_gmprot ());
648 #ifndef POP
649         fprintf (aud, from ? "<<inc>> %s  -ms %s\n" : "<<inc>> %s\n",
650                 dtimenow (), from);
651 #else   /* POP */
652         fprintf (aud, from ? "<<inc>> %s -ms %s\n"
653                         : host ? "<<inc>> %s -host %s -user %s%s\n"
654                         : "<<inc>> %s\n",
655                  dtimenow (), from ? from : host, user,
656                  rpop < 0 ? " -apop" : rpop > 0 ? " -rpop" : "");
657 #endif  /* POP */
658     }
659
660 #ifdef  MHE
661     if (m_find ("mhe")) {
662         cp = concat (maildir, "/++", NULLCP);
663         i = stat (cp, &st);
664         if ((mhe = fopen (cp, "a")) == NULL)
665             admonish (cp, "unable to append to");
666         else
667             if (i == NOTOK)
668                 (void) chmod (cp, m_gmprot ());
669         free (cp);
670     }
671 #endif  /* MHE */
672
673     nfs = new_fs (form, format, FORMAT);
674
675     if (noisy) {
676         printf ("Incorporating new mail into %s...\n\n", folder);
677         (void) fflush (stdout);
678     }
679
680 /* \f */
681
682 #ifdef  POP
683     if (host) {
684         if (file) {
685             file = path (file, TFILE);
686             if (stat (file, &st) == NOTOK) {
687                 if (errno != ENOENT)
688                     adios (file, "error on file");
689                 cp = concat ("Create file \"", file, "\"? ", NULLCP);
690                 if (noisy && !getanswer (cp))
691                     done (1);
692                 free (cp);
693             }
694             msgnum = map_count ();
695             if ((pd = mbx_open (file, getuid (), getgid (), m_gmprot ()))
696                     == NOTOK)
697                 adios (file, "unable to open");
698             if ((pf = fdopen (pd, "w+")) == NULL)
699                 adios (NULLCP, "unable to fdopen %s", file);
700         }
701         else {
702             hghnum = msgnum = mp -> hghmsg;
703             if ((mp = m_remsg (mp, 0, mp -> hghmsg + nmsgs)) == NULL)
704                 adios (NULLCP, "unable to allocate folder storage");
705         }
706
707         for (i = 1; i <= nmsgs; i++) {
708             msgnum++;
709             if (file) {
710                 (void) fseek (pf, 0L, 1);
711                 pos = ftell (pf);
712                 size = 0;
713                 (void) fwrite (mmdlm1, 1, strlen (mmdlm1), pf);
714                 start = ftell (pf);
715
716                 if (pop_retr (i, pop_pack) == NOTOK)
717                     adios (NULLCP, "%s", response);
718
719                 (void) fseek (pf, 0L, 1);
720                 stop = ftell (pf);
721                 if (fflush (pf))
722                     adios (file, "write error on");
723                 (void) fseek (pf, start, 0);
724             }
725             else {
726                 cp = getcpy (m_name (msgnum));
727                 if ((pf = fopen (cp, "w+")) == NULL)
728                     adios (cp, "unable to write");
729                 (void) chmod (cp, m_gmprot ());
730                 start = stop = 0L;
731
732                 if (pop_retr (i, pop_action) == NOTOK)
733                     adios (NULLCP, "%s", response);
734
735                 if (fflush (pf))
736                     adios (cp, "write error on");
737                 (void) fseek (pf, 0L, 0);
738             }
739             switch (p = scan (pf, msgnum, 0, nfs, width,
740                         file ? 0 : msgnum == mp -> hghmsg + 1 && chgflag,
741                         1,      /* check UNSEEN? */
742                         0, 0, stop - start, noisy)) {
743                 case SCNEOF: 
744                     printf ("%*d  empty\n", DMAXFOLDER, msgnum);
745                     break;
746
747                 case SCNFAT:
748                     trnflag = 0;
749                     noisy++;
750                     /* advise (cp, "unable to read"); already advised */
751                     /* fall thru */
752
753                 case SCNERR:
754                 case SCNNUM: 
755                     break;
756
757                 case SCNMSG: 
758                 case SCNENC:
759                 default: 
760                     if (aud)
761                         fputs (scanl, aud);
762 #ifdef  MHE
763                     if (mhe)
764                         fputs (scanl, mhe);
765 #endif  /* MHE */
766                     if (noisy)
767                         (void) fflush (stdout);
768                     if (!file) {
769                         mp -> msgstats[msgnum] = EXISTS;
770 #ifdef  TMA
771                         if (p == SCNENC) {
772                             if (mp -> lowsel == 0 || msgnum < mp -> lowsel)
773                                 mp -> lowsel = msgnum;
774                             if (mp -> hghsel == 0 || msgnum > mp -> hghsel)
775                                 mp -> hghsel = msgnum;
776                             mp -> numsel++;
777                             mp -> msgstats[msgnum] |= SELECTED;
778                         }
779 #endif  /* TMA */
780                         mp -> msgstats[msgnum] |= UNSEEN;
781                         mp -> msgflags |= SEQMOD;
782                     }
783                     break;
784                 }
785             if (file) {
786                 (void) fseek (pf, stop, 0);
787                 (void) fwrite (mmdlm2, 1, strlen (mmdlm2), pf);
788                 if (fflush (pf) || ferror (pf)) {
789                     int e = errno;
790                     (void) pop_quit ();
791                     errno = e;
792                     adios (file, "write error on");
793                 }
794                 (void) map_write (file, pd, 0, 0L, start, stop, pos, size,
795                             noisy);
796             }
797             else {
798                 if (ferror(pf) || fclose (pf)) {
799                     int e = errno;
800                     (void) unlink (cp);
801                     (void) pop_quit ();
802                     errno = e;
803                     adios (cp, "write error on");
804                 }
805                 free (cp);
806             }
807
808             if (trnflag && pop_dele (i) == NOTOK)
809                 adios (NULLCP, "%s", response);
810         }
811         if (pop_quit () == NOTOK)
812             adios (NULLCP, "%s", response);
813         if (file) {
814             (void) mbx_close (file, pd);
815             pd = NOTOK;
816         }
817     }
818     else {
819 #endif  /* POP */
820
821 /* \f */
822
823     m_unknown (in);             /* the MAGIC invocation... */
824     hghnum = msgnum = mp -> hghmsg;
825     for (i = 0;;) {
826         if (msgnum >= mp -> hghoff)
827             if ((mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER)) == NULL) {
828                 advise (NULLCP, "unable to allocate folder storage");
829                 i = NOTOK;
830                 break;
831             }
832
833         switch (i = scan (in, msgnum + 1, msgnum + 1, nfs, width,
834                     msgnum == hghnum && chgflag,
835                     1,  /* check UNSEEN? */
836                     0, 0, 0L, noisy)) {
837             case SCNFAT:
838             case SCNEOF: 
839                 break;
840
841             case SCNERR:
842                 if (aud)
843                     fputs ("inc aborted!\n", aud);
844                 advise (NULLCP, "aborted!");    /* doesn't clean up locks! */
845                 break;
846
847             case SCNNUM: 
848                 advise (NULLCP,
849                         "more than %d messages in folder %s, %s not zero'd",
850                         MAXFOLDER, folder, newmail);
851                 break;
852
853             default: 
854                 advise (NULLCP, "scan() botch (%d)", i);
855                 break;
856
857             case SCNMSG:
858             case SCNENC:
859                 if (aud)
860                     fputs (scanl, aud);
861 #ifdef  MHE
862                 if (mhe)
863                     fputs (scanl, mhe);
864 #endif  /* MHE */
865                 if (noisy)
866                     (void) fflush (stdout);
867
868                 msgnum++, mp -> hghmsg++;
869                 mp -> msgstats[msgnum] = EXISTS;
870 #ifdef  TMA
871                 if (i == SCNENC) {
872                     if (mp -> lowsel == 0 || mp -> lowsel > msgnum)
873                         mp -> lowsel = msgnum;
874                     if (mp -> hghsel == 0 || mp -> hghsel < msgnum)
875                         mp -> hghsel = msgnum;
876                     mp -> numsel++;
877                     mp -> msgstats[msgnum] |= SELECTED;
878                 }
879 #endif  /* TMA */
880                 mp -> msgstats[msgnum] |= UNSEEN;
881                 mp -> msgflags |= SEQMOD;
882                 continue;
883         }
884         break;
885     }
886 #ifdef  POP
887     }
888 #endif  /* POP */
889 #ifndef POP
890     if (i < 0) {                /* error } */
891 #else
892     if (p < 0) {                /* error */
893 #endif
894         if (locked)
895 #ifdef MAILGROUP
896         {
897           setgid(return_gid);   /* Be sure we can unlock mail file */
898 #endif  /* MAILGROUP */
899
900             (void) lkfclose (in, newmail);
901 #ifdef MAILGROUP
902             setgid(getgid());   /* And then return us to normal privileges */
903          }
904 #endif  /* MAILGROUP */
905         else
906             (void) fclose (in);
907         adios (NULLCP, "failed");
908     }
909
910     if (aud)
911         (void) fclose (aud);
912 #ifdef  MHE
913     if (mhe)
914         (void) fclose (mhe);
915 #endif  /* MHE */
916     if (noisy)
917         (void) fflush (stdout);
918 #ifdef  POP
919     if (host && file)
920         done (0);
921 #endif  /* POP */
922
923 /* \f */
924
925 #ifdef  POP
926     if (host == NULL)
927 #endif  /* POP */
928     if (trnflag) {
929         if (stat (newmail, &st) != NOTOK && s1.st_mtime != st.st_mtime)
930             advise (NULLCP, "new messages have arrived!\007");
931         else {
932             if ((i = creat (newmail, 0600)) != NOTOK)
933                 (void) close (i);
934             else
935                 admonish (newmail, "error zero'ing");
936             (void) unlink (map_name (newmail));
937         }
938     }
939     else
940         if (noisy)
941             printf ("%s not zero'd\n", newmail);
942
943     if (msgnum == hghnum)
944         admonish (NULLCP, "no messages incorporated");
945     else {
946         m_replace (pfolder, folder);
947         if (chgflag)
948             mp -> curmsg = hghnum + 1;
949         mp -> hghmsg = msgnum;
950         if (mp -> lowmsg == 0)
951             mp -> lowmsg = 1;
952         if (chgflag)            /* sigh... */
953             m_setcur (mp, mp -> curmsg);
954     }
955
956 #ifdef  POP
957     if (host == NULL)
958 #endif  /* POP */
959     if (locked)
960 #ifdef MAILGROUP
961     {
962       setgid(return_gid);       /* Be sure we can unlock mail file */
963 #endif  /* MAILGROUP */
964
965         (void) lkfclose (in, newmail);
966 #ifdef MAILGROUP
967         setgid(getgid());       /* And then return us to normal privileges */
968      }
969 #endif  /* MAILGROUP */
970     else
971         (void) fclose (in);
972
973     m_setvis (mp, 0);
974     m_sync (mp);
975     m_update ();
976
977 #ifdef  TMA
978     if (decflag && mp -> numsel > 0) {
979         if (noisy) {
980             printf ("\nIncorporating encrypted mail into %s...\n\n", folder);
981             (void) fflush (stdout);
982         }
983
984         tmastart (0);
985         for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
986             if (mp -> msgstats[msgnum] & SELECTED && decipher (msgnum) == OK) {
987                 if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) {
988                     admonish (cp, "unable to open message");
989                     free (cp);
990                     continue;
991                 }
992                 switch (scan (in, msgnum, 0, nfs, width,
993                         msgnum == mp -> curmsg,
994                         1,      /* check UNSEEN? */
995                         0, 0,
996                         fstat (fileno (in), &st) != NOTOK ? (long) st.st_size
997                             : 0L,
998                         noisy)) {
999                     case SCNEOF: 
1000                         printf ("%*d  empty\n", DMAXFOLDER, msgnum);
1001                         break;
1002
1003                     default: 
1004                         break;
1005                 }
1006                 (void) fclose (in);
1007                 free (cp);
1008             }
1009         tmastop ();
1010
1011         if (noisy)
1012             (void) fflush (stdout);
1013     }
1014 #endif  /* TMA */
1015
1016     done (0);
1017 }
1018
1019 /* \f */
1020
1021 #ifdef  POP
1022 void    done (status)
1023 int     status;
1024 {
1025     if (file && pd != NOTOK)
1026         (void) mbx_close (file, pd);
1027
1028     exit (status);
1029 }
1030 #endif  /* POP */
1031 /* \f */
1032
1033 #ifdef MF
1034 get_uucp_mail () {
1035     int     child_id;
1036     char    buffer[BUFSIZ];
1037     struct stat st;
1038
1039     (void) sprintf (buffer, "%s/%s", UUCPDIR, UUCPFIL);
1040     if (stat (buffer, &st) == NOTOK || st.st_size == 0)
1041         return;
1042
1043     switch (child_id = vfork ()) {
1044         case NOTOK: 
1045             admonish ("fork", "unable to");
1046             break;
1047
1048         case OK: 
1049             execlp (umincproc, r1bindex (umincproc, '/'), NULLCP);
1050             fprintf (stderr, "unable to exec ");
1051             perror (umincproc);
1052             _exit (-1);
1053
1054         default: 
1055             (void) pidXwait (child_id, umincproc);
1056             break;
1057     }
1058 }
1059 #endif  /* MF */
1060
1061 /* \f */
1062
1063 #ifdef  POP
1064 static int  pop_action (s)
1065 register char *s;
1066 {
1067     fprintf (pf, "%s\n", s);
1068     stop += strlen (s) + 1;
1069 }
1070
1071
1072 static int  pop_pack (s)
1073 register char *s;
1074 {
1075     register int    j;
1076     char    buffer[BUFSIZ];
1077
1078     (void) sprintf (buffer, "%s\n", s);
1079     for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
1080         continue;
1081     for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
1082         continue;
1083     fputs (buffer, pf);
1084     size += strlen (buffer) + 1;
1085 }
1086
1087 static int  map_count () {
1088     int     md;
1089     char   *cp;
1090     struct drop d;
1091     struct stat st;
1092
1093     if (stat (file, &st) == NOTOK)
1094         return 0;
1095     if ((md = open (cp = map_name (file), 0)) == NOTOK
1096             || map_chk (cp, md, &d, (long) st.st_size, 1)) {
1097         if (md != NOTOK)
1098             (void) close (md);
1099         return 0;
1100     }
1101     (void) close (md);
1102     return (d.d_id);
1103 }
1104 #endif  /* POP */
1105 @
1106
1107
1108 1.23
1109 log
1110 @update for scansbr.c -- overload {folder}.c_flags with hdrflg
1111 @
1112 text
1113 @d3 1
1114 a3 1
1115 static char ident[] = "@@(#)$Id: inc.c,v 1.22 1993/09/01 21:41:48 jromine Exp jromine $";
1116 d698 1
1117 a698 1
1118                     0, 0 0L, noisy)) {
1119 @
1120
1121
1122 1.22
1123 log
1124 @set pophost before parsing args, so user can override
1125 @
1126 text
1127 @d3 1
1128 a3 1
1129 static char ident[] = "@@(#)$Id: inc.c,v 1.21 1993/08/20 15:50:13 jromine Exp jromine $";
1130 d604 1
1131 a604 1
1132                         0, stop - start, noisy)) {
1133 d698 1
1134 a698 3
1135                     0,
1136                     0L,
1137                     noisy)) {
1138 d857 1
1139 a857 1
1140                         0,
1141 @
1142
1143
1144 1.21
1145 log
1146 @better user defaulting on rpop/apop
1147 need to check this against older releases
1148 @
1149 text
1150 @d3 1
1151 a3 1
1152 static char ident[] = "@@(#)$Id: inc.c,v 1.20 1992/12/15 00:20:22 jromine Exp jromine $";
1153 d228 17
1154 a392 20
1155 #ifdef HESIOD
1156     /*
1157      * Scheme is:
1158      *        use MAILHOST environment variable if present,
1159      *  else try Hesiod.
1160      *  If that fails, use the default (if any)
1161      *  provided by mtstailor in mts_init()
1162      */
1163     if (pophost == NULL || pophost[0] == '\0')
1164       {
1165         if ((tmphost = getenv("MAILHOST")) != NULL)
1166           pophost = tmphost;
1167         else if ((po = hes_getmailhost(getusr())) != NULL &&
1168                  strcmp(po->po_type, "POP") == 0)
1169           pophost = po->po_host;
1170       }
1171 #endif /* HESIOD */
1172     if (pophost && *pophost)
1173         host = pophost;
1174
1175 @
1176
1177
1178 1.20
1179 log
1180 @endif sugar
1181 @
1182 text
1183 @d3 1
1184 a3 1
1185 static char ident[] = "@@(#)$Id: inc.c,v 1.19 1992/11/04 00:43:53 jromine Exp jromine $";
1186 d411 3
1187 a413 3
1188         if (rpop) {
1189             if (user == NULL)
1190                 user = getusr ();
1191 a414 1
1192         }
1193 d421 1
1194 a421 1
1195         if (rpop)
1196 @
1197
1198
1199 1.19
1200 log
1201 @LOCALE
1202 @
1203 text
1204 @d3 2
1205 a4 2
1206 static char ident[] = "@@(#)$Id: inc.c,v 1.18 1992/10/16 16:51:35 jromine Exp jromine $";
1207 #endif  lint
1208 d45 1
1209 a45 1
1210 #else   MF
1211 d47 1
1212 a47 1
1213 #endif  MF
1214 d51 1
1215 a51 1
1216 #else   POP
1217 d53 1
1218 a53 1
1219 #endif  POP
1220 d57 1
1221 a57 1
1222 #else   RPOP
1223 d59 1
1224 a59 1
1225 #endif  RPOP
1226 d69 1
1227 a69 1
1228 #else   TMA
1229 d71 1
1230 a71 1
1231 #endif  TMA
1232 d159 1
1233 a159 1
1234 #endif  POP
1235 d180 1
1236 a180 1
1237 #endif  MF
1238 d186 1
1239 a186 1
1240 #endif  POP
1241 d201 1
1242 a201 1
1243 #endif  POP
1244 d215 1
1245 a215 1
1246 #endif  MHE
1247 d317 1
1248 a317 1
1249 #endif  MF
1250 d322 1
1251 a322 1
1252 #endif  MF
1253 d337 1
1254 a337 1
1255 #else   POP
1256 d340 1
1257 a340 1
1258 #endif  POP
1259 d345 1
1260 a345 1
1261 #endif  POP
1262 d405 1
1263 a405 1
1264 #endif  POP
1265 d429 1
1266 a429 1
1267 #endif  POP
1268 d438 1
1269 a438 1
1270 #endif  MF
1271 d448 1
1272 a448 1
1273 #endif  POP
1274 d476 1
1275 a476 1
1276 #endif  POP
1277 d517 1
1278 a517 1
1279 #else   POP
1280 d523 1
1281 a523 1
1282 #endif  POP
1283 d537 1
1284 a537 1
1285 #endif  MHE
1286 d631 1
1287 a631 1
1288 #endif  MHE
1289 d645 1
1290 a645 1
1291 #endif  TMA
1292 d685 1
1293 a685 1
1294 #endif  POP
1295 d732 1
1296 a732 1
1297 #endif  MHE
1298 d747 1
1299 a747 1
1300 #endif  TMA
1301 d756 1
1302 a756 1
1303 #endif  POP
1304 d783 1
1305 a783 1
1306 #endif  MHE
1307 d789 1
1308 a789 1
1309 #endif  POP
1310 d795 1
1311 a795 1
1312 #endif  POP
1313 d826 1
1314 a826 1
1315 #endif  POP
1316 d882 1
1317 a882 1
1318 #endif  TMA
1319 d898 1
1320 a898 1
1321 #endif  POP
1322 d927 1
1323 a927 1
1324 #endif  MF
1325 d972 1
1326 a972 1
1327 #endif  POP
1328 @
1329
1330
1331 1.18
1332 log
1333 @endif fixup
1334 @
1335 text
1336 @d3 1
1337 a3 1
1338 static char ident[] = "@@(#)$Id: inc.c,v 1.17 1992/10/15 15:47:32 jromine Exp jromine $";
1339 d37 3
1340 d221 3
1341 @
1342
1343
1344 1.17
1345 log
1346 @security fix.
1347 @
1348 text
1349 @d3 1
1350 a3 1
1351 static char ident[] = "@@(#)$Id: inc.c,v 1.16 1992/05/12 21:56:01 jromine Exp jromine $";
1352 a16 1
1353 static char *RCSid = "$Header: /usr/src/bs/mh-develop/mh-6.7-new/uip/RCS/inc.c,v 1.16 1992/05/12 21:56:01 jromine Exp jromine $";
1354 d62 1
1355 a62 1
1356 #endif
1357 @
1358
1359
1360 1.16
1361 log
1362 @fix from mtr
1363 @
1364 text
1365 @d3 1
1366 a3 1
1367 static char ident[] = "@@(#)$Id: inc.c,v 1.15 1992/02/11 00:37:53 jromine Exp jromine $";
1368 d17 1
1369 a17 1
1370 static char *RCSid = "$Header: /usr/src/bs/mh-develop/mh-6.7-new/uip/RCS/inc.c,v 1.15 1992/02/11 00:37:53 jromine Exp jromine $";
1371 d206 1
1372 a206 1
1373     char *user = getusr ();
1374 d383 1
1375 a383 1
1376         else if ((po = hes_getmailhost(user)) != NULL &&
1377 d406 5
1378 a410 4
1379         if (user == NULL)
1380             user = getusr ();
1381         if (rpop > 0)
1382             pass = user;
1383 @
1384
1385
1386 1.15
1387 log
1388 @typo
1389 @
1390 text
1391 @d3 1
1392 a3 1
1393 static char ident[] = "@@(#)$Id: inc.c,v 1.14 1992/02/10 19:20:02 jromine Exp $";
1394 d17 1
1395 a17 1
1396 static char *RCSid = "$Header: /usr/src/bs/mh-develop/mh-6.7-new/uip/RCS/inc.c,v 1.14 1992/02/10 19:20:02 jromine Exp $";
1397 d344 1
1398 @
1399
1400
1401 1.14
1402 log
1403 @changes to trap errors from m_getfld()
1404 @
1405 text
1406 @d3 1
1407 a3 1
1408 static char ident[] = "@@(#)$Id: inc.c,v 1.13 1992/02/08 00:06:14 jromine Exp jromine $";
1409 d17 1
1410 a17 1
1411 static char *RCSid = "$Header: /usr/rand/src/bin/mh/uip/RCS/inc.c,v 1.3 91/02/05 14:19:24 pearlman Exp $";
1412 d756 1
1413 a756 1
1414     #ifdef MAILGROUP
1415 d759 1
1416 a759 1
1417     #endif      /* MAILGROUP */
1418 d762 1
1419 a762 1
1420     #ifdef MAILGROUP
1421 d765 1
1422 a765 1
1423     #endif      /* MAILGROUP */
1424 @
1425
1426
1427 1.13
1428 log
1429 @comment
1430 @
1431 text
1432 @d3 1
1433 a3 1
1434 static char ident[] = "@@(#)$Id: inc.c,v 1.12 1992/02/08 00:04:32 jromine Exp jromine $";
1435 d17 1
1436 d183 1
1437 a183 1
1438             p,
1439 d606 7
1440 a612 1
1441                 case SCNERR: 
1442 d684 1
1443 a684 1
1444     for (;;) {
1445 d686 5
1446 a690 2
1447             if ((mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER)) == NULL)
1448                 adios (NULLCP, "unable to allocate folder storage");
1449 d698 1
1450 d702 1
1451 a702 1
1452             case SCNERR: 
1453 d705 2
1454 a706 1
1455                 adios (NULLCP, "aborted!");
1456 d709 2
1457 a710 1
1458                 adios (NULLCP, "more than %d messages in folder %s, %s not zero'd",
1459 d712 1
1460 d715 2
1461 a716 1
1462                 adios (NULLCP, "scan() botch (%d)", i);
1463 d750 20
1464 @
1465
1466
1467 1.12
1468 log
1469 @add setgid's to MAILGROUP option
1470 @
1471 text
1472 @d3 1
1473 a3 1
1474 static char ident[] = "@@(#)$Id: inc.c,v 1.11 1992/02/05 07:26:30 jromine Exp jromine $";
1475 d12 3
1476 @
1477
1478
1479 1.11
1480 log
1481 @put unseen sequence in mh-format
1482 @
1483 text
1484 @d3 1
1485 a3 1
1486 static char ident[] = "@@(#)$Id: inc.c,v 1.10 1992/02/04 21:59:06 jromine Exp jromine $";
1487 d6 9
1488 d159 4
1489 d360 5
1490 d479 4
1491 d485 3
1492 d491 4
1493 d783 10
1494 a792 1
1495         (void) lkfclose (in, newmail);
1496 @
1497
1498
1499 1.10
1500 log
1501 @contributed patch
1502 @
1503 text
1504 @d3 1
1505 a3 1
1506 static char ident[] = "@@(#)$Id: inc.c,v 1.9 1992/02/04 19:25:38 jromine Exp jromine $";
1507 d567 1
1508 d652 1
1509 d779 1
1510 @
1511
1512
1513 1.9
1514 log
1515 @typo
1516 @
1517 text
1518 @d3 1
1519 a3 1
1520 static char ident[] = "@@(#)$Id: inc.c,v 1.8 1992/02/04 00:03:05 jromine Exp jromine $";
1521 d46 6
1522 d91 6
1523 a96 1
1524 #define RPOPSW  13
1525 d98 1
1526 a98 1
1527 #define NRPOPSW 14
1528 d101 1
1529 a101 1
1530 #define SILSW   15
1531 d103 1
1532 a103 1
1533 #define NSILSW  16
1534 d106 1
1535 a106 1
1536 #define TRNCSW  17
1537 d108 1
1538 a108 1
1539 #define NTRNCSW 18
1540 d111 1
1541 a111 1
1542 #define UUCPSW  19
1543 d113 1
1544 a113 1
1545 #define NUUCPSW 20
1546 d116 1
1547 a116 1
1548 #define WIDSW   21
1549 d119 1
1550 a119 1
1551 #define HELPSW  22
1552 d325 2
1553 d328 1
1554 a328 1
1555                     rpop++;
1556 d330 1
1557 d370 1
1558 a370 1
1559     if (from || !host || !rpop)
1560 d383 3
1561 a385 1
1562         if (rpop) {
1563 a386 1
1564         }
1565 d481 2
1566 a482 1
1567                 dtimenow (), from ? from : host, user, rpop ? " -rpop" : "");
1568 @
1569
1570
1571 1.8
1572 log
1573 @contributed patch
1574 @
1575 text
1576 @d3 1
1577 a3 1
1578 static char ident[] = "@@(#)$Id: inc.c,v 1.7 1992/02/04 00:02:47 jromine Exp jromine $";
1579 d601 1
1580 a601 1
1581                 if (ferror(pf) || fclose (pf))
1582 d607 1
1583 @
1584
1585
1586 1.7
1587 log
1588 @try to catch read errors when POP
1589 @
1590 text
1591 @d3 1
1592 a3 1
1593 static char ident[] = "@@(#)$Id: inc.c,v 1.6 1992/01/31 22:49:20 jromine Exp jromine $";
1594 d407 1
1595 a407 1
1596     if (!folder)
1597 @
1598
1599
1600 1.6
1601 log
1602 @kerberos fix
1603 @
1604 text
1605 @d3 1
1606 a3 1
1607 static char ident[] = "@@(#)$Id: inc.c,v 1.5 1992/01/31 22:11:32 jromine Exp jromine $";
1608 d591 4
1609 a594 1
1610                 if (fflush (pf))
1611 d596 1
1612 d602 5
1613 a606 1
1614                     adios (file, "write error on");
1615 @
1616
1617
1618 1.5
1619 log
1620 @kerberos
1621 @
1622 text
1623 @d3 1
1624 a3 1
1625 static char ident[] = "@@(#)$Id: inc.c,v 1.4 1990/04/05 14:57:51 sources Exp jromine $";
1626 d194 1
1627 d197 1
1628 @
1629
1630
1631 1.4
1632 log
1633 @add ID
1634 @
1635 text
1636 @d3 1
1637 a3 1
1638 static char ident[] = "@@(#)$Id:$";
1639 d9 7
1640 a15 1
1641 #endif  POP
1642 d111 1
1643 a111 1
1644     NULL, NULL
1645 a168 1
1646            *user = NULL,
1647 d178 1
1648 d186 4
1649 d193 1
1650 a193 3
1651 #ifdef  POP
1652     if (pophost && *pophost)
1653         host = pophost;
1654 d196 1
1655 a196 1
1656 #endif  POP
1657 d332 20
1658 d356 1
1659 a356 1
1660 #endif  POP
1661 d368 1
1662 a368 3
1663             if (user == NULL)
1664                 user = getusr ();
1665             pass = getusr ();
1666 @
1667
1668
1669 1.3
1670 log
1671 @ANSI Compilance
1672 @
1673 text
1674 @d2 3
1675 @
1676
1677
1678 1.2
1679 log
1680 @try to detect full NFS file systems
1681 @
1682 text
1683 @d122 2
1684 a123 1
1685 int     pop_action (), pop_pack ();
1686 @
1687
1688
1689 1.1
1690 log
1691 @Initial revision
1692 @
1693 text
1694 @d565 2
1695 a566 1
1696                 (void) fclose (pf);
1697 @