]> diplodocus.org Git - nmh/blobdiff - uip/inc.c
find_cache(): Remove test that's always false.
[nmh] / uip / inc.c
index 9a72aa45f3a3cda66dedd2442d544b44e4215dfb..2bd1b71ff3f0914a50fd5fd89aa90689fbb8d32a 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -40,9 +40,9 @@
 #include <h/signals.h>
 #include <h/tws.h>
 #include <h/mts.h>
-#include "../sbr/lock_file.h"
-#include "../sbr/m_maildir.h"
-#include "../sbr/m_mktemp.h"
+#include "sbr/lock_file.h"
+#include "sbr/m_maildir.h"
+#include "sbr/m_mktemp.h"
 
 #ifndef TLS_SUPPORT
 # define TLSminc(a) (a)
@@ -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,8 +920,14 @@ inc_done (int status)
 static int
 pop_action(void *closure, char *s)
 {
-    NMH_UNUSED(closure);
-    fprintf (pf, "%s\n", s);
-    stop += strlen (s) + 1;
+    pop_closure *pc;
+    int n;
+
+    pc = closure;
+    n = fprintf(pc->mailout, "%s\n", s);
+    if (n < 0)
+        return NOTOK;
+    pc->written += n; /* Count linefeed too. */
+
     return OK;
 }