]> diplodocus.org Git - nmh/blobdiff - uip/whom.c
Simplified m_strn() per Ralph's suggestions.
[nmh] / uip / whom.c
index 862fc58c7cd82f927e0355d3b5c229fb754fea8e..efa74c63d0a1fd6555f1db3cb3499b3c6453782b 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * whom.c -- report to whom a message would be sent
+/* whom.c -- report to whom a message would be sent
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -8,8 +6,10 @@
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 #include <h/signals.h>
-#include <signal.h>
+#include "../sbr/m_maildir.h"
+#include "../sbr/m_mktemp.h"
 
 #ifndef CYRUS_SASL
 # define SASLminc(a) (a)
@@ -34,8 +34,8 @@
     X("version", 0, VERSIONSW) \
     X("help", 0, HELPSW) \
     X("client host", -6, CLIESW) \
-    X("server host", -6, SERVSW) \
-    X("snoop", -5, SNOOPSW) \
+    X("server host", 0, SERVSW) \
+    X("snoop", 0, SNOOPSW) \
     X("sasl", SASLminc(4), SASLSW) \
     X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
     X("user username", SASLminc(-4), USERSW) \
@@ -57,20 +57,14 @@ DEFINE_SWITCH_ARRAY(WHOM, switches);
 int
 main (int argc, char **argv)
 {
-    pid_t child_id;
+    pid_t child_id = OK;
     int i, status, isdf = 0;
     int distsw = 0, vecp = 0;
     char *cp, *dfolder = NULL, *dmsg = NULL;
     char *msg = NULL, **ap, **argp, backup[BUFSIZ];
     char buf[BUFSIZ], **arguments, *vec[MAXARGS];
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -157,16 +151,13 @@ main (int argc, char **argv)
     if ((cp = context_find ("Aliasfile"))) {
        char *dp = NULL;
 
-       for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
+       for (ap = brkstring(dp = mh_xstrdup(cp), " ", "\n"); ap && *ap; ap++) {
            vec[vecp++] = "-alias";
            vec[vecp++] = *ap;
        }
     }
 
     if (msg == NULL) {
-#ifdef WHATNOW
-       if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == '\0')
-#endif /* WHATNOW */
            cp  = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
        msg = vec[vecp++] = cp;
     }
@@ -191,7 +182,8 @@ main (int argc, char **argv)
 
     switch (distsw ? child_id : OK) {
        case NOTOK:
-           advise (NULL, "unable to fork, so checking directly...");
+           inform("unable to fork, so checking directly...");
+           /* FALLTHRU */
        case OK:
            execvp (postproc, vec);
            fprintf (stderr, "unable to exec ");
@@ -206,7 +198,7 @@ main (int argc, char **argv)
 
            status = pidwait(child_id, OK);
 
-           unlink (msg);
+           (void) m_unlink (msg);
            if (rename (backup, msg) == NOTOK)
                adios (msg, "unable to rename %s to", backup);
            done (status);