- }
-
- /* 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);
- }