[Commits] [SCM] claws branch, master, updated. 3.13.2-93-g73e0a2e

ticho at claws-mail.org ticho at claws-mail.org
Wed Mar 30 18:22:05 CEST 2016


The branch, master has been updated
       via  73e0a2e64074bab0b6abfde58fdf569b183dde5d (commit)
      from  57e0b0d5d8b901d82155af0a313ba7ab94b52173 (commit)

Summary of changes:
 src/common/utils.c |   42 ++++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)


- Log -----------------------------------------------------------------
commit 73e0a2e64074bab0b6abfde58fdf569b183dde5d
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Wed Mar 30 18:21:08 2016 +0200

    Rewrite unfold_line() to handle UTF8 line breaks.
    
    This closes bug #3629 - Invalid subject can distort
    message list view

diff --git a/src/common/utils.c b/src/common/utils.c
index ab063ce..5e24bc6 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -996,19 +996,37 @@ void remove_space(gchar *str)
 
 void unfold_line(gchar *str)
 {
-	register gchar *p = str;
-	register gint spc;
+	register gchar *ch;
+	register gunichar c;
+	register gint len;
 
-	while (*p) {
-		if (*p == '\n' || *p == '\r') {
-			*p++ = ' ';
-			spc = 0;
-			while (g_ascii_isspace(*(p + spc)))
-				spc++;
-			if (spc)
-				memmove(p, p + spc, strlen(p + spc) + 1);
-		} else
-			p++;
+	ch = str; /* iterator for source string */
+
+	while (*ch != 0) {
+		c = g_utf8_get_char_validated(ch, -1);
+
+		if (c < 0) {
+			/* non-unicode byte, move past it */
+			ch++;
+			continue;
+		}
+
+		len = g_unichar_to_utf8(c, NULL);
+
+		if (!g_unichar_isdefined(c) || !g_unichar_isprint(c) ||
+				g_unichar_isspace(c)) {
+			/* replace anything bad or whitespacey with a single space */
+			*ch = ' ';
+			ch++;
+			if (len > 1) {
+				/* move rest of the string forwards, since we just replaced
+				 * a multi-byte sequence with one byte */
+				memmove(ch, ch + len-1, strlen(ch + len-1) + 1);
+			}
+		} else {
+			/* A valid unicode character, copy it. */
+			ch += len;
+		}
 	}
 }
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list