]> diplodocus.org Git - nmh/blobdiff - uip/whatnowsbr.c
inc/test-eom-align: Replace case on $MBOX_TYPE with interpolation.
[nmh] / uip / whatnowsbr.c
index e2e0ceb64546ab41a72bc3b63253d0aee05d5f73..102916174f3c3bfe65f8e75bae452928ff0be4d6 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * whatnowsbr.c -- the WhatNow shell
+/* whatnowsbr.c -- the WhatNow shell
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
 #include <fcntl.h>
 #include <h/mime.h>
 #include <h/utils.h>
-
 #ifdef OAUTH_SUPPORT
 # include <h/oauth.h>
 #endif
+#include "h/done.h"
+#include "sbr/m_maildir.h"
+#include "sbr/m_mktemp.h"
+#include "sbr/mime_type.h"
 
 #define WHATNOW_SWITCHES \
     X("draftfolder +folder", 0, DFOLDSW) \
@@ -57,8 +58,6 @@
     X("prompt string", 4, PRMPTSW) \
     X("version", 0, VERSIONSW) \
     X("help", 0, HELPSW) \
-    X("attach header-field-name", -6, ATTACHSW) \
-    X("noattach", -8, NOATTACHSW) \
 
 
 #define X(sw, minchars, id) id,
@@ -197,20 +196,11 @@ WhatNow (int argc, char **argv)
                if (!(myprompt = *argp++) || *myprompt == '-')
                    adios (NULL, "missing argument to %s", argp[-2]);
                continue;
-
-           case ATTACHSW:
-               inform("The -attach switch is deprecated");
-               continue;
-
-           case NOATTACHSW:
-               inform("The -noattach switch is deprecated");
-               continue;
            }
        }
        if (drft)
            adios (NULL, "only one draft at a time!");
-       else
-           drft = cp;
+        drft = cp;
     }
 
     if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0)
@@ -718,8 +708,8 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
            }
            if (altmsg) {
                if (mp)
-                   m_putenv ("mhfolder", mp->foldpath);
-               m_putenv ("editalt", altpath);
+                   setenv("mhfolder", mp->foldpath, 1);
+               setenv("editalt", altpath, 1);
            }
 
            vec = argsplit(*ed, &prog, &vecp);
@@ -733,7 +723,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
            execvp (prog, vec);
            fprintf (stderr, "unable to exec ");
            perror (*ed);
-           _exit (-1);
+           _exit(1);
 
        default:
            if ((status = pidwait (pid, NOTOK))) {
@@ -812,7 +802,7 @@ static int
 sendfile (char **arg, char *file, int pushsw)
 {
     pid_t child_id;
-    int i, vecp;
+    int vecp;
     char *cp, *sp, **vec, *program;
 
     /*
@@ -829,12 +819,11 @@ sendfile (char **arg, char *file, int pushsw)
     context_save ();   /* save the context file */
     fflush (stdout);
 
-    for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
-       sleep (5);
+    child_id = fork();
     switch (child_id) {
        case NOTOK:
-           inform("unable to fork, so sending directly...");
-           /* FALLTHRU */
+            adios("fork", "failed:");
+
        case OK:
            vec = argsplit(sendproc, &program, &vecp);
            if (pushsw)
@@ -848,7 +837,7 @@ sendfile (char **arg, char *file, int pushsw)
            execvp (program, vec);
            fprintf (stderr, "unable to exec ");
            perror (sendproc);
-           _exit (-1);
+           _exit(1);
 
        default:
            if (pidwait(child_id, OK) == 0)
@@ -876,7 +865,7 @@ buildfile (char **argp, char *file)
        while (argp[i])
            i++;
     }
-    args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
+    args = mh_xmalloc((i + 2) * sizeof(char *));
 
     /*
      * For backward compatibility, we need to add -build
@@ -894,7 +883,7 @@ buildfile (char **argp, char *file)
     i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0, 0);
     free (args);
 
-    return (i ? NOTOK : OK);
+    return i ? NOTOK : OK;
 }
 
 
@@ -948,9 +937,6 @@ buildfile (char **argp, char *file)
     X("saslmech", SASLminc(5), SASLMECHSW) \
     X("authservice", SASLminc(0), AUTHSERVICESW) \
     X("user username", SASLminc(4), USERSW) \
-    X("attach fieldname", 6, SNDATTACHSW) \
-    X("noattach", 0, SNDNOATTACHSW) \
-    X("attachformat", 7, SNDATTACHFORMAT) \
     X("port server-port-name/number", 4, PORTSW) \
     X("tls", TLSminc(-3), TLSSW) \
     X("initialtls", TLSminc(-10), INITTLSSW) \
@@ -994,10 +980,6 @@ sendit (char *sp, char **arg, char *file, int pushed)
     int snoop = 0;
     struct stat st;
 
-#ifndef        lint
-    int        distsw = 0;
-#endif
-
     /*
      * Make sure these are defined.  In particular, we need
      * savearg[1] to be NULL, in case "arg" is NULL below.  It
@@ -1187,19 +1169,8 @@ sendit (char *sp, char **arg, char *file, int pushed)
                        inform("missing argument to %s", argp[-2]);
                        return;
                    }
-                   /* FALLTHRU */
-               case SNDRFSW:
                    continue;
-
-               case SNDATTACHSW:
-                   inform("The -attach switch is deprecated");
-                   continue;
-               case SNDNOATTACHSW:
-                   inform("The -noattach switch is deprecated");
-                   continue;
-
-               case SNDATTACHFORMAT:
-                   inform("The -attachformat switch is deprecated");
+               case SNDRFSW:
                    continue;
            }
        }
@@ -1220,7 +1191,7 @@ sendit (char *sp, char **arg, char *file, int pushed)
 
     if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
        if ((cp = context_find ("signature")) && *cp)
-           m_putenv ("SIGNATURE", cp);
+           setenv("SIGNATURE", cp, 1);
 
     if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
        annotext = NULL;
@@ -1231,14 +1202,11 @@ sendit (char *sp, char **arg, char *file, int pushed)
 
     if ((cp = getenv ("mhdist"))
            && *cp
-#ifndef lint
-           && (distsw = atoi (cp))
-#endif /* not lint */
+           && atoi(cp)
            && altmsg) {
        vec[vecp++] = "-dist";
        if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
+           adios(NULL, "unable to create temporary file");
        }
        distfile = mh_xstrdup(cp);
        (void) m_unlink(distfile);
@@ -1306,10 +1274,10 @@ whomfile (char **arg, char *file)
            execvp (program, vec);
            fprintf (stderr, "unable to exec ");
            perror (whomproc);
-           _exit (-1);         /* NOTREACHED */
+           _exit(1);           /* NOTREACHED */
 
        default:
-           return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
+           return pidwait(pid, NOTOK) & 0377 ? 1 : 0;
     }
 }
 
@@ -1336,18 +1304,19 @@ static int
 checkmimeheader (char *drft)
 {
     FILE *f;
-    m_getfld_state_t gstate = 0;
-    char buf[BUFSIZ], name[NAMESZ];
+    m_getfld_state_t gstate;
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     int state, retval = 0;
 
     if ((f = fopen(drft, "r")) == NULL) {
        admonish(drft, "unable to read draft");
-       return (0);
+       return 0;
     }
 
+    gstate = m_getfld_state_init(f);
     for (;;) {
        int bufsz = sizeof(buf);
-       switch (state = m_getfld(&gstate, name, buf, &bufsz, f)) {
+       switch (state = m_getfld2(&gstate, name, buf, &bufsz)) {
        case FLD:
        case FLDPLUS:
            if (strcasecmp(name, VRSN_FIELD) == 0) {