[bug #4302] errno is not always an extern int
[mmh] / uip / spost.c
index c5b27a0..5a7d943 100644 (file)
@@ -6,6 +6,10 @@
  * when "sendmail" is the transport system.
  *
  * $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>
@@ -13,7 +17,8 @@
 #include <h/addrsbr.h>
 #include <h/aliasbr.h>
 #include <h/dropsbr.h>
-#include <zotnet/tws/tws.h>
+#include <h/tws.h>
+#include <h/mts.h>
 
 #define        uptolow(c)      ((isalpha(c) && isupper (c)) ? tolower (c) : c)
 
@@ -54,7 +59,7 @@ struct swit switches[] = {
 #define VERSIONSW           15
     { "version", 0 },
 #define        HELPSW              16
-    { "help", 4 },
+    { "help", 0 },
 #define        DEBUGSW             17
     { "debug", -5 },
 #define        DISTSW              18
@@ -176,6 +181,8 @@ extern char *sendmail;
 extern char *getfullname (void);
 extern char *getusername (void);
 
+extern boolean  draft_from_masquerading;  /* defined in mts.c */
+
 /*
  * static prototypes
  */
@@ -347,13 +354,14 @@ main (int argc, char **argv)
     }
     else {
 #ifdef HAVE_MKSTEMP
-           mkstemp (tmpfil);
+           if ((out = fdopen( mkstemp (tmpfil), "w" )) == NULL )
+               adios (tmpfil, "unable to create");
 #else
            mktemp (tmpfil);
-#endif
            if ((out = fopen (tmpfil, "w")) == NULL)
                adios (tmpfil, "unable to create");
            chmod (tmpfil, 0600);
+#endif
        }
 
     hdrtab = (msgstate == normal) ? NHeaders : RHeaders;
@@ -454,6 +462,7 @@ main (int argc, char **argv)
     }
     execv ( sendmail, sargv);
     adios ( sendmail, "can't exec");
+    return 0;  /* dead code to satisfy the compiler */
 }
 
 /* DRAFT GENERATION */
@@ -489,7 +498,7 @@ putfmt (char *name, char *str, FILE *out)
     if (hdr->flags & HFCC) {
        if ((cp = strrchr(str, '\n')))
            *cp = 0;
-       for (cp = pp = str; cp = strchr(pp, ','); pp = cp) {
+       for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) {
            *cp++ = 0;
            insert_fcc (hdr, pp);
        }
@@ -504,7 +513,7 @@ putfmt (char *name, char *str, FILE *out)
     }
 #endif /* notdef */
 
-    if (*str != '\n' && *str != '\0')
+    if (*str != '\n' && *str != '\0') {
        if (aliasflg && hdr->flags & HTRY) {
            /* this header contains address(es) that we have to do
             * alias expansion on.  Because of the saved state in
@@ -529,8 +538,21 @@ putfmt (char *name, char *str, FILE *out)
            f = mp->m_next; mp->m_next = 0;
            putadr( name, f );
        } else {
+           /* The author(s) of spost decided that alias substitution wasn't
+              necessary for the non-HTRY headers.  Unfortunately, one of those
+              headers is "From:", and having alias substitution work on that is
+              extremely useful for someone with a lot of POP3 email accounts or
+              aliases.  post supports aliasing of "From:"...
+
+              Since "From:"-processing is incompletely implemented in this
+              unsupported and undocumented spost backend, I'm not going to take
+              the time to implement my new draft-From:-based email address
+              masquerading.  If I do ever implement it here, I'd almost
+              certainly want to implement "From:" line alias processing as
+              well.  -- Dan Harkless <dan-nmh@dilvish.speed.net> */
            fprintf (out, "%s: %s", name, str );
        }
+    }
 }
 
 
@@ -558,10 +580,19 @@ finish_headers (FILE *out)
        case normal: 
            if (!(msgflags & MDAT))
                fprintf (out, "Date: %s\n", dtimenow (0));
-           if (msgflags & MFRM)
-               fprintf (out, "Sender: %s\n", from);
+           
+           if (msgflags & MFRM) {
+               /* There was already a From: in the draft.  Don't add one. */
+               if (!draft_from_masquerading)
+                   /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
+                      so we'll reveal the user's actual account@thismachine
+                      address in a Sender: header (and use it as the envelope
+                      From: later). */
+                   fprintf (out, "Sender: %s\n", from);
+           }
            else
                fprintf (out, "From: %s\n", signature);
+          
 #ifdef notdef
            if (!(msgflags & MVIS))
                fprintf (out, "Bcc: Blind Distribution List: ;\n");
@@ -571,9 +602,17 @@ finish_headers (FILE *out)
        case resent: 
            if (!(msgflags & MRDT))
                fprintf (out, "Resent-Date: %s\n", dtimenow(0));
-           if (msgflags & MRFM)
-               fprintf (out, "Resent-Sender: %s\n", from);
+           if (msgflags & MRFM) {
+               /* There was already a Resent-From: in draft.  Don't add one. */
+               if (!draft_from_masquerading)
+                   /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
+                      so we'll reveal the user's actual account@thismachine
+                      address in a Sender: header (and use it as the envelope
+                      From: later). */
+                   fprintf (out, "Resent-Sender: %s\n", from);
+           }
            else
+               /* Construct a Resent-From: header. */
                fprintf (out, "Resent-From: %s\n", signature);
 #ifdef notdef
            if (!(msgflags & MVIS))
@@ -711,9 +750,15 @@ make_bcc_file (void)
     char *vec[6];
     FILE * in, *out;
 
+#ifdef HAVE_MKSTEMP
+    fd = mkstemp(bccfil);
+    if (fd == -1 || (out = fdopen(fd, "w")) == NULL)
+       adios (bccfil, "unable to create");
+#else
     mktemp (bccfil);
     if ((out = fopen (bccfil, "w")) == NULL)
        adios (bccfil, "unable to create");
+#endif
     chmod (bccfil, 0600);
 
     fprintf (out, "Date: %s\n", dtimenow (0));