]> diplodocus.org Git - nmh/commitdiff
Cleanup MIME header handling in mhbuild
authorKen Hornstein <kenh@pobox.com>
Mon, 13 May 2019 00:07:56 +0000 (20:07 -0400)
committerKen Hornstein <kenh@pobox.com>
Mon, 13 May 2019 00:08:27 +0000 (20:08 -0400)
Per discussion on nmh-workers, cleanup the handling of MIME headers
in mhbuild.  The following logic should now apply.

If mhbuild is run with -auto AND a MIME-Version header is detected, then
exit silently with no error (and leave the draft untouched).  Otherwise,
if a MIME-Version header or ANY Content-* header is found, exit with an
error.  Note that this means if mhbuild is run with -auto then an error
will be returned if any Content-* headers are seen.

Previously, mhbuild would silently eat any Content-Type headers seen
in an existing draft; this behavior was brought forward from MH 6 and
no one could explain the reason for this behavior.  This behavior has
been removed.

man/mhbuild.man
test/mhbuild/test-mhbuild
uip/mhbuildsbr.c

index 46a0507..47d9f87 100644 (file)
@@ -969,13 +969,24 @@ Template for composing contents.
 (RFC 6531)
 .SH DEFAULTS
 .nf
+\-noauto
 \-autoheaderencoding
 \-contentid
 \-headers
 \-maxunencoded 78
-\-nocheck
 \-nodisposition
 \-norfc934mode
 \-noverbose
 \-realsize
+.SH DEFAULTS (with \-auto)
+.nf
+\-autoheaderencoding
+\-contentid
+\-headers
+\-maxunencoded 78
+\-nodisposition
+\-norfc934mode
+\-noverbose
+\-realsize
+\-nodirectives
 .fi
index 8d08661..6f69080 100755 (executable)
@@ -36,6 +36,113 @@ EOF
 run_test "mhbuild -nodirectives `mhpath last`"
 check "`mhpath last`" "$expected"
 
+start_test "Checking for MIME-Version handling in draft"
+
+cat > "`mhpath new`" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+MIME-Version: 1.0
+--------
+This is a test
+EOF
+
+cat >"$expected" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+MIME-Version: 1.0
+--------
+This is a test
+EOF
+
+run_test "mhbuild `mhpath last`" "mhbuild: draft shouldn't contain MIME-Version: field"
+check "`mhpath last`" "$expected" 'keep first'
+
+cat >"$expected" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+MIME-Version: 1.0
+--------
+This is a test
+EOF
+
+run_test "mhbuild -auto `mhpath last`"
+check "`mhpath last`" "$expected"
+
+start_test "Checking for arbitrary Content header handling in draft"
+
+cat > "`mhpath new`" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+Content-Fart: nothing
+--------
+This is a test
+EOF
+
+cat >"$expected" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+Content-Fart: nothing
+--------
+This is a test
+EOF
+
+run_test "mhbuild `mhpath last`" "mhbuild: draft shouldn't contain Content-Fart: field"
+check "`mhpath last`" "$expected" 'keep first'
+
+cat >"$expected" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+Content-Fart: nothing
+--------
+This is a test
+EOF
+
+run_test "mhbuild -auto `mhpath last`" "mhbuild: draft shouldn't contain Content-Fart: field"
+check "`mhpath last`" "$expected"
+
+start_test "Checking for out-of-order Content header handling in draft"
+
+cat > "`mhpath new`" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+Content-Fart: nothing
+MIME-Version: 1.0
+--------
+This is a test
+EOF
+
+cat >"$expected" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+Content-Fart: nothing
+MIME-Version: 1.0
+--------
+This is a test
+EOF
+
+run_test "mhbuild `mhpath last`" "mhbuild: draft shouldn't contain MIME-Version: field"
+check "`mhpath last`" "$expected" 'keep first'
+
+cat >"$expected" <<'EOF'
+From: Somebody <somebody@example.com>
+To: Nobody <nobody@example.com>
+Subject: Test message
+Content-Fart: nothing
+MIME-Version: 1.0
+--------
+This is a test
+EOF
+
+run_test "mhbuild -auto `mhpath last`"
+check "`mhpath last`" "$expected"
 
 finish_test
 exit $failed
index 04dc4a7..b96e63a 100644 (file)
@@ -190,9 +190,20 @@ build_mime (char *infile, int autobuild, int dist, int directives,
        case FLDPLUS:
            compnum++;
 
-           /* abort if draft has Mime-Version or C-T-E header field */
-           if (strcasecmp (name, VRSN_FIELD) == 0 ||
-               strcasecmp (name, ENCODING_FIELD) == 0) {
+           /*
+            * If we are running with autobuild set, then silently
+            * exit if we find a MIME-Version header.  For any other MIME
+            * header, return an error.
+            *
+            * RFC 2045, Section 9 says that any valid MIME header should
+            * start with "Content-", so we will match on that rather than
+            * enumerate all current MIME headers.
+            *
+            * Because the headers could be in any order, just check for
+            * MIME-Version here; check for Content-* later.
+            */
+
+           if (strcasecmp (name, VRSN_FIELD) == 0) {
                if (autobuild) {
                    fclose(in);
                    free (ct);
@@ -201,15 +212,6 @@ build_mime (char *infile, int autobuild, int dist, int directives,
                 die("draft shouldn't contain %s: field", name);
            }
 
-           /* ignore any Content-Type fields in the header */
-           if (!strcasecmp (name, TYPE_FIELD)) {
-               while (state == FLDPLUS) {
-                   bufsz = sizeof buf;
-                   state = m_getfld2(&gstate, name, buf, &bufsz);
-               }
-               goto finish_field;
-           }
-
            /* get copies of the buffers */
            np = mh_xstrdup(name);
            vp = mh_xstrdup(buf);
@@ -365,6 +367,16 @@ finish_field:
     }
     m_getfld_state_destroy (&gstate);
 
+    /*
+     * If we see any Content-* headers at this point, it is an error.
+     */
+
+    for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) {
+       if (uprf (hp->name, "Content-")) {
+           die ("draft shouldn't contain %s: field", hp->name);
+       }
+    }
+
     if (header_encoding != CE_8BIT) {
         /*
          * Iterate through the list of headers and call the function to MIME-ify