For the mhstore -clobber test, cd to the Mail subdirectory so that
[mmh] / uip / mhmail.c
index f9dc33b..6c5039c 100644 (file)
@@ -2,11 +2,15 @@
 /*
  * mhmail.c -- simple mail program
  *
- * $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 <h/mts.h>
 #include <h/signals.h>
+#include <h/utils.h>
 #include <signal.h>
 
 static struct swit switches[] = {
@@ -21,7 +25,7 @@ static struct swit switches[] = {
 #define VERSIONSW          4
     { "version", 0 },
 #define        HELPSW             5
-    { "help", 4 },
+    { "help", 0 },
 #define        RESNDSW            6
     { "resent", -6 },
 #define        QUEUESW            7
@@ -34,19 +38,21 @@ static char tmpfil[BUFSIZ];
 /*
  * static prototypes
  */
-static RETSIGTYPE intrser (int);
+static void intrser (int);
 
 
 int
 main (int argc, char **argv)
 {
     pid_t child_id;
-    int status, i, iscc = 0, nvec;
+    int status, iscc = 0, nvec;
+    size_t i;
     int queued = 0, resent = 0, somebody;
     char *cp, *tolist = NULL, *cclist = NULL, *subject = NULL;
     char *from = NULL, *body = NULL, **argp, **arguments;
     char *vec[5], buf[BUFSIZ];
     FILE *out;
+    char *tfile = NULL;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -79,10 +85,10 @@ main (int argc, char **argv)
                    snprintf (buf, sizeof(buf), "%s [addrs ... [switches]]",
                        invo_name);
                    print_help (buf, switches, 0);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version(invo_name);
-                   done (1);
+                   done (0);
 
                case FROMSW: 
                    if (!(from = *argp++) || *from == '-')
@@ -120,10 +126,11 @@ main (int argc, char **argv)
 
     if (tolist == NULL)
        adios (NULL, "usage: %s addrs ... [switches]", invo_name);
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((out = fopen (tmpfil, "w")) == NULL)
-       adios (tmpfil, "unable to write");
-    chmod (tmpfil, 0600);
+
+    tfile = m_mktemp2(NULL, invo_name, NULL, &out);
+    if (tfile == NULL) adios("mhmail", "unable to create temporary file");
+    chmod(tfile, 0600);
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     SIGNAL2 (SIGINT, intrser);
 
@@ -134,6 +141,8 @@ main (int argc, char **argv)
        fprintf (out, "%sSubject: %s\n", resent ? "Resent-" : "", subject);
     if (from)
        fprintf (out, "%sFrom: %s\n", resent ? "Resent-" : "", from);
+    else
+       fprintf (out, "From: %s\n", getlocalmbox ());
     if (!resent)
        fputs ("\n", out);
 
@@ -168,7 +177,7 @@ main (int argc, char **argv)
 
     if (child_id == NOTOK) {
        /* report failure and then send it */
-       admonish (NULL, "unable to fork");
+       adios (NULL, "unable to fork");
     } else if (child_id) {
        /* parent process */
        if ((status = pidXwait(child_id, postproc))) {
@@ -187,17 +196,14 @@ main (int argc, char **argv)
        perror (postproc);
        _exit (-1);
     }
+
+    return 0;  /* dead code to satisfy the compiler */
 }
 
 
-static RETSIGTYPE
+static void
 intrser (int i)
 {
-#ifndef RELIABLE_SIGNALS
-    if (i)
-       SIGNAL (i, SIG_IGN);
-#endif
-
     unlink (tmpfil);
     done (i != 0 ? 1 : 0);
 }