]> diplodocus.org Git - nmh/blobdiff - uip/inc.c
geteditor.c: Hard-code the default, "vi".
[nmh] / uip / inc.c
index 0df0a4de8879d7dc715599b3691809db283bcf3b..ad454e10dfef39d465f2570f167bf8b5ff1b6cee 100644 (file)
--- 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(char *);
+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) == 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;
@@ -915,9 +918,16 @@ inc_done (int status)
 }
 
 static int
-pop_action (char *s)
+pop_action(void *closure, char *s)
 {
-    fprintf (pf, "%s\n", s);
-    stop += strlen (s) + 1;
-    return 0;  /* Is return value used?  This was missing before 1999-07-15. */
+    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;
 }