diff --git a/src/lib-mail/rfc822-parser.c b/src/lib-mail/rfc822-parser.c index 917288cda7..2f7e77da9c 100644 --- a/src/lib-mail/rfc822-parser.c +++ b/src/lib-mail/rfc822-parser.c @@ -234,6 +234,13 @@ int rfc822_parse_quoted_string(struct rfc822_parser_context *ctx, string_t *str) if (ctx->data >= ctx->end) return -1; + if (*ctx->data == '\r' || *ctx->data == '\n') { + /* quoted-pair doesn't allow CR/LF. + They are part of the obs-qp though, so don't + return them as error. */ + ctx->data--; + break; + } str_append_data(str, start, ctx->data - start - 1); start = ctx->data; break; diff --git a/src/lib-mail/test-rfc822-parser.c b/src/lib-mail/test-rfc822-parser.c index 695021f1e5..8f8d4fb66b 100644 --- a/src/lib-mail/test-rfc822-parser.c +++ b/src/lib-mail/test-rfc822-parser.c @@ -18,7 +18,11 @@ static void test_rfc822_parse_quoted_string(void) { "\"\"\"", "", 1 }, { "\"\\\"\"", "\"", 0 }, { "\"\\\\\"", "\\", 0 }, - { "\"\\\\foo\\\\foo\\\\\"", "\\foo\\foo\\", 0 } + { "\"\\\\foo\\\\foo\\\\\"", "\\foo\\foo\\", 0 }, + { "\"foo\n bar\"", "foo bar", 0 }, + { "\"foo\n\t\t bar\"", "foo\t\t bar", 0 }, + { "\"foo\\\n bar\"", "foo\\ bar", 0 }, + { "\"foo\\\r\n bar\"", "foo\\ bar", 0 }, }; struct rfc822_parser_context parser; string_t *str = t_str_new(64);