From: Ken Hornstein Date: Sun, 8 Jun 2014 03:14:12 +0000 (-0400) Subject: Return an appropriate error if the input characters are 8-bit, but the X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/c3bb80a82ee1c5f74fbd38e870af591227ac2de3?ds=sidebyside;hp=6b1962e92b9a3bfc7570aecb844fe67141fb87d7 Return an appropriate error if the input characters are 8-bit, but the locale character set is US-ASCII. --- diff --git a/test/mhbuild/test-ext-params b/test/mhbuild/test-ext-params index adde9d95..0b5e66da 100755 --- a/test/mhbuild/test-ext-params +++ b/test/mhbuild/test-ext-params @@ -157,7 +157,6 @@ This is a test message EOF run_prog mhbuild "$draft" -rm -f "$MH_TEST_DIR/tïny.jpg" cat > "$expected" < @@ -183,6 +182,31 @@ EOF 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" < +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 # diff --git a/test/mhbuild/test-utf8-body b/test/mhbuild/test-utf8-body index 650133c9..13629706 100755 --- a/test/mhbuild/test-utf8-body +++ b/test/mhbuild/test-utf8-body @@ -16,6 +16,8 @@ fi 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 @@ -124,6 +126,31 @@ EOF 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" < +To: Somebody +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" <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", - contains8bit ? write_charset_8bit() : "us-ascii", 0); + contains8bit ? eightbitcharset : "us-ascii", 0); + t->tx_charset = CHARSET_SPECIFIED; } } diff --git a/uip/mhparse.c b/uip/mhparse.c index 6e16a5aa..75414667 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -3851,8 +3851,12 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont, * add them now. */ - if (! pm->pm_charset) + if (! pm->pm_charset) { 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 */