[geary/mjog/571-imap-fetch-space-workaround-redux: 2/2] Fix RFC822.Header.get_header_names returning null names
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/571-imap-fetch-space-workaround-redux: 2/2] Fix RFC822.Header.get_header_names returning null names
- Date: Tue, 22 Oct 2019 06:31:07 +0000 (UTC)
commit ab77067d8aeb47834ccef330c736e57947f2661e
Author: Michael Gratton <mike vee net>
Date: Thu Oct 10 08:55:42 2019 +1100
Fix RFC822.Header.get_header_names returning null names
The custom GMime VAPI assumed the call to get_iter() actually returned a
new iter, but it doesn't. Fix that, update Header class style, and add
tests.
bindings/vapi/gmime-2.6.vapi | 2 +-
src/engine/rfc822/rfc822-message-data.vala | 26 +++++++++++---------------
test/engine/rfc822-message-data-test.vala | 22 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/bindings/vapi/gmime-2.6.vapi b/bindings/vapi/gmime-2.6.vapi
index 2c4ad52a..7665a784 100644
--- a/bindings/vapi/gmime-2.6.vapi
+++ b/bindings/vapi/gmime-2.6.vapi
@@ -505,7 +505,7 @@ namespace GMime {
[CCode (cname = "g_mime_header_list_get")]
public unowned string @get (string name);
[CCode (cname = "g_mime_header_list_get_iter")]
- public bool get_iter (out unowned GMime.HeaderIter iter);
+ public bool get_iter (GMime.HeaderIter iter);
[CCode (cname = "g_mime_header_list_get_stream")]
public unowned GMime.Stream get_stream ();
[CCode (cname = "g_mime_header_list_prepend")]
diff --git a/src/engine/rfc822/rfc822-message-data.vala b/src/engine/rfc822/rfc822-message-data.vala
index 0c8d9e17..2d399986 100644
--- a/src/engine/rfc822/rfc822-message-data.vala
+++ b/src/engine/rfc822/rfc822-message-data.vala
@@ -328,7 +328,7 @@ public class Geary.RFC822.Header : Geary.MessageData.BlockMessageData, Geary.RFC
private string[]? names = null;
public Header(Memory.Buffer buffer) {
- base ("RFC822.Header", buffer);
+ base("RFC822.Header", buffer);
}
private unowned GMime.HeaderList get_headers() throws RFC822Error {
@@ -351,20 +351,16 @@ public class Geary.RFC822.Header : Geary.MessageData.BlockMessageData, Geary.RFC
}
public string[] get_header_names() throws RFC822Error {
- if (names != null)
- return names;
-
- names = new string[0];
-
- unowned GMime.HeaderIter iter;
- if (!get_headers().get_iter(out iter))
- return names;
-
- do {
- names += iter.get_name();
- } while (iter.next());
-
- return names;
+ if (this.names == null) {
+ this.names = new string[0];
+ GMime.HeaderIter iter = new GMime.HeaderIter();
+ if (get_headers().get_iter(iter) && iter.first()) {
+ do {
+ names += iter.get_name();
+ } while (iter.next());
+ }
+ }
+ return this.names;
}
}
diff --git a/test/engine/rfc822-message-data-test.vala b/test/engine/rfc822-message-data-test.vala
index 2b849edb..504efaa0 100644
--- a/test/engine/rfc822-message-data-test.vala
+++ b/test/engine/rfc822-message-data-test.vala
@@ -10,7 +10,10 @@ class Geary.RFC822.MessageDataTest : TestCase {
public MessageDataTest() {
base("Geary.RFC822.MessageDataTest");
add_test("date_from_rfc822", date_from_rfc822);
+ add_test("date_from_rfc822", date_from_rfc822);
add_test("date_to_rfc822", date_to_rfc822);
+ add_test("header_from_rfc822", header_from_rfc822);
+ add_test("header_names_from_rfc822", header_names_from_rfc822);
add_test("PreviewText.with_header", preview_text_with_header);
}
@@ -42,6 +45,20 @@ class Geary.RFC822.MessageDataTest : TestCase {
assert_string(HTML_BODY2_EXPECTED, html_preview2.buffer.to_string());
}
+ public void header_from_rfc822() throws GLib.Error {
+ Header test_article = new Header(new Memory.StringBuffer(HEADER_FIXTURE));
+ assert_string("Test <test example com>", test_article.get_header("From"));
+ assert_string("test", test_article.get_header("Subject"));
+ assert_null_string(test_article.get_header("Blah"));
+ }
+
+ public void header_names_from_rfc822() throws GLib.Error {
+ Header test_article = new Header(new Memory.StringBuffer(HEADER_FIXTURE));
+ assert_int(2, test_article.get_header_names().length);
+ assert_string("From", test_article.get_header_names()[0]);
+ assert_string("Subject", test_article.get_header_names()[1]);
+ }
+
public void date_from_rfc822() throws GLib.Error {
const string FULL_HOUR_TZ = "Thu, 28 Feb 2019 00:00:00 -0100";
Date full_hour_tz = new Date(FULL_HOUR_TZ);
@@ -92,6 +109,11 @@ class Geary.RFC822.MessageDataTest : TestCase {
}
+ private const string HEADER_FIXTURE = """From: Test <test example com>
+Subject: test
+
+""";
+
public static string PLAIN_BODY1_HEADERS = "Content-Type: text/plain;
charset=\"us-ascii\"\r\nContent-Transfer-Encoding: 7bit\r\n";
public static string PLAIN_BODY1_ENCODED = "-----BEGIN PGP SIGNED MESSAGE-----\r\nHash:
SHA512\r\n\r\n=============================================================================\r\nFreeBSD-EN-16:11.vmbus
Errata Notice\r\n
The FreeBSD Project\r\n\r\nTopic: Avoid using spin locks for channel message
locks\r\n\r\nCategory: core\r\nModule: vmbus\r\nAnnounced: 2016-08-12\r\nCredits:
Microsoft OSTC\r\nAffects: FreeBSD 10.3\r\nCorrected: 2016-06-15 09:52:01 UTC (stable/10,
10.3-STABLE)\r\n 2016-08-12 04:01:16 UTC (releng/10.3, 10.3-RELEASE-p7)\r\n\r\nFor general
information regarding FreeBSD Errata Notices and Security\r\nAdvisories, including descriptions of the fields
above, security\r\nbranches, and the following sections, please
visit\r\n<URL:https://security.FreeBSD.org/>.\r\n";
public static string PLAIN_BODY1_EXPECTED = "FreeBSD-EN-16:11.vmbus Errata Notice The FreeBSD Project
Topic: Avoid using spin locks for channel message locks Category: core Module: vmbus Announced: 2016-08-12
Credits: Microsoft OSTC Affects: FreeBSD 10.3 Corrected: 2016-06-15 09:52:01 UTC (stable/10, 10.3-STABLE)
2016-08-12 04:01:16 UTC (releng/10.3, 10.3-RELEASE-p7) For general information regarding FreeBSD Errata
Notices and Security Advisories, including descriptions of the fields above, security branches, and the
following sections, please visit <URL:https://security.FreeBSD.org/>.";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]