Geary.RFC822.Subject: Handle long headers being folded

Remove "\n " sequences from RFC822 text before decoding so that any
long subject lines folded before the 80 char limit are unfolded.

Fixes #895
This commit is contained in:
Michael Gratton 2021-01-20 19:20:30 +11:00
parent 900b51004b
commit b51b933b6d
3 changed files with 24 additions and 4 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright © 2016 Software Freedom Conservancy Inc.
* Copyright © 2020 Michael Gratton <mike@vee.net>
* Copyright © 2020-2021 Michael Gratton <mike@vee.net>
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
@ -367,7 +367,7 @@ public class Geary.RFC822.Subject :
}
public Subject.from_rfc822_string(string rfc822) {
base(GMime.utils_header_decode_text(get_parser_options(), rfc822).strip());
base(Utils.decode_rfc822_text_header_value(rfc822));
this.rfc822 = rfc822;
}

View file

@ -1,6 +1,7 @@
/*
* Copyright 2016 Software Freedom Conservancy Inc.
* Portions copyright (C) 2000-2013 Jeffrey Stedfast
* Copyright © 2016 Software Freedom Conservancy Inc.
* Copyright © 2021 Michael Gratton <mike@vee.net>
* Portions copyright © 2000-2013 Jeffrey Stedfast
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
@ -200,6 +201,16 @@ namespace Geary.RFC822.Utils {
return Geary.String.reduce_whitespace(preview.make_valid());
}
/**
* Decodes RFC-822 long header lines and RFC 2047 encoded text headers.
*/
internal string decode_rfc822_text_header_value(string rfc822) {
return GMime.utils_header_decode_text(
get_parser_options(),
GMime.utils_header_unfold(rfc822)
);
}
/**
* Uses a GMime.FilterBest to determine the best charset.
*

View file

@ -9,6 +9,7 @@ class Geary.RFC822.MessageDataTest : TestCase {
public MessageDataTest() {
base("Geary.RFC822.MessageDataTest");
add_test("subject_from_rfc822", subject_from_rfc822);
add_test("date_from_rfc822", date_from_rfc822);
add_test("date_from_rfc822", date_from_rfc822);
add_test("date_to_rfc822", date_to_rfc822);
@ -21,6 +22,14 @@ class Geary.RFC822.MessageDataTest : TestCase {
add_test("MessageIdList.merge", message_id_list_merge);
}
public void subject_from_rfc822() throws GLib.Error {
Subject plain = new Subject.from_rfc822_string("hello");
assert_equal(plain.to_string(), "hello");
Subject new_line = new Subject.from_rfc822_string("hello\n there");
assert_equal(new_line.to_string(), "hello there");
}
public void preview_text_with_header() throws GLib.Error {
PreviewText plain_preview1 = new PreviewText.with_header(
new Geary.Memory.StringBuffer(PLAIN_BODY1_HEADERS),