Geary.RFC822.MessageID: Ensure RFC822 value does not include errant wtsp

`to_rfc822_string` must not include any leading/trailing white space
even if it was included in the `from_rfc822_string` constructor.
This commit is contained in:
Michael Gratton 2020-08-22 11:57:12 +10:00
parent b8ed6ed230
commit 4e50822674
2 changed files with 18 additions and 8 deletions

View file

@ -41,8 +41,6 @@ public interface Geary.RFC822.EncodedMessageData :
public class Geary.RFC822.MessageID :
Geary.MessageData.StringMessageData, DecodedMessageData {
private string rfc822 = null;
public MessageID(string value) {
base(value);
}
@ -52,17 +50,13 @@ public class Geary.RFC822.MessageID :
throw new Error.INVALID("Empty RFC822 message id: %s", rfc822);
}
base(GMime.utils_decode_message_id(rfc822));
this.rfc822 = rfc822;
}
/**
* Returns the {@link Date} in RFC 822 format.
*/
public string to_rfc822_string() {
if (this.rfc822 == null) {
this.rfc822 = "<%s>".printf(this.value);
}
return this.rfc822;
return "<%s>".printf(this.value);
}
}

View file

@ -15,7 +15,8 @@ class Geary.RFC822.MessageDataTest : TestCase {
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);
add_test("MessageIDList.from_rfc822_string", message_id_list_from_rfc822_string);
add_test("MessageId.to_rfc822_string", message_id_to_rfc822_string);
add_test("MessageIdList.from_rfc822_string", message_id_list_from_rfc822_string);
add_test("MessageIdList.merge", message_id_list_merge);
}
@ -110,6 +111,21 @@ class Geary.RFC822.MessageDataTest : TestCase {
assert_equal(neg_half_hour_tz.to_rfc822_string(), NEG_HALF_HOUR_TZ);
}
public void message_id_to_rfc822_string() throws GLib.Error {
assert_equal(
new MessageID("note_895184@gitlab.gnome.org").to_rfc822_string(),
"<note_895184@gitlab.gnome.org>"
);
assert_equal(
new MessageID.from_rfc822_string("<note_895184@gitlab.gnome.org>").to_rfc822_string(),
"<note_895184@gitlab.gnome.org>"
);
assert_equal(
new MessageID.from_rfc822_string(" <note_895184@gitlab.gnome.org>\n").to_rfc822_string(),
"<note_895184@gitlab.gnome.org>"
);
}
public void message_id_list_from_rfc822_string() throws GLib.Error {
// Standard variants