-#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");
- }
-
- for (i = 1; i <= nmsgs; i++) {
- msgnum++;
- if (packfile) {
- fseek (pf, 0L, SEEK_CUR);
- pos = ftell (pf);
- size = 0;
- fwrite (mmdlm1, 1, strlen (mmdlm1), pf);
- start = ftell (pf);
-
- if (pop_retr (i, pop_pack) == NOTOK)
- adios (NULL, "%s", response);
-
- fseek (pf, 0L, SEEK_CUR);
- stop = ftell (pf);
- if (fflush (pf))
- adios (packfile, "write error on");
- fseek (pf, start, SEEK_SET);
- } else {
- cp = getcpy (m_name (msgnum));
- if ((pf = fopen (cp, "w+")) == NULL)
- adios (cp, "unable to write");
- chmod (cp, m_gmprot ());
- start = stop = 0L;
-
- if (pop_retr (i, pop_action) == NOTOK)
- adios (NULL, "%s", response);
-
- if (fflush (pf))
- adios (cp, "write error on");
- fseek (pf, 0L, SEEK_SET);
- }
- switch (p = scan (pf, msgnum, 0, nfs, width,
- packfile ? 0 : msgnum == mp->hghmsg + 1 && chgflag,
- 1, NULL, stop - start, noisy)) {
- case SCNEOF:
- printf ("%*d empty\n", DMAXFOLDER, msgnum);
- break;
-
- case SCNFAT:
- trnflag = 0;
- noisy++;
- /* advise (cp, "unable to read"); already advised */
- /* fall thru */
-
- case SCNERR:
- case SCNNUM:
- break;
-
- case SCNMSG:
- case SCNENC:
- default:
- if (aud)
- fputs (scanl, aud);
-# ifdef MHE
- if (mhe)
- fputs (scanl, mhe);
-# endif /* MHE */
- if (noisy)
- fflush (stdout);
- if (!packfile) {
- clear_msg_flags (mp, msgnum);
- set_exists (mp, msgnum);
- set_unseen (mp, msgnum);
- mp->msgflags |= SEQMOD;
- }
- break;
- }
- if (packfile) {
- fseek (pf, stop, SEEK_SET);
- fwrite (mmdlm2, 1, strlen (mmdlm2), pf);
- if (fflush (pf) || ferror (pf)) {
- int e = errno;
- pop_quit ();
- errno = e;
- adios (packfile, "write error on");
- }
- map_write (packfile, pd, 0, 0L, start, stop, pos, size, noisy);
- } else {
- if (ferror(pf) || fclose (pf)) {
- int e = errno;
- unlink (cp);
- pop_quit ();
- errno = e;
- adios (cp, "write error on");
- }
- free (cp);
- }
-
- if (trnflag && pop_dele (i) == NOTOK)
- adios (NULL, "%s", response);
- }
-
- if (pop_quit () == NOTOK)
- adios (NULL, "%s", response);
- if (packfile) {
- mbx_close (packfile, pd);
- pd = NOTOK;
- }
- }
-#endif /* POP */
-