From 452b4d0d24debfff5376fe61f3673e712872847a Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Tue, 10 Jul 2012 21:13:07 +0000 Subject: [PATCH] 2012-07-10 [paul] 3.8.1cvs13 * src/messageview.c * src/common/defs.h * src/common/quoted-printable.c * src/common/quoted-printable.h revert 3.8.1cvs2,3,4,5 because they (somewhere!) cause the bug: partial message text loss --- ChangeLog | 9 +++ PATCHSETS | 1 + configure.ac | 2 +- src/common/defs.h | 3 - src/common/quoted-printable.c | 115 +++++++++++++++------------------- src/common/quoted-printable.h | 12 ---- src/messageview.c | 5 +- 7 files changed, 63 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a1d22783..e3f72c6db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-07-10 [paul] 3.8.1cvs13 + + * src/messageview.c + * src/common/defs.h + * src/common/quoted-printable.c + * src/common/quoted-printable.h + revert 3.8.1cvs2,3,4,5 because they (somewhere!) cause + the bug: partial message text loss + 2012-07-10 [mones] 3.8.1cvs12 * src/plugins/pgpcore/sgpgme.c diff --git a/PATCHSETS b/PATCHSETS index a18cbf153..20511e1c9 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -4387,3 +4387,4 @@ ( cvs diff -u -r 1.1.2.23 -r 1.1.2.24 src/gtk/icon_legend.c; ) > 3.8.1cvs10.patchset ( cvs diff -u -r 1.1.2.70 -r 1.1.2.71 src/plugins/pgpcore/sgpgme.c; ) > 3.8.1cvs11.patchset ( cvs diff -u -r 1.1.2.71 -r 1.1.2.72 src/plugins/pgpcore/sgpgme.c; ) > 3.8.1cvs12.patchset +( cvs diff -u -r 1.94.2.234 -r 1.94.2.235 src/messageview.c; cvs diff -u -r 1.9.2.57 -r 1.9.2.58 src/common/defs.h; cvs diff -u -r 1.3.2.18 -r 1.3.2.19 src/common/quoted-printable.c; cvs diff -u -r 1.3.2.10 -r 1.3.2.11 src/common/quoted-printable.h; ) > 3.8.1cvs13.patchset diff --git a/configure.ac b/configure.ac index 21db9c696..2812c9c00 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=8 MICRO_VERSION=1 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=12 +EXTRA_VERSION=13 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/common/defs.h b/src/common/defs.h index e006a1436..f7bccce96 100644 --- a/src/common/defs.h +++ b/src/common/defs.h @@ -148,9 +148,6 @@ #define BUFFSIZE 8192 -/* according to RFC 821 1000 characters including CRLF */ -#define MAXSMTPTEXTLEN 1000 - #ifndef MAXPATHLEN # define MAXPATHLEN 4095 #endif diff --git a/src/common/quoted-printable.c b/src/common/quoted-printable.c index dcc637d66..dd0a6bb59 100644 --- a/src/common/quoted-printable.c +++ b/src/common/quoted-printable.c @@ -22,81 +22,66 @@ #include "utils.h" - #define MAX_LINELEN 76 #define IS_LBREAK(p) \ - ((p)[0] == '\n' ? 1 : ((p)[0] == '\r' && (p)[1] == '\n') ? 2 : 0) + (*(p) == '\0' || *(p) == '\n' || (*(p) == '\r' && *((p) + 1) == '\n')) + +#define SOFT_LBREAK_IF_REQUIRED(n) \ + if (len + (n) > MAX_LINELEN || \ + (len + (n) == MAX_LINELEN && (!IS_LBREAK(inp + 1)))) { \ + *outp++ = '='; \ + *outp++ = '\n'; \ + len = 0; \ + } -gint qp_encode(gboolean text, gchar *out, const guchar *in, gint len) +void qp_encode_line(gchar *out, const guchar *in) { - /* counters of input/output characters */ - gint inc = 0; - gint outc = 1; /* one character reserved for '=' soft line break */ - - while(inc < len) { - /* allow literal linebreaks in text */ - if(text) { - if(IS_LBREAK(in)) { - /* inserting linebreaks is the job of our caller */ - g_assert(outc <= MAX_LINELEN); - *out = '\0'; - return inc + IS_LBREAK(in); - } - if(IS_LBREAK(in+1)) { - /* free the reserved character since no softbreak - * will be needed after the current character */ - outc--; - /* guard against whitespace before a literal linebreak */ - if(*in == ' ' || *in == '\t') { - goto escape; - } - } - } - if(*in == '=') { - goto escape; - } - /* Cave: Whitespace is unconditionally output literally, - * but according to the RFC it must not be output before a - * linebreak. - * This requirement is obeyed by quoting all linebreaks - * and therefore ending all lines with '='. */ - else if((*in >= ' ' && *in <= '~') || *in == '\t') { - if(outc + 1 <= MAX_LINELEN) { - *out++ = *in++; - outc++; - inc++; - } - else break; - } - else { -escape: - if(outc + 3 <= MAX_LINELEN) { - *out++ = '='; - outc++; - get_hex_str(out, *in); - out += 2; - outc += 2; - in++; - inc++; + const guchar *inp = in; + gchar *outp = out; + guchar ch; + gint len = 0; + + while (*inp != '\0') { + ch = *inp; + + if (IS_LBREAK(inp)) { + *outp++ = '\n'; + len = 0; + if (*inp == '\r') + inp++; + inp++; + } else if (ch == '\t' || ch == ' ') { + if (IS_LBREAK(inp + 1)) { + SOFT_LBREAK_IF_REQUIRED(3); + *outp++ = '='; + get_hex_str(outp, ch); + outp += 2; + len += 3; + inp++; + } else { + SOFT_LBREAK_IF_REQUIRED(1); + *outp++ = *inp++; + len++; } - else break; + } else if ((ch >= 33 && ch <= 60) || (ch >= 62 && ch <= 126)) { + SOFT_LBREAK_IF_REQUIRED(1); + *outp++ = *inp++; + len++; + } else { + SOFT_LBREAK_IF_REQUIRED(3); + *outp++ = '='; + get_hex_str(outp, ch); + outp += 2; + len += 3; + inp++; } } - g_assert(outc <= MAX_LINELEN); - *out++ = '='; - *out = '\0'; - return inc; -} -void qp_encode_line(gchar *out, const guchar *in) { - while (*in != '\0') { - in += qp_encode(TRUE, out, in, strlen(in)); + if (len > 0) + *outp++ = '\n'; - while(*out != '\0') out++; - *out++ = '\n'; - *out++ = '\0'; - } + *outp = '\0'; } gint qp_decode_line(gchar *str) diff --git a/src/common/quoted-printable.h b/src/common/quoted-printable.h index 3cdc2c109..92f53b67f 100644 --- a/src/common/quoted-printable.h +++ b/src/common/quoted-printable.h @@ -22,18 +22,6 @@ #include -/* Processes at most 78 characters from in buffer, - * and stores one NULL-terminated line of at most 76 characters (excl. \0) of - * quoted-printable output without terminating newline characters in out buffer. - * Except when encoding text, every output line ends in a soft line break. - * Therefore the caller can chain multiple lines of encoded data resulting from - * sequential runs by glueing them together with line breaks. - * The number of processed input characters is returned. */ -gint qp_encode (gboolean text, - gchar *out, - const guchar *in, - gint len); -/* Deprecated */ void qp_encode_line (gchar *out, const guchar *in); gint qp_decode_line (gchar *str); diff --git a/src/messageview.c b/src/messageview.c index 6a3e0ee78..bfd8d1b36 100644 --- a/src/messageview.c +++ b/src/messageview.c @@ -988,9 +988,8 @@ static gint disposition_notification_send(MsgInfo *msginfo) extract_address(orig_to); } if (msginfo->subject && *(msginfo->subject)) { - gint len = strlen(msginfo->subject); - enc_sub = g_malloc0(len*8); - qp_encode(TRUE, enc_sub, (const guchar *)msginfo->subject, len); + enc_sub = g_malloc0(strlen(msginfo->subject)*8); + qp_encode_line(enc_sub, (const guchar *)msginfo->subject); g_strstrip(enc_sub); } ok = fprintf(fp,"MIME-Version: 1.0\n" -- 2.25.1