[geary] Geary.RFC822.Subject: Handle long headers being folded
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Geary.RFC822.Subject: Handle long headers being folded
- Date: Wed, 20 Jan 2021 08:24:52 +0000 (UTC)
commit b51b933b6de8fbe880d6c6a657eff7a7b677db79
Author: Michael Gratton <mike vee net>
Date: Wed Jan 20 19:20:30 2021 +1100
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
src/engine/rfc822/rfc822-message-data.vala | 4 ++--
src/engine/rfc822/rfc822-utils.vala | 15 +++++++++++++--
test/engine/rfc822/rfc822-message-data-test.vala | 9 +++++++++
3 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message-data.vala b/src/engine/rfc822/rfc822-message-data.vala
index d238bdec1..d36e57a0d 100644
--- a/src/engine/rfc822/rfc822-message-data.vala
+++ b/src/engine/rfc822/rfc822-message-data.vala
@@ -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;
}
diff --git a/src/engine/rfc822/rfc822-utils.vala b/src/engine/rfc822/rfc822-utils.vala
index feb377eb8..e0b0bee55 100644
--- a/src/engine/rfc822/rfc822-utils.vala
+++ b/src/engine/rfc822/rfc822-utils.vala
@@ -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.
*
diff --git a/test/engine/rfc822/rfc822-message-data-test.vala
b/test/engine/rfc822/rfc822-message-data-test.vala
index d6357ff95..613e4b9a1 100644
--- a/test/engine/rfc822/rfc822-message-data-test.vala
+++ b/test/engine/rfc822/rfc822-message-data-test.vala
@@ -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),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]