]> diplodocus.org Git - nmh/commitdiff
Return an appropriate error if the input characters are 8-bit, but the
authorKen Hornstein <kenh@pobox.com>
Sun, 8 Jun 2014 03:14:12 +0000 (23:14 -0400)
committerKen Hornstein <kenh@pobox.com>
Sun, 8 Jun 2014 03:14:12 +0000 (23:14 -0400)
locale character set is US-ASCII.

test/mhbuild/test-ext-params
test/mhbuild/test-utf8-body
uip/mhbuildsbr.c
uip/mhparse.c

index adde9d958da27bf0fba2e8c2f7c0f4833b0695b2..0b5e66dabe5e15331c489ef44acd0869268ea631 100755 (executable)
@@ -157,7 +157,6 @@ This is a test message
 EOF
 
 run_prog mhbuild "$draft"
 EOF
 
 run_prog mhbuild "$draft"
-rm -f "$MH_TEST_DIR/tïny.jpg"
 
 cat > "$expected" <<EOF
 To: Mr Test <mrtest@example.com>
 
 cat > "$expected" <<EOF
 To: Mr Test <mrtest@example.com>
@@ -183,6 +182,31 @@ EOF
 
 check "$draft" "$expected"
 
 
 check "$draft" "$expected"
 
+#
+# Test to make sure things fail if we try to put 8-bit characters when the
+# locale is US-ASCII
+#
+
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+------
+This is a test message
+#image/jpeg {attachment} $MH_TEST_DIR/tïny.jpg
+EOF
+
+old_locale="$LC_ALL"
+LC_ALL=C; export LC_ALL
+
+set +e
+run_test 'eval mhbuild "$draft" 2>&1' 'mhbuild: 8-bit characters in parameter "filename", but local character set is US-ASCII'
+set -e
+
+LC_ALL="$old_locale"; export LC_ALL
+
+rm -f "$MH_TEST_DIR/tïny.jpg"
+
 #
 # Test out message/external-body decoding
 #
 #
 # Test out message/external-body decoding
 #
index 650133c9bd2ff3bc2c398d105ac899de29f012ff..13629706c60cd101a96fd077c59412139693728f 100755 (executable)
@@ -16,6 +16,8 @@ fi
 
 setup_test
 testname="${MH_TEST_DIR}/$$"
 
 setup_test
 testname="${MH_TEST_DIR}/$$"
+expected="$MH_TEST_DIR/$$.expected"
+actual="$MH_TEST_DIR/$$.actual"
 
 LC_ALL=en_US.UTF-8; export LC_ALL
 
 
 LC_ALL=en_US.UTF-8; export LC_ALL
 
@@ -124,6 +126,31 @@ EOF
 
 test_attachment "${testname}.expected"
 
 
 test_attachment "${testname}.expected"
 
+# Repeat the previous test, but make sure that the locale is set to C, which 
+# should cause mhbuild to fail
+
+cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody <somebody@example.com>
+Subject: Test
+Attach: $MH_TEST_DIR/attachment.txt
+
+¡Ay, caramba!
+EOF
+
+LC_ALL="C"; export LC_ALL
+
+set +e
+run_prog send -draft -mts sendmail/pipe > "$actual" 2>&1
+set -e
+
+cat > "$expected" <<EOF
+mhbuild: Text content contains 8 bit characters, but character set is US-ASCII
+${MH_INST_DIR}${bindir}/mhbuild: exit 1
+EOF
+
+check "$expected" "$actual"
+
 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
 
 exit ${failed:-0}
 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
 
 exit ${failed:-0}
index 19d31316adff6e56f1d304e32f5485b197430ce2..7776333781cb879144e2ae068af318c340789e96 100644 (file)
@@ -1476,9 +1476,16 @@ scan_content (CT ct, size_t maxunencoded)
        t = (struct text *) ct->c_ctparams;
        if (t->tx_charset == CHARSET_UNSPECIFIED) {
            CI ci = &ct->c_ctinfo;
        t = (struct text *) ct->c_ctparams;
        if (t->tx_charset == CHARSET_UNSPECIFIED) {
            CI ci = &ct->c_ctinfo;
+           char *eightbitcharset = write_charset_8bit();
+
+           if (contains8bit && strcasecmp(eightbitcharset, "US-ASCII") == 0) {
+               adios(NULL, "Text content contains 8 bit characters, but "
+                     "character set is US-ASCII");
+           }
 
            add_param(&ci->ci_first_pm, &ci->ci_last_pm, "charset",
 
            add_param(&ci->ci_first_pm, &ci->ci_last_pm, "charset",
-                       contains8bit ? write_charset_8bit() : "us-ascii", 0);
+                       contains8bit ? eightbitcharset : "us-ascii", 0);
+
            t->tx_charset = CHARSET_SPECIFIED;
        }
     }
            t->tx_charset = CHARSET_SPECIFIED;
        }
     }
index 6e16a5aa613b9ecd66a36d13c2f3daad56decc77..754146674fbe71f88ec7da757133d2956304ed61 100644 (file)
@@ -3851,8 +3851,12 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont,
         * add them now.
         */
 
         * add them now.
         */
 
-       if (! pm->pm_charset)
+       if (! pm->pm_charset) {
            pm->pm_charset = getcpy(write_charset_8bit());
            pm->pm_charset = getcpy(write_charset_8bit());
+           if (strcasecmp(pm->pm_charset, "US-ASCII") == 0)
+               adios(NULL, "8-bit characters in parameter \"%s\", but "
+                     "local character set is US-ASCII", pm->pm_name);
+       }
        if (! pm->pm_lang)
            pm->pm_lang = getcpy(NULL); /* Default to a blank lang tag */
 
        if (! pm->pm_lang)
            pm->pm_lang = getcpy(NULL); /* Default to a blank lang tag */