]> diplodocus.org Git - nmh/commitdiff
Merge branch 'fix-post-bcc'
authorKen Hornstein <kenh@pobox.com>
Tue, 1 Aug 2017 17:22:36 +0000 (13:22 -0400)
committerKen Hornstein <kenh@pobox.com>
Tue, 1 Aug 2017 17:22:36 +0000 (13:22 -0400)
This branch fixes bug #51098; the lack of alias expansion on a From line
when doing a Bcc.  Admittedly, this is rather an obscure bug, and AFAICT
it never worked in any version of MH or nmh, but it is fixed now.

test/post/test-post-aliases
uip/post.c

index 8420aa3..bd9123e 100755 (executable)
@@ -22,6 +22,7 @@ named.list; one@example.com, two@example.com
 one: one@example.com
 two: two@example.com
 three: three@example.com
+four: Mister Four <four@example.com>
 EOF
 
 #### Rely on sendmail/smtp or sendmail/pipe below to override default mts.
@@ -158,5 +159,61 @@ EOF
 
 test_alias sendmail/pipe "${testname}.expected"
 
+# check that alias expansion happens in the From: line when doing a bcc
+cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
+From: four
+To: one
+Bcc: two
+Subject: from bcc expansion test
+
+This is test of from line expansion for a bcc.
+EOF
+
+cat >"${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<four@example.com>
+RCPT TO:<one@example.com>
+RCPT TO:<two@example.com>
+RSET
+MAIL FROM:<four@example.com>
+RCPT TO:<one@example.com>
+DATA
+From: Mister Four <four@example.com>
+To: one@example.com
+Subject: from bcc expansion test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Date:
+
+This is test of from line expansion for a bcc.
+.
+RSET
+MAIL FROM:<four@example.com>
+RCPT TO:<two@example.com>
+DATA
+From: Mister Four <four@example.com>
+Date:
+Subject: from bcc expansion test
+BCC:
+
+------- Blind-Carbon-Copy
+
+From: Mister Four <four@example.com>
+To: one@example.com
+Subject: from bcc expansion test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Date:
+
+This is test of from line expansion for a bcc.
+
+------- End of Blind-Carbon-Copy
+.
+QUIT
+EOF
+
+test_post "${testname}.actual" "${testname}.expected" \
+  "-alias ${MH_TEST_DIR}/Mail/aliases"
+
 
 exit ${failed:-0}
index 81bd7b4..9282a71 100644 (file)
@@ -291,7 +291,8 @@ static void putfmt (char *, char *, int *, FILE *);
 static void start_headers (void);
 static void finish_headers (FILE *);
 static int get_header (char *, struct headers *);
-static int putadr (char *, char *, struct mailname *, FILE *, unsigned int);
+static int putadr (char *, char *, struct mailname *, FILE *, unsigned int,
+                  char *, unsigned int);
 static void putgrp (char *, char *, FILE *, unsigned int);
 static int insert (struct mailname *);
 static void pl (void);
@@ -790,6 +791,8 @@ putfmt (char *name, char *str, int *eai, FILE *out)
     int count, grp, i, keep;
     char *cp, *pp, *qp;
     char namep[BUFSIZ], error[BUFSIZ];
+    char *savehdr = NULL;
+    unsigned int savehdrlen = 0;
     struct mailname *mp = NULL, *np = NULL;
     struct headers *hdr;
 
@@ -873,6 +876,19 @@ putfmt (char *name, char *str, int *eai, FILE *out)
        return;
     }
 
+    /*
+     * If this is a From:/Resent-From: header, save the full thing for
+     * later in case we need it for use when constructing a Bcc draft message.
+     * Because we want to capture the results of alias expansion, save
+     * the output from putadr().
+     */
+
+    if ((msgstate == RESENT) ? (hdr->set & MRFM) : (hdr->set & MFRM)) {
+       savehdr = fullfrom;
+       savehdr[0] = '\0';
+       savehdrlen = sizeof(fullfrom);
+    }
+
     tmpaddrs.m_next = NULL;
 
     for (count = 0; (cp = getname (str)); count++) {
@@ -992,7 +1008,8 @@ putfmt (char *name, char *str, int *eai, FILE *out)
 
                    grp++;
                }
-               if (putadr (namep, qp, mp, out, hdr->flags))
+               if (putadr (namep, qp, mp, out, hdr->flags, savehdr,
+                           savehdrlen))
                    msgflags |= (hdr->set & (MVIS | MINV));
                else
                    mnfree (mp);
@@ -1041,7 +1058,7 @@ putfmt (char *name, char *str, int *eai, FILE *out)
                putgrp (namep, mp->m_gname, out, hdr->flags);
            if (mp->m_ingrp)
                grp++;
-           keep = putadr (namep, "", mp, out, hdr->flags);
+           keep = putadr (namep, "", mp, out, hdr->flags, savehdr, savehdrlen);
            np = mp->m_next;
            if (keep) {
                mp->m_next = NULL;
@@ -1052,17 +1069,11 @@ putfmt (char *name, char *str, int *eai, FILE *out)
        }
 
     /*
-     * If this is a From:/Resent-From: header, save the full thing for
-     * later in case we need it for use when constructing a Bcc draft message
+     * If it was a From header, strip off any trailing newlines from
+     * the alias-expanded From line.
      */
 
     if ((msgstate == RESENT) ? (hdr->set & MRFM) : (hdr->set & MFRM)) {
-       strncpy(fullfrom, str, sizeof(fullfrom));
-       fullfrom[sizeof(fullfrom) - 1] = 0;
-       /*
-        * Strip off any trailing newlines
-        */
-
        while (*fullfrom && fullfrom[strlen(fullfrom) - 1] == '\n') {
            fullfrom[strlen(fullfrom) - 1] = '\0';
        }
@@ -1221,9 +1232,11 @@ get_header (char *header, struct headers *table)
 
 
 static int
-putadr (char *name, char *aka, struct mailname *mp, FILE *out, unsigned int flags)
+putadr (char *name, char *aka, struct mailname *mp, FILE *out,
+       unsigned int flags, char *savehdr, unsigned int savehdrsize)
 {
-    int len;
+    int len, saveappend = 0;
+    unsigned int shlen;
     char *cp;
     char buffer[BUFSIZ];
 
@@ -1238,6 +1251,11 @@ putadr (char *name, char *aka, struct mailname *mp, FILE *out, unsigned int flag
        linepos += (nameoutput = strlen (name) + 2);
     }
 
+    if (savehdr) {
+       shlen = strlen(savehdr);
+       saveappend = 1;
+    }
+
     if (*aka && mp->m_type != UUCPHOST && !mp->m_pers)
        mp->m_pers = mh_xstrdup(aka);
     if (format) {
@@ -1253,15 +1271,34 @@ putadr (char *name, char *aka, struct mailname *mp, FILE *out, unsigned int flag
     len = strlen (cp);
 
     if (linepos != nameoutput) {
-       if (len + linepos + 2 > outputlinelen)
+       if (len + linepos + 2 > outputlinelen) {
            fprintf (out, ",\n%*s", linepos = nameoutput, "");
-       else {
+           if (saveappend) {
+               if (shlen + 2 + nameoutput + len >= savehdrsize) {
+                   saveappend = 0;
+               } else {
+                   snprintf(savehdr + shlen, savehdrsize - shlen, ",\n%*s",
+                            linepos, "");
+               }
+           }
+       } else {
            fputs (", ", out);
            linepos += 2;
+           if (saveappend) {
+               if (shlen + 2 + len >= savehdrsize) {
+                   saveappend = 0;
+               } else {
+                   strncat(savehdr, ", ", savehdrsize - shlen);
+               }
+           }
        }
     }
 
     fputs (cp, out);
+
+    if (saveappend && shlen + len < savehdrsize)
+       strncat(savehdr, cp, savehdrsize - shlen + len);
+
     linepos += len;
 
     return (flags & HTRY);