Clean up a bunch of unused code and options. Specifically:
[mmh] / uip / post.c
index d5760a2..b24f571 100644 (file)
 #include <h/mts.h>
 
 #include <errno.h>
-#include <setjmp.h>
 #include <signal.h>
 
-#ifdef TIME_WITH_SYS_TIME
+#ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
-# include <time.h>
-#else
-# ifdef TM_IN_SYS_TIME
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
 #endif
+#include <time.h>
 
-#ifdef SMTPMTS
-# include <mts/smtp/smtp.h>
-#endif
+#include <mts/smtp/smtp.h>
 
 #ifndef CYRUS_SASL
 # define SASLminc(a) (a)
@@ -110,42 +101,36 @@ static struct swit switches[] = {
     { "dashstuffing", -12 },           /* should we dashstuff BCC messages? */
 #define NBITSTUFFSW              23
     { "nodashstuffing", -14 },
-#define        MAILSW                   24
-    { "mail", -4 },                    /* specify MAIL smtp mode */
-#define        SAMLSW                   25
-    { "saml", -4 },                    /* specify SAML smtp mode */
-#define        SENDSW                   26
-    { "send", -4 },                    /* specify SEND smtp mode */
-#define        SOMLSW                   27
-    { "soml", -4 },                    /* specify SOML smtp mode */
-#define        ANNOSW                   28
+#define        ANNOSW                   24
     { "idanno number", -6 },           /* interface from send    */
-#define        DLVRSW                   29
-    { "deliver address-list", -7 },
-#define        CLIESW                   30
+#define        CLIESW                   25
     { "client host", -6 },
-#define        SERVSW                   31
-    { "server host", -6 },             /* specify alternate SMTP server */
-#define        SNOOPSW                  32
+#define        SERVSW                   26
+    { "server host", 6 },              /* specify alternate SMTP server */
+#define        SNOOPSW                  27
     { "snoop", -5 },                   /* snoop the SMTP transaction */
-#define        FILLSW                   33
-    { "fill-in file", -7 },
-#define        FILLUSW                  34
-    { "fill-up", -7 },
-#define        PARTSW                   35
+#define        PARTSW                   28
     { "partno", -6 },
-#define        QUEUESW                  36
+#define        QUEUESW                  29
     { "queued", -6 },
-#define SASLSW                   37
+#define SASLSW                   30
     { "sasl", SASLminc(-4) },
-#define SASLMECHSW               38
+#define NOSASLSW                 31
+    { "nosasl", SASLminc(-6) },
+#define SASLMXSSFSW              32
+    { "saslmaxssf", SASLminc(-10) },
+#define SASLMECHSW               33
     { "saslmech", SASLminc(-5) },
-#define USERSW                   39
+#define USERSW                   34
     { "user", SASLminc(-4) },
-#define PORTSW                  40
+#define PORTSW                  35
     { "port server port name/number", 4 },
-#define TLSSW                   41
+#define TLSSW                   36
     { "tls", TLSminc(-3) },
+#define FILEPROCSW              37
+    { "fileproc", -4 },
+#define MHLPROCSW               38
+    { "mhlproc", -3 },
     { NULL, 0 }
 };
 
@@ -242,6 +227,7 @@ static int checksw = 0;             /* whom -check                           */
 static int linepos=0;          /* putadr()'s position on the line       */
 static int nameoutput=0;       /* putadr() has output header name       */
 static int sasl=0;             /* Use SASL auth for SMTP                */
+static int saslssf=-1;         /* Our maximum SSF for SASL              */
 static char *saslmech=NULL;    /* Force use of particular SASL mech     */
 static char *user=NULL;                /* Authenticate as this user             */
 static char *port="smtp";      /* Name of server port for SMTP          */
@@ -268,24 +254,19 @@ static char *fccfold[FCCS];       /* foldernames for FCC'ing       */
 
 static struct headers  *hdrtab;        /* table for the message we're doing */
 
-static struct mailname localaddrs={NULL};      /* local addrs     */
-static struct mailname netaddrs={NULL};                /* network addrs   */
-static struct mailname uuaddrs={NULL};         /* uucp addrs      */
-static struct mailname tmpaddrs={NULL};                /* temporary queue */
+static struct mailname localaddrs;             /* local addrs     */
+static struct mailname netaddrs;               /* network addrs   */
+static struct mailname uuaddrs;                        /* uucp addrs      */
+static struct mailname tmpaddrs;               /* temporary queue */
 
-#ifdef SMTPMTS
 static int snoop      = 0;
-static int smtpmode   = S_MAIL;
 static char *clientsw = NULL;
 static char *serversw = NULL;
 
 extern struct smtp sm_reply;
-#endif /* SMTPMTS */
 
 static char prefix[] = "----- =_aaaaaaaaaa";
 
-static int fill_up = 0;
-static char *fill_in = NULL;
 static char *partno = NULL;
 static int queued = 0;
 
@@ -459,33 +440,6 @@ main (int argc, char **argv)
                        adios (NULL, "bad argument %s %s", argp[-2], cp);
                    continue;
 
-               case DLVRSW:
-                   if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                   continue;
-
-#ifndef        SMTPMTS
-               case CLIESW:
-               case SERVSW:
-                   if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                   continue;
-
-               case SNOOPSW:
-                   continue;
-#else /* SMTPMTS */
-               case MAILSW:
-                   smtpmode = S_MAIL;
-                   continue;
-               case SAMLSW:
-                   smtpmode = S_SAML;
-                   continue;
-               case SOMLSW:
-                   smtpmode = S_SOML;
-                   continue;
-               case SENDSW:
-                   smtpmode = S_SEND;
-                   continue;
                case CLIESW:
                    if (!(clientsw = *argp++) || *clientsw == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
@@ -497,15 +451,7 @@ main (int argc, char **argv)
                case SNOOPSW:
                    snoop++;
                    continue;
-#endif /* SMTPMTS */
 
-               case FILLSW:
-                   if (!(fill_in = *argp++) || *fill_in == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                   continue;
-               case FILLUSW:
-                   fill_up++;
-                   continue;
                case PARTSW:
                    if (!(partno = *argp++) || *partno == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
@@ -518,6 +464,16 @@ main (int argc, char **argv)
                case SASLSW:
                    sasl++;
                    continue;
+
+               case NOSASLSW:
+                   sasl = 0;
+                   continue;
+
+               case SASLMXSSFSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   saslssf = atoi(cp);
+                   continue;
                
                case SASLMECHSW:
                    if (!(saslmech = *argp++) || *saslmech == '-')
@@ -537,6 +493,18 @@ main (int argc, char **argv)
                case TLSSW:
                    tls++;
                    continue;
+
+               case FILEPROCSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   fileproc = cp;
+                   continue;
+
+               case MHLPROCSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   mhlproc = cp;
+                   continue;
            }
        }
        if (msg)
@@ -562,7 +530,7 @@ main (int argc, char **argv)
        discard (out = stdout); /* XXX: reference discard() to help loader */
     } else {
        if (whomsw) {
-           if ((out = fopen (fill_in ? fill_in : "/dev/null", "w")) == NULL)
+           if ((out = fopen ("/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
             char *cp = m_mktemp(m_maildir(invo_name), NULL, &out);
@@ -600,7 +568,7 @@ main (int argc, char **argv)
            case BODY: 
            case BODYEOF: 
                finish_headers (out);
-               if (whomsw && !fill_in)
+               if (whomsw)
                    break;
                fprintf (out, "\n%s", buf);
                while (state == BODY) {
@@ -636,8 +604,7 @@ main (int argc, char **argv)
 
     /* If we are doing a "whom" check */
     if (whomsw) {
-       if (!fill_up)
-           verify_all_addresses (1);
+       verify_all_addresses (1);
        done (0);
     }
 
@@ -693,17 +660,11 @@ putfmt (char *name, char *str, FILE *out)
 
     hdr = &hdrtab[i];
     if (hdr->flags & HIGN) {
-       if (fill_in)
-           fprintf (out, "%s: %s", name, str);
        return;
     }
     if (hdr->flags & HBAD) {
-       if (fill_in)
-           fprintf (out, "%s: %s", name, str);
-       else {
-           advise (NULL, "illegal header line -- %s:", name);
-           badmsg++;
-       }
+       advise (NULL, "illegal header line -- %s:", name);
+       badmsg++;
        return;
     }
     msgflags |= (hdr->set & ~(MVIS | MINV));
@@ -711,11 +672,6 @@ putfmt (char *name, char *str, FILE *out)
     if (hdr->flags & HSUB)
        subject = subject ? add (str, add ("\t", subject)) : getcpy (str);
     if (hdr->flags & HFCC) {
-       if (fill_in) {
-           fprintf (out, "%s: %s", name, str);
-           return;
-       }
-
        if ((cp = strrchr(str, '\n')))
            *cp = 0;
        for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) {
@@ -760,7 +716,7 @@ putfmt (char *name, char *str, FILE *out)
 
     nameoutput = linepos = 0;
     snprintf (namep, sizeof(namep), "%s%s",
-               !fill_in && (hdr->flags & HMNG) ? "Original-" : "", name);
+               (hdr->flags & HMNG) ? "Original-" : "", name);
 
     for (grp = 0, mp = tmpaddrs.m_next; mp; mp = np)
        if (mp->m_nohost) {     /* also used to test (hdr->flags & HTRY) */
@@ -841,8 +797,6 @@ putfmt (char *name, char *str, FILE *out)
        badmsg++;
     }
     if (linepos) {
-       if (fill_in && grp > 0)
-           putc (';', out);
        putc ('\n', out);
     }
 }
@@ -859,8 +813,8 @@ start_headers (void)
     mygid = getgid ();
     time (&tclock);
 
-    strncpy (from, adrsprintf (NULL, NULL), sizeof(from));
-    strncpy (myhost, LocalName (), sizeof(myhost));
+    strncpy (from, getlocaladdr(), sizeof(from));
+    strncpy (myhost, LocalName (0), sizeof(myhost));
 
     for (cp = myhost; *cp; cp++)
        *cp = uptolow (*cp);
@@ -868,7 +822,7 @@ start_headers (void)
     if ((cp = getfullname ()) && *cp) {
        strncpy (sigbuf, cp, sizeof(sigbuf));
        snprintf (signature, sizeof(signature), "%s <%s>",
-               sigbuf, adrsprintf (NULL, NULL));
+               sigbuf, getlocaladdr());
        if ((cp = getname (signature)) == NULL)
            adios (NULL, "getname () failed -- you lose extraordinarily big");
        if ((mp = getm (cp, NULL, 0, AD_HOST, NULL)) == NULL)
@@ -877,7 +831,7 @@ start_headers (void)
        while (getname (""))
            continue;
     } else {
-       strncpy (signature, adrsprintf (NULL, NULL), sizeof(signature));
+       strncpy (signature, getlocaladdr(), sizeof(signature));
     }
 }
 
@@ -893,13 +847,13 @@ finish_headers (FILE *out)
 {
     switch (msgstate) {
        case NORMAL: 
-           if (whomsw && !fill_up)
+           if (whomsw)
                break;
 
            fprintf (out, "Date: %s\n", dtime (&tclock, 0));
            if (msgid)
                fprintf (out, "Message-ID: <%d.%ld@%s>\n",
-                       (int) getpid (), (long) tclock, LocalName ());
+                       (int) getpid (), (long) tclock, LocalName (1));
            if (msgflags & MFRM) {
                /* There was already a From: in the draft.  Don't add one. */
                if (!draft_from_masquerading)
@@ -928,13 +882,13 @@ finish_headers (FILE *out)
                advise (NULL, "message has no From: header");
                badmsg++;
            }
-           if (whomsw && !fill_up)
+           if (whomsw)
                break;
 
            fprintf (out, "Resent-Date: %s\n", dtime (&tclock, 0));
            if (msgid)
                fprintf (out, "Resent-Message-ID: <%d.%ld@%s>\n",
-                       (int) getpid (), (long) tclock, LocalName ());
+                       (int) getpid (), (long) tclock, LocalName (1));
            if (msgflags & MRFM) {
                /* There was already a Resent-From: in draft.  Don't add one. */
                if (!draft_from_masquerading)
@@ -983,7 +937,7 @@ putadr (char *name, char *aka, struct mailname *mp, FILE *out, unsigned int flag
 
     if (mp->m_mbox == NULL || ((flags & HTRY) && !insert (mp)))
        return 0;
-    if ((!fill_in && (flags & (HBCC | HDCC))) || mp->m_ingrp)
+    if ((flags & (HBCC | HDCC)) || mp->m_ingrp)
        return 1;
 
     if (!nameoutput) {
@@ -994,7 +948,7 @@ putadr (char *name, char *aka, struct mailname *mp, FILE *out, unsigned int flag
     if (*aka && mp->m_type != UUCPHOST && !mp->m_pers)
        mp->m_pers = getcpy (aka);
     if (format) {
-       if (mp->m_gname && !fill_in) {
+       if (mp->m_gname) {
            snprintf (buffer, sizeof(buffer), "%s;", mp->m_gname);
            cp = buffer;
        } else {
@@ -1027,17 +981,15 @@ putgrp (char *name, char *group, FILE *out, unsigned int flags)
     int len;
     char *cp;
 
-    if (!fill_in && (flags & HBCC))
+    if (flags & HBCC)
        return;
 
     if (!nameoutput) {
        fprintf (out, "%s: ", name);
        linepos += (nameoutput = strlen (name) + 2);
-       if (fill_in)
-           linepos -= strlen (group);
     }
 
-    cp = fill_in ? group : concat (group, ";", NULL);
+    cp = concat (group, ";", NULL);
     len = strlen (cp);
 
     if (linepos > nameoutput) {
@@ -1188,7 +1140,7 @@ make_bcc_file (int dashstuff)
     fprintf (out, "Date: %s\n", dtime (&tclock, 0));
     if (msgid)
        fprintf (out, "Message-ID: <%d.%ld@%s>\n",
-               (int) getpid (), (long) tclock, LocalName ());
+               (int) getpid (), (long) tclock, LocalName (1));
     if (msgflags & MFRM) {
       /* There was already a From: in the draft.  Don't add one. */
       if (!draft_from_masquerading)
@@ -1309,16 +1261,13 @@ make_bcc_file (int dashstuff)
 static int
 find_prefix (void)
 {
-    int        len, result;
+    int        result = OK;
     unsigned char buffer[BUFSIZ];
     FILE *in;
 
     if ((in = fopen (tmpfil, "r")) == NULL)
        adios (tmpfil, "unable to re-open");
 
-    len = strlen (prefix);
-
-    result = OK;
     while (fgets (buffer, sizeof(buffer) - 1, in))
        if (buffer[0] == '-' && buffer[1] == '-') {
            unsigned char *cp;
@@ -1389,10 +1338,8 @@ do_addresses (int bccque, int talk)
 
     chkadr ();
 
-#ifdef SMTPMTS
     if (rp_isbad (retval = sm_waend ()))
        die (NULL, "problem ending addresses; %s", rp_string (retval));
-#endif /* SMTPMTS */
 }
 
 
@@ -1405,8 +1352,6 @@ do_addresses (int bccque, int talk)
  * SENDMAIL/SMTP routines
  */
 
-#ifdef SMTPMTS
-
 static void
 post (char *file, int bccque, int talk)
 {
@@ -1425,9 +1370,9 @@ post (char *file, int bccque, int talk)
     sigon ();
 
     if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, verbose,
-                                   snoop, onex, queued, sasl, saslmech,
-                                   user, tls))
-           || rp_isbad (retval = sm_winit (smtpmode, from)))
+                                   snoop, onex, queued, sasl, saslssf,
+                                   saslmech, user, tls))
+           || rp_isbad (retval = sm_winit (from)))
        die (NULL, "problem initializing server; %s", rp_string (retval));
 
     do_addresses (bccque, talk && verbose);
@@ -1465,8 +1410,8 @@ verify_all_addresses (int talk)
     if (!whomsw || checksw)
        if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch,
                                        verbose, snoop, 0, queued, sasl,
-                                       saslmech, user, tls))
-               || rp_isbad (retval = sm_winit (smtpmode, from)))
+                                       saslssf, saslmech, user, tls))
+               || rp_isbad (retval = sm_winit (from)))
            die (NULL, "problem initializing server; %s", rp_string (retval));
 
     if (talk && !whomsw)
@@ -1591,28 +1536,22 @@ do_text (char *file, int fd)
     }
 }
 
-#endif /* SMTPMTS */
-
 
 /*
  * SIGNAL HANDLING
  */
 
-static RETSIGTYPE
+static void
 sigser (int i)
 {
-#ifndef RELIABLE_SIGNALS
-    SIGNAL (i, SIG_IGN);
-#endif
+    NMH_UNUSED (i);
 
     unlink (tmpfil);
     if (msgflags & MINV)
        unlink (bccfil);
 
-#ifdef SMTPMTS
     if (!whomsw || checksw)
        sm_end (NOTOK);
-#endif /* SMTPMTS */
 
     done (1);
 }
@@ -1728,10 +1667,8 @@ die (char *what, char *fmt, ...)
     if (msgflags & MINV)
        unlink (bccfil);
 
-#ifdef SMTPMTS
     if (!whomsw || checksw)
        sm_end (NOTOK);
-#endif /* SMTPMTS */
 
     va_start(ap, fmt);
     advertise (what, NULL, fmt, ap);