]> diplodocus.org Git - nmh/blobdiff - uip/inc.c
Fixed inc(1) and %(me) to not obey Local-Mailbox profile component.
[nmh] / uip / inc.c
index 60a4fd64f79fc491ea8413e96be0a6401ad8d0ec..c34d28ae9fd1c121d04ecf5aff3631c15e40987f 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
 #endif
 
 #include "h/mh.h"
 #endif
 
 #include "h/mh.h"
+#include "sbr/fmt_new.h"
+#include "sbr/dtime.h"
+#include "scansbr.h"
+#include "sbr/m_name.h"
+#include "sbr/m_gmprot.h"
+#include "sbr/getarguments.h"
+#include "sbr/concat.h"
+#include "sbr/seq_setunseen.h"
+#include "sbr/seq_setcur.h"
+#include "sbr/seq_save.h"
+#include "sbr/smatch.h"
+#include "sbr/getfolder.h"
+#include "sbr/ext_hook.h"
+#include "sbr/folder_read.h"
+#include "sbr/folder_realloc.h"
+#include "sbr/folder_free.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
 #include "sbr/context_find.h"
 #include "sbr/ambigsw.h"
 #include "sbr/path.h"
 #include "sbr/context_find.h"
 #include "sbr/ambigsw.h"
 #include "sbr/path.h"
@@ -40,9 +58,8 @@
 #include "h/utils.h"
 #include <fcntl.h>
 #include "h/dropsbr.h"
 #include "h/utils.h"
 #include <fcntl.h>
 #include "h/dropsbr.h"
-#include "h/popsbr.h"
+#include "popsbr.h"
 #include "h/fmt_scan.h"
 #include "h/fmt_scan.h"
-#include "h/scansbr.h"
 #include "h/signals.h"
 #include "h/tws.h"
 #include "h/mts.h"
 #include "h/signals.h"
 #include "h/tws.h"
 #include "h/mts.h"
@@ -79,6 +96,7 @@
     X("sasl", 0, SASLSW) \
     X("nosasl", 0, NOSASLSW) \
     X("saslmech", 0, SASLMECHSW) \
     X("sasl", 0, SASLSW) \
     X("nosasl", 0, NOSASLSW) \
     X("saslmech", 0, SASLMECHSW) \
+    X("tls", TLSminc(-3), TLSSW) \
     X("initialtls", TLSminc(-10), INITTLSSW) \
     X("notls", TLSminc(-5), NOTLSSW) \
     X("certverify", TLSminc(-10), CERTVERSW) \
     X("initialtls", TLSminc(-10), INITTLSSW) \
     X("notls", TLSminc(-5), NOTLSSW) \
     X("certverify", TLSminc(-10), CERTVERSW) \
@@ -188,7 +206,8 @@ main (int argc, char **argv)
     int width = -1;
     int hghnum = 0, msgnum = 0;
     FILE *pf = NULL;
     int width = -1;
     int hghnum = 0, msgnum = 0;
     FILE *pf = NULL;
-    bool sasl, tls, noverify;
+    bool sasl, noverify;
+    int tls = 0;
     int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */
     char *cp, *maildir = NULL, *folder = NULL;
     char *format = NULL, *form = NULL;
     int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */
     char *cp, *maildir = NULL, *folder = NULL;
     char *format = NULL, *form = NULL;
@@ -200,6 +219,7 @@ main (int argc, char **argv)
     FILE *aud = NULL;
     char b[PATH_MAX + 1];
     char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */
     FILE *aud = NULL;
     char b[PATH_MAX + 1];
     char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */
+    charstring_t scanl = NULL;
 
     int nmsgs, nbytes;
     char *MAILHOST_env_variable;
 
     int nmsgs, nbytes;
     char *MAILHOST_env_variable;
@@ -233,7 +253,7 @@ main (int argc, char **argv)
     if (pophost && *pophost)
        host = pophost;
 
     if (pophost && *pophost)
        host = pophost;
 
-    sasl = tls = false;
+    sasl = false;
     chgflag = noisy = noverify = true;
     while ((cp = *argp++)) {
        if (*cp == '-') {
     chgflag = noisy = noverify = true;
     while ((cp = *argp++)) {
        if (*cp == '-') {
@@ -350,12 +370,16 @@ main (int argc, char **argv)
                    die("missing argument to %s", argp[-2]);
                continue;
 
                    die("missing argument to %s", argp[-2]);
                continue;
 
+           case TLSSW:
+               tls = 1;
+               continue;
+
            case INITTLSSW:
            case INITTLSSW:
-                tls = true;
+                tls = 2;
                continue;
 
            case NOTLSSW:
                continue;
 
            case NOTLSSW:
-                tls = false;
+                tls = 0;
                continue;
 
            case CERTVERSW:
                continue;
 
            case CERTVERSW:
@@ -416,8 +440,10 @@ main (int argc, char **argv)
            }
        }
 
            }
        }
 
-       if (tls)
-           tlsflag |= P_INITTLS;
+       if (tls == 1)
+           tlsflag = P_STARTTLS;
+       else if (tls == 2)
+           tlsflag = P_INITTLS;
 
        if (noverify)
            tlsflag |= P_NOVERIFY;
 
        if (noverify)
            tlsflag |= P_NOVERIFY;
@@ -451,55 +477,55 @@ main (int argc, char **argv)
        }
        if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
            die("no mail to incorporate");
        }
        if (stat (newmail, &s1) == NOTOK || s1.st_size == 0)
            die("no mail to incorporate");
-       if (s1.st_mode & S_IFDIR) {
-           DIR *md;
-           struct dirent *de;
-           struct stat ms;
-           int i;
-           i = 0;
-           cp = concat (newmail, "/new", NULL);
-           if ((md = opendir(cp)) == NULL)
-               die("unable to open %s", cp);
-           while ((de = readdir (md)) != NULL) {
-               if (de->d_name[0] == '.')
-                   continue;
-               if (i >= num_maildir_entries) {
-                   if ((Maildir = realloc(Maildir, sizeof(*Maildir) * (2*i+16))) == NULL)
-                       die("not enough memory for %d messages", 2*i+16);
-                   num_maildir_entries = 2*i+16;
-               }
-               Maildir[i].filename = concat (cp, "/", de->d_name, NULL);
-               if (stat(Maildir[i].filename, &ms) != 0)
-                  adios (Maildir[i].filename, "couldn't get delivery time");
-               Maildir[i].mtime = ms.st_mtime;
-               i++;
-           }
-           free (cp);
-           closedir (md);
-           cp = concat (newmail, "/cur", NULL);
-           if ((md = opendir(cp)) == NULL)
-               die("unable to open %s", cp);
-           while ((de = readdir (md)) != NULL) {
-               if (de->d_name[0] == '.')
-                   continue;
-               if (i >= num_maildir_entries) {
-                   if ((Maildir = realloc(Maildir, sizeof(*Maildir) * (2*i+16))) == NULL)
-                       die("not enough memory for %d messages", 2*i+16);
-                   num_maildir_entries = 2*i+16;
-               }
-               Maildir[i].filename = concat (cp, "/", de->d_name, NULL);
-               if (stat(Maildir[i].filename, &ms) != 0)
-                  adios (Maildir[i].filename, "couldn't get delivery time");
-               Maildir[i].mtime = ms.st_mtime;
-               i++;
-           }
-           free (cp);
-           closedir (md);
-           if (i == 0)
-               die("no mail to incorporate");
-           num_maildir_entries = i;
-           qsort (Maildir, num_maildir_entries, sizeof(*Maildir), maildir_srt);
-       }
+       if (s1.st_mode & S_IFDIR) {
+           DIR *md;
+           struct dirent *de;
+           struct stat ms;
+           int i;
+           i = 0;
+           cp = concat (newmail, "/new", NULL);
+           if ((md = opendir(cp)) == NULL)
+               die("unable to open %s", cp);
+           while ((de = readdir (md)) != NULL) {
+               if (de->d_name[0] == '.')
+                   continue;
+               if (i >= num_maildir_entries) {
+                   if ((Maildir = realloc(Maildir, sizeof(*Maildir) * (2*i+16))) == NULL)
+                       die("not enough memory for %d messages", 2*i+16);
+                   num_maildir_entries = 2*i+16;
+               }
+               Maildir[i].filename = concat (cp, "/", de->d_name, NULL);
+               if (stat(Maildir[i].filename, &ms) != 0)
+                  adios (Maildir[i].filename, "couldn't get delivery time");
+               Maildir[i].mtime = ms.st_mtime;
+               i++;
+           }
+           free (cp);
+           closedir (md);
+           cp = concat (newmail, "/cur", NULL);
+           if ((md = opendir(cp)) == NULL)
+               die("unable to open %s", cp);
+           while ((de = readdir (md)) != NULL) {
+               if (de->d_name[0] == '.')
+                   continue;
+               if (i >= num_maildir_entries) {
+                   if ((Maildir = realloc(Maildir, sizeof(*Maildir) * (2*i+16))) == NULL)
+                       die("not enough memory for %d messages", 2*i+16);
+                   num_maildir_entries = 2*i+16;
+               }
+               Maildir[i].filename = concat (cp, "/", de->d_name, NULL);
+               if (stat(Maildir[i].filename, &ms) != 0)
+                  adios (Maildir[i].filename, "couldn't get delivery time");
+               Maildir[i].mtime = ms.st_mtime;
+               i++;
+           }
+           free (cp);
+           closedir (md);
+           if (i == 0)
+               die("no mail to incorporate");
+           num_maildir_entries = i;
+           qsort (Maildir, num_maildir_entries, sizeof(*Maildir), maildir_srt);
+       }
 
        cp = mh_xstrdup(newmail);
        newmail = cp;
 
        cp = mh_xstrdup(newmail);
        newmail = cp;
@@ -570,7 +596,7 @@ main (int argc, char **argv)
            fprintf (aud, "<<inc>> %s -ms %s\n", dtimenow(0), from);
        else {
            if (host)
            fprintf (aud, "<<inc>> %s -ms %s\n", dtimenow(0), from);
        else {
            if (host)
-               fprintf (aud, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
+               fprintf (aud, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
                         host, user);
            else
                fprintf (aud, "<<inc>> %s\n", dtimenow (0));
                         host, user);
            else
                fprintf (aud, "<<inc>> %s\n", dtimenow (0));
@@ -596,7 +622,6 @@ main (int argc, char **argv)
 
         hghnum = msgnum = mp->hghmsg;
        for (i = 1; i <= nmsgs; i++) {
 
         hghnum = msgnum = mp->hghmsg;
        for (i = 1; i <= nmsgs; i++) {
-           charstring_t scanl = NULL;
 
            msgnum++;
             cp = mh_xstrdup(m_name (msgnum));
 
            msgnum++;
             cp = mh_xstrdup(m_name (msgnum));
@@ -630,7 +655,6 @@ main (int argc, char **argv)
                break;
 
            case SCNMSG:
                break;
 
            case SCNMSG:
-           case SCNENC:
            default:
                if (aud)
                    fputs (charstring_buffer (scanl), aud);
            default:
                if (aud)
                    fputs (charstring_buffer (scanl), aud);
@@ -638,7 +662,9 @@ main (int argc, char **argv)
                    fflush (stdout);
                break;
            }
                    fflush (stdout);
                break;
            }
-           charstring_free (scanl);
+
+           if (scanl)
+               charstring_clear (scanl);
 
             if (ferror(pf) || fclose (pf)) {
                 int e = errno;
 
             if (ferror(pf) || fclose (pf)) {
                 int e = errno;
@@ -655,6 +681,9 @@ main (int argc, char **argv)
            scan_finished();
        }
 
            scan_finished();
        }
 
+       charstring_free (scanl);
+       scanl = NULL;
+
        if (pop_quit () == NOTOK)
            die("%s", response);
 
        if (pop_quit () == NOTOK)
            die("%s", response);
 
@@ -664,8 +693,6 @@ main (int argc, char **argv)
        scan_detect_mbox_style (in);            /* the MAGIC invocation... */
        hghnum = msgnum = mp->hghmsg;
        for (;;) {
        scan_detect_mbox_style (in);            /* the MAGIC invocation... */
        hghnum = msgnum = mp->hghmsg;
        for (;;) {
-           charstring_t scanl = NULL;
-
            /* create scanline for new message */
            switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width,
                              msgnum == hghnum && chgflag, 1, NULL, 0L, noisy,
            /* create scanline for new message */
            switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width,
                              msgnum == hghnum && chgflag, 1, NULL, 0L, noisy,
@@ -689,7 +716,6 @@ main (int argc, char **argv)
                break;
 
            case SCNMSG:
                break;
 
            case SCNMSG:
-           case SCNENC:
                /*
                 *  Run the external program hook on the message.
                 */
                /*
                 *  Run the external program hook on the message.
                 */
@@ -702,16 +728,18 @@ main (int argc, char **argv)
                if (noisy)
                    fflush (stdout);
 
                if (noisy)
                    fflush (stdout);
 
+               charstring_clear (scanl);
                msgnum++;
                continue;
            }
                msgnum++;
                continue;
            }
-           charstring_free (scanl);
 
            /* If we get here there was some sort of error from scan(),
             * so stop processing anything more from the spool.
             */
            break;
        }
 
            /* If we get here there was some sort of error from scan(),
             * so stop processing anything more from the spool.
             */
            break;
        }
+       charstring_free (scanl);
+       scanl = NULL;
 
     } else {
         /* Mail from Maildir. */
 
     } else {
         /* Mail from Maildir. */
@@ -721,8 +749,6 @@ main (int argc, char **argv)
 
        hghnum = msgnum = mp->hghmsg;
        for (i = 0; i < num_maildir_entries; i++) {
 
        hghnum = msgnum = mp->hghmsg;
        for (i = 0; i < num_maildir_entries; i++) {
-           charstring_t scanl = NULL;
-
            msgnum++;
 
            sp = Maildir[i].filename;
            msgnum++;
 
            sp = Maildir[i].filename;
@@ -733,7 +759,7 @@ main (int argc, char **argv)
                size_t nrd;
 
                if ((sf = fopen (sp, "r")) == NULL)
                size_t nrd;
 
                if ((sf = fopen (sp, "r")) == NULL)
-                   adios (sp, "unable to read for copy");
+                   adios (sp, "unable to read for copy");
                if ((pf = fopen (cp, "w+")) == NULL)
                    adios (cp, "unable to write for copy");
                while ((nrd = fread(buf, 1, sizeof(buf), sf)) > 0)
                if ((pf = fopen (cp, "w+")) == NULL)
                    adios (cp, "unable to write for copy");
                while ((nrd = fread(buf, 1, sizeof(buf), sf)) > 0)
@@ -771,7 +797,6 @@ main (int argc, char **argv)
                break;
 
            case SCNMSG:
                break;
 
            case SCNMSG:
-           case SCNENC:
            default:
                /*
                 *  Run the external program hook on the message.
            default:
                /*
                 *  Run the external program hook on the message.
@@ -786,7 +811,7 @@ main (int argc, char **argv)
                    fflush (stdout);
                break;
            }
                    fflush (stdout);
                break;
            }
-           charstring_free (scanl);
+           charstring_clear (scanl);
 
            if (ferror(pf) || fclose (pf)) {
                int e = errno;
 
            if (ferror(pf) || fclose (pf)) {
                int e = errno;
@@ -804,6 +829,8 @@ main (int argc, char **argv)
            scan_finished();
        }
        free (Maildir); /* From now on Maildir is just a flag - don't dref! */
            scan_finished();
        }
        free (Maildir); /* From now on Maildir is just a flag - don't dref! */
+       charstring_free (scanl);
+       scanl = NULL;
     }
 
     scan_finished ();
     }
 
     scan_finished ();
@@ -847,7 +874,7 @@ main (int argc, char **argv)
     if (msgnum == hghnum) {
        inform("no messages incorporated, continuing...");
     } else {
     if (msgnum == hghnum) {
        inform("no messages incorporated, continuing...");
     } else {
-       /*
+       /*
         * Lock the sequence file now, and loop to set the right flags
         * in the folder structure
         */
         * Lock the sequence file now, and loop to set the right flags
         * in the folder structure
         */