[Commits] procmime.c 1.49.2.144 1.49.2.145

miras at claws-mail.org miras at claws-mail.org
Wed Jul 4 00:43:05 CEST 2012


Update of /home/claws-mail/claws/src
In directory srv:/tmp/cvs-serv7891/src

Modified Files:
      Tag: gtk2
	procmime.c 
Log Message:
2012-07-03 [mir]	3.8.1cvs5

	* src/procmime.c
	    fix bug 2642, 'improve transfer encoding selection'.
	    Patch provided by Christopher Zimmermann
	    (madroach claws at gmerlin dot de)

Index: procmime.c
===================================================================
RCS file: /home/claws-mail/claws/src/procmime.c,v
retrieving revision 1.49.2.144
retrieving revision 1.49.2.145
diff -u -d -r1.49.2.144 -r1.49.2.145
--- procmime.c	3 Jul 2012 21:33:32 -0000	1.49.2.144
+++ procmime.c	3 Jul 2012 22:43:02 -0000	1.49.2.145
@@ -1199,11 +1199,12 @@
 {
 	FILE *fp;
 	guchar buf[BUFFSIZE];
+	gboolean cr = FALSE;
 	size_t len;
+	gint linelen = 0, maxlinelen = 0;
 	size_t octet_chars = 0;
 	size_t total_len = 0;
 	gfloat octet_percentage;
-	gboolean force_b64 = FALSE;
 
 	if ((fp = g_fopen(file, "rb")) == NULL) {
 		FILE_OP_ERROR(file, "fopen");
@@ -1215,11 +1216,27 @@
 		gint i;
 
 		for (p = buf, i = 0; i < len; ++p, ++i) {
-			if (*p & 0x80)
-				++octet_chars;
-			if (*p == '\0') {
-				force_b64 = TRUE;
+			switch (*p) {
+			case '\n':
+				if (cr) linelen--;
+				maxlinelen = MAX(linelen, maxlinelen);
+				linelen = 0;
+				cr = FALSE;
+				break;
+			case '\r':
+				cr = TRUE;
+				linelen++;
+				break;
+			case '\0':
 				*has_binary = TRUE;
+				maxlinelen = G_MAXINT;
+				cr = FALSE;
+				break;
+			default:
+				if (*p & 0x80)
+					octet_chars++;
+				linelen++;
+				cr = FALSE;
 			}
 		}
 		total_len += len;
@@ -1233,15 +1250,20 @@
 		octet_percentage = 0.0;
 
 	debug_print("procmime_get_encoding_for_text_file(): "
-		    "8bit chars: %zd / %zd (%f%%)\n", octet_chars, total_len,
-		    100.0 * octet_percentage);
+		    "8bit chars: %zd / %zd (%f%%). "
+		    "maximum line length: %d chars\n",
+		    octet_chars, total_len, 100.0 * octet_percentage,
+		    maxlinelen);
 
-	if (octet_percentage > 0.20 || force_b64) {
+	if (octet_percentage > 0.20) {
 		debug_print("using BASE64\n");
 		return ENC_BASE64;
-	} else if (octet_chars > 0) {
+	} else if (maxlinelen > MAXSMTPTEXTLEN-2) {
 		debug_print("using quoted-printable\n");
 		return ENC_QUOTED_PRINTABLE;
+	} else if (octet_chars > 0) {
+		debug_print("using 8bit\n");
+		return ENC_8BIT;
 	} else {
 		debug_print("using 7bit\n");
 		return ENC_7BIT;



More information about the Commits mailing list