- }
-
- /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
- * not DROPGROUPPRIVS().
- */
- /* guarantee dropping group priveleges; we might not have done so earlier */
- DROPGROUPPRIVS();
-
- /*
- * We will get the mail from a file
- * (typically the standard maildrop)
- */
- if (from)
- newmail = from;
- else if ((newmail = getenv ("MAILDROP")) && *newmail)
- newmail = m_mailpath (newmail);
- else if ((newmail = context_find ("maildrop")) && *newmail)
- newmail = m_mailpath (newmail);
- else {
- newmail = concat (MAILDIR, "/", MAILFIL, NULL);
- }
- if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
- adios (NULL, "no mail to incorporate");
-
- if ((cp = strdup(newmail)) == (char *)0)
- adios (NULL, "error allocating memory to copy newmail");
-
- newmail = cp;
-
- if (!context_find ("path"))
- free (path ("./", TFOLDER));
- if (!folder)
- folder = getfolder (0);
- maildir = m_maildir (folder);
-
- if ((maildir_copy = strdup(maildir)) == (char *)0)
- adios (maildir, "error allocating memory to copy maildir");
-
- if (!folder_exists(maildir)) {
- /* If the folder doesn't exist, and we're given the -silent flag,
- * just fail.
- */
- if (noisy)
- create_folder(maildir, 0, done);
- else
- done (1);
- }
-
- if (chdir (maildir) == NOTOK)
- adios (maildir, "unable to change directory to");
-
- /* read folder and create message structure */
- if (!(mp = folder_read (folder)))
- adios (NULL, "unable to read folder %s", folder);
-
- if (access (newmail, W_OK) != NOTOK) {
- locked++;
- if (trnflag) {
- SIGNAL (SIGHUP, SIG_IGN);
- SIGNAL (SIGINT, SIG_IGN);
- SIGNAL (SIGQUIT, SIG_IGN);
- SIGNAL (SIGTERM, SIG_IGN);
- }
-
- GETGROUPPRIVS(); /* Reset gid to lock mail file */
- in = lkfopen (newmail, "r");
- DROPGROUPPRIVS();
- if (in == NULL)
- adios (NULL, "unable to lock and fopen %s", newmail);
- fstat (fileno(in), &s1);
- } else {
- trnflag = 0;
- if ((in = fopen (newmail, "r")) == NULL)
- adios (newmail, "unable to read");
- }
-
- /* This shouldn't be necessary but it can't hurt. */
- DROPGROUPPRIVS();
-
- if (audfile) {
- int i;
- if ((i = stat (audfile, &st)) == NOTOK)
- advise (NULL, "Creating Receive-Audit: %s", audfile);
- if ((aud = fopen (audfile, "a")) == NULL)
- adios (audfile, "unable to append to");
- else if (i == NOTOK)
- chmod (audfile, m_gmprot ());
-
- fprintf (aud, from ? "<<inc>> %s -ms %s\n" : "<<inc>> %s\n",
- dtimenow (0), from);
- }
-
-#ifdef MHE
- if (context_find ("mhe")) {
- int i;
- cp = concat (maildir, "/++", NULL);
- i = stat (cp, &st);
- if ((mhe = fopen (cp, "a")) == NULL)
- admonish (cp, "unable to append to");
- else
- if (i == NOTOK)
- chmod (cp, m_gmprot ());
- free (cp);
- }
-#endif /* MHE */
-
- /* Get new format string */
- nfs = new_fs (form, format, FORMAT);
-
- if (noisy) {
- printf ("Incorporating new mail into %s...\n\n", folder);
- fflush (stdout);
- }
-
- /*
- * Get the mail from file (usually mail spool)
- */
- m_unknown (in); /* the MAGIC invocation... */
- hghnum = msgnum = mp->hghmsg;
- for (;;) {
- /*
- * Check if we need to allocate more space for message status.
- * If so, then add space for an additional 100 messages.
- */
- if (msgnum >= mp->hghoff
- && !(mp = folder_realloc (mp, mp->lowoff, mp->hghoff + 100))) {
- advise (NULL, "unable to allocate folder storage");
- incerr = NOTOK;
- break;
- }
-
- /* create scanline for new message */
- switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width,
- msgnum == hghnum && chgflag, 1, NULL, 0L, noisy)) {
- case SCNFAT:
- case SCNEOF:
- break;
-
- case SCNERR:
- if (aud)
- fputs ("inc aborted!\n", aud);
- advise (NULL, "aborted!"); /* doesn't clean up locks! */
- break;
-
- case SCNNUM:
- advise (NULL, "BUG in %s, number out of range", invo_name);
- break;
-
- default:
- advise (NULL, "BUG in %s, scan() botch (%d)", invo_name, incerr);
- break;
-
- case SCNMSG:
- case SCNENC:
- /*
- * Run the external program hook on the message.
- */
-
- (void)snprintf(b, sizeof (b), "%s/%d", maildir_copy, msgnum + 1);
- (void)ext_hook("add-hook", b, (char *)0);
-
- if (aud)
- fputs (scanl, aud);
-#ifdef MHE
- if (mhe)
- fputs (scanl, mhe);
-#endif /* MHE */
- if (noisy)
- fflush (stdout);
- msgnum++;
- mp->hghmsg++;
- mp->nummsg++;
- if (mp->lowmsg == 0)
- mp->lowmsg = 1;
- clear_msg_flags (mp, msgnum);
- set_exists (mp, msgnum);
- set_unseen (mp, msgnum);
- mp->msgflags |= SEQMOD;
- continue;
- }
- /* If we get here there was some sort of error from scan(),
- * so stop processing anything more from the spool.
- */
- break;
- }
-
- if (incerr < 0) { /* error */