talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 315a839750c45604226cfc0c6695f5a0e421d881
parent 2392a32a5c57acaa7c17a0a7bc19781f091d35fc
Author: Michael Rasmussen <mir@datanom.net>
Date:   Tue,  3 Jul 2012 22:43:04 +0000

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)

Diffstat:
MChangeLog | 7+++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/procmime.c | 40+++++++++++++++++++++++++++++++---------
4 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,10 @@ +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) + 2012-07-03 [mir] 3.8.1cvs4 * src/procmime.c diff --git a/PATCHSETS b/PATCHSETS @@ -4379,3 +4379,4 @@ ( cvs diff -u -r 1.94.2.233 -r 1.94.2.234 src/messageview.c; cvs diff -u -r 1.49.2.142 -r 1.49.2.143 src/procmime.c; cvs diff -u -r 1.3.2.17 -r 1.3.2.18 src/common/quoted-printable.c; cvs diff -u -r 1.3.2.9 -r 1.3.2.10 src/common/quoted-printable.h; ) > 3.8.1cvs2.patchset ( cvs diff -u -r 1.49.2.143 -r 1.49.2.144 src/procmime.c; cvs diff -u -r 1.9.2.54 -r 1.9.2.55 src/common/defs.h; ) > 3.8.1cvs3.patchset ( cvs diff -u -r 1.49.2.143 -r 1.49.2.144 src/procmime.c; cvs diff -u -r 1.9.2.54 -r 1.9.2.55 src/common/defs.h; ) > 3.8.1cvs4.patchset +( cvs diff -u -r 1.49.2.144 -r 1.49.2.145 src/procmime.c; ) > 3.8.1cvs5.patchset diff --git a/configure.ac b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=8 MICRO_VERSION=1 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=4 +EXTRA_VERSION=5 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/procmime.c b/src/procmime.c @@ -1199,11 +1199,12 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *ha { 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 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *ha 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 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *ha 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;