From 2c4ac164edefd18861595ec7624e5ad344b10198 Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 2 Nov 2016 20:24:32 -0400 Subject: [PATCH] Replace non-ASCII characters in headers with ?'s with non-UTF8 locale. --- test/mhl/test-rfc6532 | 37 ++++++++++++++++++++++++------------- uip/mhlsbr.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/test/mhl/test-rfc6532 b/test/mhl/test-rfc6532 index 05dae7bc..378d41c0 100755 --- a/test/mhl/test-rfc6532 +++ b/test/mhl/test-rfc6532 @@ -81,19 +81,30 @@ Subject: Blåbærsy MIME-Version: 1.0' -# check with incompatible locale -# This is here as a place holder. We should either try to run the (8-bit) text -# through iconv, or refuse to display it if the locale is incompatible. In the -# case of EAI, that means not UTF-8. -# start_test 'incompatible locale' -# LC_ALL=C -# run_test "$mhl -form mhl.headers `mhpath last`" \ -# 'Date: 20 May 2014 14:28:51 +0200 -# To: recipientæ@example.com -# From: sender??@example.com -# Subject: Bl??b??rsyltet??y -# -# MIME-Version: 1.0' +start_test 'incompatible locale' +# Show that LC_CTYPE is sufficient, if LC_ALL is unset. +unset LC_ALL +LC_CTYPE=C +cat >"$MH_TEST_DIR/test.format" <c_flags |= FORCE7BIT; + } text = c1->c_text ? c1->c_text : c1->c_name; /* Create a copy with trailing whitespace trimmed, for use with @@ -1561,9 +1569,24 @@ putch (char ch, long flags) putchar ('-'); putchar (' '); } - if ((flags & INVISIBLE) == 0) { - /* If multibyte character, its first byte only. */ - ++column; + /* + * Increment the character count, unless + * 1) In UTF-8 locale, this is other than the last byte of + a multibyte character, or + * 2) In C locale, will print a non-printable character. + */ + if ((flags & FORCE7BIT) == 0) { + /* UTF-8 locale */ + if ((flags & INVISIBLE) == 0) { + /* If multibyte character, its first byte only. */ + ++column; + } + } else { + /* If not an ASCII character, the replace character will be + displayed. Count it. */ + if (! isascii((unsigned char) ch) || isprint((unsigned char) ch)) { + ++column; + } } break; } @@ -1577,7 +1600,11 @@ putch (char ch, long flags) return; } - putchar (ch); + if (flags & FORCE7BIT && ! isascii((unsigned char) ch)) { + putchar ('?'); + } else { + putchar (ch); + } } -- 2.56.0