From 3c4d5c5e9d1444cce1e2027091c4558262ef1a70 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Wed, 20 Jan 2021 19:22:46 +1100 Subject: [PATCH] Geary.RFC822.MailboxAddress: Handle long headers being folded Remove "\n " sequences from RFC822 text before decoding so that any long mailboxes/mailbox lists folded before the 80 char limit are unfolded. Fixes #1009 --- src/engine/rfc822/rfc822-mailbox-address.vala | 6 +++--- .../rfc822/rfc822-mailbox-address-test.vala | 21 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/engine/rfc822/rfc822-mailbox-address.vala b/src/engine/rfc822/rfc822-mailbox-address.vala index 1e23fca4..90a337a2 100644 --- a/src/engine/rfc822/rfc822-mailbox-address.vala +++ b/src/engine/rfc822/rfc822-mailbox-address.vala @@ -136,11 +136,11 @@ public class Geary.RFC822.MailboxAddress : : GMime.utils_decode_8bit(get_parser_options(), part.data) ); - // unquote the string then decode the text + text = GMime.utils_header_unfold(text); GMime.utils_unquote_string(text); - // Sometimes quoted printables contain unencoded spaces which trips up GMime, so we want to - // encode them all here. + // Sometimes quoted printables contain unencoded spaces which + // trips up GMime, so we want to encode them all here. int offset = 0; int start; while ((start = text.index_of("=?", offset)) != -1) { diff --git a/test/engine/rfc822/rfc822-mailbox-address-test.vala b/test/engine/rfc822/rfc822-mailbox-address-test.vala index fdef5b0b..a79a1a86 100644 --- a/test/engine/rfc822/rfc822-mailbox-address-test.vala +++ b/test/engine/rfc822/rfc822-mailbox-address-test.vala @@ -234,12 +234,21 @@ class Geary.RFC822.MailboxAddressTest : TestCase { assert(new MailboxAddress("test", "example@example@example.com").is_spoofed() == true); assert(new MailboxAddress("'prefix-example@example.com'", "example@example.com").is_spoofed() == true); - try { - assert(new MailboxAddress.from_rfc822_string("\"=?utf-8?b?dGVzdCIgPHBvdHVzQHdoaXRlaG91c2UuZ292Pg==?==?utf-8?Q?=00=0A?=\" ") - .is_spoofed() == true); - } catch (Error err) { - assert_no_error(err); - } + assert_false( + new MailboxAddress.from_rfc822_string( + "hello\n there " + ).is_spoofed() + ); + assert_false( + new MailboxAddress.from_rfc822_string( + "\"hello\n there\" " + ).is_spoofed() + ); + assert_true( + new MailboxAddress.from_rfc822_string( + "\"=?utf-8?b?dGVzdCIgPHBvdHVzQHdoaXRlaG91c2UuZ292Pg==?==?utf-8?Q?=00=0A?=\" " + ).is_spoofed() + ); } public void to_full_display() throws GLib.Error {