]> diplodocus.org Git - nmh/commitdiff
Fixed display of header field values with multibyte characters.
authorDavid Levine <levinedl@acm.org>
Thu, 3 Nov 2016 00:08:27 +0000 (20:08 -0400)
committerDavid Levine <levinedl@acm.org>
Thu, 3 Nov 2016 00:08:27 +0000 (20:08 -0400)
test/mhl/test-rfc6532
uip/mhlsbr.c

index 978f291..05dae7b 100755 (executable)
@@ -22,11 +22,14 @@ mhl="${MH_LIBEXEC_DIR}/mhl"
 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
 
 
-# check UTF-8 headers
 start_test 'UTF-8 headers'
-cat >"$MH_TEST_DIR"/Mail/inbox/11 <<EOF
-From: senderø@example.com
+#### The -- position the multibyte characters to check edge
+#### cases in the 'UTF-8 headers with narrow width' test below.
+cat >`mhpath new` <<EOF
+From: sender--ø@example.com
 To: recipientæ@example.com
+To: recipient2@example.com
+Cc: recip--æ@example.com
 Subject: Blåbærsyltetøy
 Date: 20 May 2014 14:28:51 +0200
 MIME-Version: 1.0
@@ -46,13 +49,38 @@ EOF
 #### squashes the trailing blank lines from mhl.
 run_test "$mhl -form mhl.headers `mhpath last`" \
 'Date:    20 May 2014 14:28:51 +0200
-To:      recipientæ@example.com
-From:    senderø@example.com
+To:      recipientæ@example.com,
+        recipient2@example.com
+cc:      recip--æ@example.com
+From:    sender--ø@example.com
 Subject: Blåbærsyltetøy
 
 MIME-Version: 1.0'
 
 
+start_test 'UTF-8 headers with narrow width'
+run_test "$mhl -form mhl.headers -width 18 `mhpath last`" \
+'Date:    20 May 2
+     ***014 14:28
+     ***:51 +0200
+To:      recipien
+     ***tæ@exampl
+     ***e.com,
+        recipien
+     ***t2@exampl
+     ***e.com
+cc:      recip--æ
+     ***@example.
+     ***com
+From:    sender--
+     ***ø@example
+     ***.com
+Subject: Blåbærsy
+     ***ltetøy
+
+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
index f3f518e..5a6401e 100644 (file)
@@ -93,7 +93,8 @@ DEFINE_SWITCH_ARRAY(MHL, mhlswitches);
 #define        NONEWLINE   0x020000    /* don't write trailing newline      */
 #define NOWRAP      0x040000   /* Don't wrap lines ever             */
 #define FMTFILTER   0x080000   /* Filter through format filter      */
-#define        LBITS   "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017RTRIM\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER"
+#define INVISIBLE   0x100000   /* count byte in display columns?    */
+#define        LBITS   "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017RTRIM\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER\025INVISIBLE"
 #define        GFLAGS  (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT | NOWRAP)
 
 /*
@@ -1459,6 +1460,10 @@ oneline (char *stuff, long flags)
 static void
 putstr (char *string, long flags)
 {
+    /* To not count, for the purpose of counting columns, all of
+       the bytes of a multibyte character. */
+    int char_len;
+
     if (!column && lm > 0) {
        while (lm > 0)
            if (lm >= 8) {
@@ -1471,8 +1476,33 @@ putstr (char *string, long flags)
            }
     }
     lm = 0;
-    while (*string)
-       putch (*string++, flags);
+
+#ifdef MULTIBYTE_SUPPORT
+    (void) mbtowc (NULL, NULL, 0); /* reset shift state */
+    char_len = 0;
+#else
+    NMH_UNUSED (char_len);
+#endif
+
+    while (*string) {
+        flags &= ~INVISIBLE;
+#ifdef MULTIBYTE_SUPPORT
+        /* mbtowc should never return 0, because *string is non-NULL. */
+        if (char_len <= 0) {
+            /* Find number of bytes in next character. */
+            if ((char_len =
+                 mbtowc (NULL, string, (size_t) MB_CUR_MAX)) == -1) {
+                char_len = 1;
+            }
+        } else {
+            /* Multibyte character, after the first byte. */
+            flags |= INVISIBLE;
+        }
+
+        --char_len;
+#endif
+        putch (*string++, flags);
+    }
 }
 
 
@@ -1531,8 +1561,10 @@ putch (char ch, long flags)
                putchar ('-');
                putchar (' ');
            }
-           if (ch >= ' ')
-               column++;
+            if ((flags & INVISIBLE) == 0) {
+                /* If multibyte character, its first byte only. */
+                ++column;
+            }
            break;
     }