Added -messageid switch to send(1) and post(8). This allows selection
[mmh] / uip / send.c
index 2370ea4..7f0529e 100644 (file)
@@ -2,7 +2,9 @@
 /*
  * send.c -- send a composed message
  *
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 #include <h/mh.h>
 #include <signal.h>
 
 
+#ifndef CYRUS_SASL
+# define SASLminc(a) (a)
+#else /* CYRUS_SASL */
+# define SASLminc(a)  0
+#endif /* CYRUS_SASL */
+
+#ifndef TLS_SUPPORT
+# define TLSminc(a)  (a)
+#else /* TLS_SUPPORT */
+# define TLSminc(a)   0
+#endif /* TLS_SUPPORT */
+
 static struct swit switches[] = {
 #define        ALIASW                 0
     { "alias aliasfile", 0 },
@@ -67,7 +81,7 @@ static struct swit switches[] = {
 #define VERSIONSW             26
     { "version", 0 },
 #define        HELPSW                27
-    { "help", 4 },
+    { "help", 0 },
 #define BITSTUFFSW            28
     { "dashstuffing", -12 },
 #define NBITSTUFFSW           29
@@ -83,9 +97,35 @@ static struct swit switches[] = {
 #define        CLIESW                34
     { "client host", -6 },
 #define        SERVSW                35
-    { "server host", -6 },
+    { "server host", 6 },
 #define        SNOOPSW               36
-    { "snoop", -5 },
+    { "snoop", 5 },
+#define SASLSW                37
+    { "sasl", SASLminc(4) },
+#define NOSASLSW              38
+    { "nosasl", SASLminc(-6) },
+#define SASLMXSSFSW           39
+    { "saslmaxssf", SASLminc(-10) },
+#define SASLMECHSW            40
+    { "saslmech mechanism", SASLminc(-5) },
+#define USERSW                41
+    { "user username", SASLminc(-4) },
+#define ATTACHSW              42
+    { "attach", 6 },
+#define NOATTACHSW            43
+    { "noattach", 0 },
+#define ATTACHFORMATSW        44
+    { "attachformat", 7 },
+#define PORTSW               45
+    { "port server-port-name/number" , 4 },
+#define TLSSW                46
+    { "tls", TLSminc(-3) },
+#define NTLSSW                47
+    { "notls", TLSminc(-5) },
+#define MTSSW                48
+    { "mts smtp|sendmail/smtp|sendmail/pipe", 2 },
+#define MESSAGEIDSW          49
+    { "messageid localname|random", 2 },
     { NULL, 0 }
 };
 
@@ -111,7 +151,6 @@ extern char *altmsg;                /*  .. */
 extern char *annotext;
 extern char *distfile;
 
-extern int   errno;
 
 int
 main (int argc, char **argv)
@@ -124,9 +163,8 @@ main (int argc, char **argv)
     char *msgs[MAXARGS], *vec[MAXARGS];
     struct msgs *mp;
     struct stat st;
-#ifdef UCI
-    FILE *fp;
-#endif /* UCI */
+    char *attach = NMH_ATTACH_HEADER;  /* header field name for attachments */
+    int attachformat = 1; /* mhbuild format specifier for attachments */
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -142,6 +180,16 @@ main (int argc, char **argv)
     vec[vecp++] = "-library";
     vec[vecp++] = getcpy (m_maildir (""));
 
+    if ((cp = context_find ("fileproc"))) {
+      vec[vecp++] = "-fileproc";
+      vec[vecp++] = cp;
+    }
+
+    if ((cp = context_find ("mhlproc"))) {
+      vec[vecp++] = "-mhlproc";
+      vec[vecp++] = cp;
+    }
+
     while ((cp = *argp++)) {
        if (*cp == '-') {
            switch (smatch (++cp, switches)) {
@@ -154,10 +202,10 @@ main (int argc, char **argv)
                case HELPSW: 
                    snprintf (buf, sizeof(buf), "%s [file] [switches]", invo_name);
                    print_help (buf, switches, 1);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version(invo_name);
-                   done (1);
+                   done (0);
 
                case DRAFTSW: 
                    msgs[msgp++] = draft;
@@ -241,6 +289,10 @@ main (int argc, char **argv)
                case SENDSW: 
                case SOMLSW: 
                case SNOOPSW: 
+               case SASLSW:
+               case NOSASLSW:
+               case TLSSW:
+               case NTLSSW:
                    vec[vecp++] = --cp;
                    continue;
 
@@ -249,11 +301,40 @@ main (int argc, char **argv)
                case WIDTHSW: 
                case CLIESW: 
                case SERVSW: 
+               case SASLMECHSW:
+               case SASLMXSSFSW:
+               case USERSW:
+               case PORTSW:
+               case MTSSW:
+               case MESSAGEIDSW:
                    vec[vecp++] = --cp;
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                    vec[vecp++] = cp;
                    continue;
+               
+               case ATTACHSW:
+                   if (!(attach = *argp++) || *attach == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   continue;
+               case NOATTACHSW:
+                   attach = NULL;
+                   continue;
+
+               case ATTACHFORMATSW:
+                   if (! *argp || **argp == '-')
+                       adios (NULL, "missing argument to %s", argp[-1]);
+                   else {
+                       attachformat = atoi (*argp);
+                       if (attachformat < 0 ||
+                           attachformat > ATTACHFORMATS - 1) {
+                           advise (NULL, "unsupported attachformat %d",
+                                   attachformat);
+                           continue;
+                       }
+                   }
+                   ++argp;
+                   continue;
            }
        } else {
            msgs[msgp++] = cp;
@@ -347,18 +428,6 @@ go_to_it:
     if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
        if ((cp = context_find ("signature")) && *cp)
            m_putenv ("SIGNATURE", cp);
-#ifdef UCI
-       else {
-           snprintf (buf, sizeof(buf), "%s/.signature", mypath);
-           if ((fp = fopen (buf, "r")) != NULL
-               && fgets (buf, sizeof buf, fp) != NULL) {
-                   fclose (fp);
-                   if (cp = strchr (buf, '\n'))
-                       *cp = 0;
-                   m_putenv ("SIGNATURE", buf);
-           }
-       }
-#endif /* UCI */
 
     for (msgnum = 0; msgnum < msgp; msgnum++)
        if (stat (msgs[msgnum], &st) == NOTOK)
@@ -376,16 +445,18 @@ go_to_it:
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_scratch (altmsg, invo_name));
+       distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
+       unlink(distfile);
        if (link (altmsg, distfile) == NOTOK) {
-           if (errno != EXDEV
+           /* Cygwin with FAT32 filesystem produces EPERM. */
+           if (errno != EXDEV  &&  errno != EPERM
 #ifdef EISREMOTE
                    && errno != EISREMOTE
 #endif /* EISREMOTE */
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
-           distfile = getcpy (m_tmpfil (invo_name));
+           distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
            {
                int in, out;
                struct stat st;
@@ -417,7 +488,8 @@ go_to_it:
     closefds (3);
 
     for (msgnum = 0; msgnum < msgp; msgnum++) {
-       switch (sendsbr (vec, vecp, msgs[msgnum], &st, 1)) {
+       switch (sendsbr (vec, vecp, msgs[msgnum], &st, 1, attach,
+                        attachformat)) {
            case DONE: 
                done (++status);
            case NOTOK: 
@@ -429,4 +501,5 @@ go_to_it:
 
     context_save ();   /* save the context file */
     done (status);
+    return 1;
 }