X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/6aec307fcced3dbd5dc47c52c79bd5c833021f51..39a12997e2d7705a2760a1198932f23f4e590aab:/uip/inc.c?ds=sidebyside diff --git a/uip/inc.c b/uip/inc.c index 20d4088b..ad454e10 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -100,12 +100,12 @@ static struct Maildir_entry { static int num_maildir_entries = 0; static int snoop = 0; -extern char response[]; - -static long start; -static long stop; +typedef struct { + FILE *mailout; + long written; +} pop_closure; -static FILE *pf = NULL; +extern char response[]; /* This is an attempt to simplify things by putting all the * privilege ops into macros. @@ -149,17 +149,18 @@ static gid_t return_gid; #endif /* not MAILGROUP */ /* these variables have to be globals so that done() can correctly clean up the lockfile */ -static int locked = 0; +static bool locked; static char *newmail; static FILE *in; /* * prototypes */ +static int maildir_srt(const void *va, const void *vb) PURE; static void inc_done(int) NORETURN; static int pop_action(void *closure, char *); -int +static int maildir_srt(const void *va, const void *vb) { const struct Maildir_entry *a = va, *b = vb; @@ -179,6 +180,7 @@ main (int argc, char **argv) bool noisy; int width = -1; int hghnum = 0, msgnum = 0; + FILE *pf = NULL; bool sasl, tls, noverify; int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */ char *cp, *maildir = NULL, *folder = NULL; @@ -375,8 +377,7 @@ main (int argc, char **argv) if (*cp == '+' || *cp == '@') { if (folder) adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + folder = pluspath (cp); } else { adios (NULL, "usage: %s [+folder] [switches]", invo_name); } @@ -525,7 +526,7 @@ main (int argc, char **argv) /* Mail from a spool file. */ if (access (newmail, W_OK) != NOTOK) { - locked++; + locked = true; if (trnflag) { SIGNAL (SIGHUP, SIG_IGN); SIGNAL (SIGINT, SIG_IGN); @@ -555,7 +556,7 @@ main (int argc, char **argv) inform("Creating Receive-Audit: %s", audfile); if ((aud = fopen (audfile, "a")) == NULL) adios (audfile, "unable to append to"); - else if (i == NOTOK) + if (i == NOTOK) chmod (audfile, m_gmprot ()); if (from) @@ -584,6 +585,7 @@ main (int argc, char **argv) if (inc_type == INC_POP) { /* Mail from a POP server. */ int i; + pop_closure pc; hghnum = msgnum = mp->hghmsg; for (i = 1; i <= nmsgs; i++) { @@ -594,9 +596,10 @@ main (int argc, char **argv) if ((pf = fopen (cp, "w+")) == NULL) adios (cp, "unable to write"); chmod (cp, m_gmprot ()); - start = stop = 0L; - if (pop_retr(i, pop_action, NULL) == NOTOK) + pc.written = 0; + pc.mailout = pf; + if (pop_retr(i, pop_action, &pc) == NOTOK) adios (NULL, "%s", response); if (fflush (pf)) @@ -604,7 +607,7 @@ main (int argc, char **argv) fseek (pf, 0L, SEEK_SET); switch (incerr = scan (pf, msgnum, 0, nfs, width, msgnum == mp->hghmsg + 1 && chgflag, - 1, NULL, stop - start, noisy, &scanl)) { + 1, NULL, pc.written, noisy, &scanl)) { case SCNEOF: printf ("%*d empty\n", DMAXFOLDER, msgnum); break; @@ -745,7 +748,7 @@ main (int argc, char **argv) fseek (pf, 0L, SEEK_SET); switch (incerr = scan (pf, msgnum, 0, nfs, width, msgnum == mp->hghmsg + 1 && chgflag, - 1, NULL, stop - start, noisy, &scanl)) { + 1, NULL, 0, noisy, &scanl)) { case SCNEOF: printf ("%*d empty\n", DMAXFOLDER, msgnum); break; @@ -917,12 +920,14 @@ inc_done (int status) static int pop_action(void *closure, char *s) { - NMH_UNUSED(closure); + pop_closure *pc; + int n; - if (fputs(s, pf) == EOF || putc('\n', pf) == EOF) + pc = closure; + n = fprintf(pc->mailout, "%s\n", s); + if (n < 0) return NOTOK; - - stop += strlen(s) + 1; /* Count linefeed too. */ + pc->written += n; /* Count linefeed too. */ return OK; }