dovecot-2.0: quoted-printable decoding didn't handle QP after so...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Sep 11 02:14:02 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/281ea23515ce
changeset: 9924:281ea23515ce
user: Timo Sirainen <tss at iki.fi>
date: Thu Sep 10 19:13:19 2009 -0400
description:
quoted-printable decoding didn't handle QP after soft line breaks correctly.
Patch by Yamazaki Hideto.
diffstat:
2 files changed, 32 insertions(+), 17 deletions(-)
src/lib-mail/quoted-printable.c | 4 +--
src/lib-mail/test-quoted-printable.c | 45 ++++++++++++++++++++++------------
diffs (93 lines):
diff -r 77228b5431e1 -r 281ea23515ce src/lib-mail/quoted-printable.c
--- a/src/lib-mail/quoted-printable.c Thu Sep 10 18:56:49 2009 -0400
+++ b/src/lib-mail/quoted-printable.c Thu Sep 10 19:13:19 2009 -0400
@@ -43,7 +43,7 @@ void quoted_printable_decode(const unsig
if (src[src_pos+1] == '\n') {
/* =\n -> skip both */
- src_pos += 2;
+ src_pos++;
next += 2;
continue;
}
@@ -53,7 +53,7 @@ void quoted_printable_decode(const unsig
if (src[src_pos+1] == '\r' && src[src_pos+2] == '\n') {
/* =\r\n -> skip both */
- src_pos += 3;
+ src_pos += 2;
next += 3;
continue;
}
diff -r 77228b5431e1 -r 281ea23515ce src/lib-mail/test-quoted-printable.c
--- a/src/lib-mail/test-quoted-printable.c Thu Sep 10 18:56:49 2009 -0400
+++ b/src/lib-mail/test-quoted-printable.c Thu Sep 10 19:13:19 2009 -0400
@@ -6,19 +6,27 @@
#include "quoted-printable.h"
#include "test-common.h"
+struct test_quoted_printable_decode_data {
+ const char *input;
+ const char *output;
+ int end_skip;
+};
+
static void test_quoted_printable_decode(void)
{
- const char *data[] = {
- "foo \r\nbar=", "foo\r\nbar",
- "foo =\nbar", "foo bar",
- "foo =\r\nbar", "foo bar",
- "foo \nbar=", "foo\r\nbar",
- "=0A=0D ", "\n\r",
- "foo_bar", "foo_bar",
- "foo=", "foo",
- "foo=A", "foo",
- "foo=Ax", "foo=Ax",
- "foo=Ax=xy", "foo=Ax=xy"
+ static struct test_quoted_printable_decode_data data[] = {
+ { "foo \r\nbar=", "foo\r\nbar", 1 },
+ { "foo =\nbar", "foo bar", 0 },
+ { "foo =\n=01", "foo \001", 0 },
+ { "foo =\r\nbar", "foo bar", 0 },
+ { "foo =\r\n=01", "foo \001", 0 },
+ { "foo \nbar=", "foo\r\nbar", 1 },
+ { "=0A=0D ", "\n\r", 2 },
+ { "foo_bar", "foo_bar", 0 },
+ { "foo=", "foo", 1 },
+ { "foo=A", "foo", 2 },
+ { "foo=Ax", "foo=Ax", 0 },
+ { "foo=Ax=xy", "foo=Ax=xy", 0 }
};
buffer_t *buf;
unsigned int i, start, end, len;
@@ -26,10 +34,16 @@ static void test_quoted_printable_decode
test_begin("quoted printable decode");
buf = buffer_create_dynamic(pool_datastack_create(), 128);
- for (i = 0; i < N_ELEMENTS(data); i += 2) {
- len = strlen(data[i]);
+ for (i = 0; i < N_ELEMENTS(data); i++) {
+ len = strlen(data[i].input);
+ quoted_printable_decode((const void *)data[i].input, len,
+ &src_pos, buf);
+ test_assert(src_pos + data[i].end_skip == len);
+ test_assert(strcmp(data[i].output, str_c(buf)) == 0);
+
+ buffer_set_used_size(buf, 0);
for (start = 0, end = 1; end <= len; ) {
- quoted_printable_decode(CONST_PTR_OFFSET(data[i], start),
+ quoted_printable_decode(CONST_PTR_OFFSET(data[i].input, start),
end - start, &src_pos, buf);
src_pos += start;
start = src_pos;
@@ -38,7 +52,8 @@ static void test_quoted_printable_decode
else
end = src_pos + 1;
}
- test_assert(strcmp(data[i+1], str_c(buf)) == 0);
+ test_assert(src_pos + data[i].end_skip == len);
+ test_assert(strcmp(data[i].output, str_c(buf)) == 0);
buffer_set_used_size(buf, 0);
}
test_end();
More information about the dovecot-cvs
mailing list