- }
-
-#ifdef POP
- /* skip the folder setup */
- if ((inc_type == INC_POP) && packfile)
- goto go_to_it;
-#endif /* POP */
-
- 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);
-
-#ifdef POP
-go_to_it:
-#endif /* POP */
-
- if (inc_type == INC_FILE) {
- 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) {
- 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 ());
-
-#ifdef POP
- fprintf (aud, from ? "<<inc>> %s -ms %s\n"
- : host ? "<<inc>> %s -host %s -user %s\n"
- : "<<inc>> %s\n",
- dtimenow (0), from ? from : host, user);
-#else /* POP */
- fprintf (aud, from ? "<<inc>> %s -ms %s\n" : "<<inc>> %s\n",
- dtimenow (0), from);
-#endif /* POP */
- }
-
-#ifdef MHE
- if (context_find ("mhe")) {
- 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);
- }
-
-#ifdef POP
- /*
- * Get the mail from a POP server
- */
- if (inc_type == INC_POP) {
- if (packfile) {
- packfile = path (packfile, TFILE);
- if (stat (packfile, &st) == NOTOK) {
- if (errno != ENOENT)
- adios (packfile, "error on file");
- cp = concat ("Create file \"", packfile, "\"? ", NULL);
- if (noisy && !getanswer (cp))
- done (1);
- free (cp);
- }
- msgnum = map_count ();
- if ((pd = mbx_open (packfile, mbx_style, getuid(), getgid(), m_gmprot()))
- == NOTOK)
- adios (packfile, "unable to open");
- if ((pf = fdopen (pd, "w+")) == NULL)
- adios (NULL, "unable to fdopen %s", packfile);
- } else {
- hghnum = msgnum = mp->hghmsg;
- /*
- * Check if we have enough message space for all the new
- * messages. If not, then realloc the folder and add enough
- * space for all new messages plus 10 additional slots.
- */
- if (mp->hghmsg + nmsgs >= mp->hghoff
- && !(mp = folder_realloc (mp, mp->lowoff, mp->hghmsg + nmsgs + 10)))
- adios (NULL, "unable to allocate folder storage");
- }