]> diplodocus.org Git - nmh/blobdiff - uip/rcvdist.c
Add basic support for the STLS command in POP
[nmh] / uip / rcvdist.c
index 35bbfb7cbbcb201487c4d7cf8d9a5f1499a93694..fcf9dd77943cbaf9ef1e1429047ccc818682e810 100644 (file)
@@ -5,13 +5,27 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/fmt_scan.h>
-#include <h/rcvmail.h>
-#include <h/tws.h>
-#include <h/mts.h>
-#include <h/utils.h>
-#include "../sbr/m_mktemp.h"
+#include "h/mh.h"
+#include "sbr/fmt_new.h"
+#include "distsbr.h"
+#include "sbr/m_gmprot.h"
+#include "sbr/m_getfld.h"
+#include "sbr/getarguments.h"
+#include "sbr/smatch.h"
+#include "sbr/cpydata.h"
+#include "sbr/context_find.h"
+#include "sbr/ambigsw.h"
+#include "sbr/pidstatus.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/arglist.h"
+#include "sbr/error.h"
+#include "h/fmt_scan.h"
+#include "h/tws.h"
+#include "h/mts.h"
+#include "h/done.h"
+#include "h/utils.h"
+#include "sbr/m_mktemp.h"
 
 #define RCVDIST_SWITCHES \
     X("form formfile", 4, FORMSW) \
@@ -26,6 +40,54 @@ DEFINE_SWITCH_ENUM(RCVDIST);
 DEFINE_SWITCH_ARRAY(RCVDIST, switches);
 #undef X
 
+#ifndef CYRUS_SASL
+# define SASLminc(a) (a)
+#else /* CYRUS_SASL */
+# define SASLminc(a)  0
+#endif /* CYRUS_SASL */
+
+#ifndef OAUTH_SUPPORT
+# define OAUTHminc(a)  (a)
+#else /* OAUTH_SUPPORT */
+# define OAUTHminc(a)  0
+#endif /* OAUTH_SUPPORT */
+
+/* These are just the post(1) switches that take an argument. */
+#define POST_SWITCHES \
+    X("alias aliasfile", 0, ALIASW) \
+    X("filter filterfile", 0, FILTSW) \
+    X("library directory", -7, LIBSW) /* interface from send, whom */ \
+    X("width columns", 0, WIDTHSW) \
+    X("idanno number", -6, ANNOSW) /* interface from send    */ \
+    X("client host", -6, CLIESW) \
+    X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
+    X("partno", -6, PARTSW) \
+    X("saslmech", SASLminc(5), SASLMECHSW) \
+    X("user", SASLminc(-4), USERSW) \
+    X("port server submission port name/number", 4, PORTSW) \
+    X("fileproc", -4, FILEPROCSW) \
+    X("mhlproc", -3, MHLPROCSW) \
+    X("sendmail program", 0, MTSSM) \
+    X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
+    X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
+    X("messageid localname|random", 2, MESSAGEIDSW) \
+    X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
+    X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
+    X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
+    X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
+    X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
+    X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
+    X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
+    X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(POST);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(POST, post_switches_with_args);
+#undef X
+
 static char backup[BUFSIZ] = "";
 static char drft[BUFSIZ] = "";
 static char tmpfil[BUFSIZ] = "";
@@ -47,9 +109,9 @@ main (int argc, char **argv)
     FILE *fp;
     char *tfile = NULL;
 
-    if (nmh_init(argv[0], 2)) { return 1; }
+    if (nmh_init(argv[0], true, false)) { return 1; }
 
-    done=unlink_done;
+    set_done(unlink_done);
 
     /*
      * Configure this now, since any unknown switches to rcvdist get
@@ -68,10 +130,19 @@ main (int argc, char **argv)
                case AMBIGSW: 
                    ambigsw (cp, switches);
                    done (1);
-               case UNKWNSW: 
+               case UNKWNSW: {
+                   const int argno = smatch(cp, post_switches_with_args);
                    vec[vecp++] = --cp;
+                   if (argno != AMBIGSW && argno != UNKWNSW) {
+                       /* It's a post switch that does take an argument. */
+                       if (!(cp = *argp) || *cp == '-') {
+                           die("missing argument to %s", argp[-1]);
+                       }
+                       vec[vecp++] = cp;
+                       ++argp;
+                   }
                    continue;
-
+               }
                case HELPSW: 
                    snprintf (buf, sizeof(buf),
                        "%s [switches] [switches for postproc] address ...",
@@ -84,7 +155,7 @@ main (int argc, char **argv)
 
                case FORMSW: 
                    if (!(form = *argp++) || *form == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    continue;
            }
        }
@@ -92,13 +163,13 @@ main (int argc, char **argv)
     }
 
     if (addrs == NULL)
-       adios (NULL, "usage: %s [switches] [switches for postproc] address ...",
+       die("usage: %s [switches] [switches for postproc] address ...",
            invo_name);
 
     umask (~m_gmprot ());
 
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+       die("unable to create temporary file in %s", get_temp_dir());
     }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
@@ -106,7 +177,7 @@ main (int argc, char **argv)
     fseek (fp, 0L, SEEK_SET);
 
     if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+       die("unable to create temporary file in %s", get_temp_dir());
     }
     strncpy (drft, tfile, sizeof(tmpfil));
 
@@ -127,8 +198,8 @@ main (int argc, char **argv)
     child_id = fork();
     switch (child_id) {
        case NOTOK: 
-           inform("unable to fork, continuing...");
-           /* FALLTHRU */
+            adios("fork", "failed:");
+
        case OK: 
            execvp (program, vec);
            fprintf (stderr, "unable to exec ");
@@ -226,7 +297,7 @@ rcvdistout (FILE *inb, char *form, char *addrs)
                goto finished;
 
            default: 
-               adios (NULL, "m_getfld2() returned %d", state);
+               die("m_getfld2() returned %d", state);
        }
     }
 finished: ;
@@ -258,5 +329,5 @@ unlink_done (int status)
     if (tmpfil[0])
        (void) m_unlink (tmpfil);
 
-    exit (status ? RCV_MBX : RCV_MOK);
+    exit(status ? 1 : 0);
 }