Fix MailboxAddresses.to_rfc822_string formatting, add unit tests.
This commit is contained in:
parent
8a1906fa96
commit
178ce35113
5 changed files with 57 additions and 7 deletions
|
|
@ -105,15 +105,16 @@ public class Geary.RFC822.MailboxAddresses : Geary.MessageData.AbstractMessageDa
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the addresses suitable for insertion into an RFC822 message. RFC822 quoting is
|
||||
* performed if required.
|
||||
* Returns the addresses suitable for insertion into an RFC822 message.
|
||||
*
|
||||
* RFC822 quoting is performed if required.
|
||||
*
|
||||
* @see MailboxAddress.to_rfc822_string
|
||||
*/
|
||||
public string to_rfc822_string() {
|
||||
return MailboxAddress.list_to_string(addrs, "", (a) => a.to_rfc822_string());
|
||||
return MailboxAddress.list_to_string(addrs, ", ", (a) => a.to_rfc822_string());
|
||||
}
|
||||
|
||||
|
||||
public uint hash() {
|
||||
// create sorted set to ensure ordering no matter the list's order
|
||||
Gee.TreeSet<string> sorted_addresses = traverse<RFC822.MailboxAddress>(addrs)
|
||||
|
|
@ -143,14 +144,14 @@ public class Geary.RFC822.MailboxAddresses : Geary.MessageData.AbstractMessageDa
|
|||
|
||||
return Collection.are_sets_equal<RFC822.MailboxAddress>(first, second);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See Geary.MessageData.SearchableMessageData.
|
||||
*/
|
||||
public string to_searchable_string() {
|
||||
return MailboxAddress.list_to_string(addrs, "", (a) => a.to_searchable_string());
|
||||
return MailboxAddress.list_to_string(addrs, " ", (a) => a.to_searchable_string());
|
||||
}
|
||||
|
||||
|
||||
public override string to_string() {
|
||||
return MailboxAddress.list_to_string(addrs, "(no addresses)", (a) => a.to_string());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ set(TEST_ENGINE_SRC
|
|||
engine/imap-engine/account-processor-test.vala
|
||||
engine/mime-content-type-test.vala
|
||||
engine/rfc822-mailbox-address-test.vala
|
||||
engine/rfc822-mailbox-addresses-test.vala
|
||||
engine/rfc822-message-test.vala
|
||||
engine/rfc822-message-data-test.vala
|
||||
engine/rfc822-utils-test.vala
|
||||
|
|
|
|||
46
test/engine/rfc822-mailbox-addresses-test.vala
Normal file
46
test/engine/rfc822-mailbox-addresses-test.vala
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 2018 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.
|
||||
*/
|
||||
|
||||
class Geary.RFC822.MailboxAddressesTest : Gee.TestCase {
|
||||
|
||||
public MailboxAddressesTest() {
|
||||
base("Geary.RFC822.MailboxAddressesTest");
|
||||
add_test("from_rfc822_string_encoded", from_rfc822_string_encoded);
|
||||
add_test("to_rfc822_string", to_rfc822_string);
|
||||
}
|
||||
|
||||
public void from_rfc822_string_encoded() {
|
||||
MailboxAddresses addrs = new MailboxAddresses.from_rfc822_string("test@example.com");
|
||||
assert(addrs.size == 1);
|
||||
|
||||
addrs = new MailboxAddresses.from_rfc822_string("test1@example.com, test2@example.com");
|
||||
assert(addrs.size == 2);
|
||||
|
||||
// Courtesy Mailsploit https://www.mailsploit.com
|
||||
addrs = new MailboxAddresses.from_rfc822_string("\"=?utf-8?b?dGVzdCIgPHBvdHVzQHdoaXRlaG91c2UuZ292Pg==?==?utf-8?Q?=00=0A?=\" <demo@mailsploit.com>");
|
||||
assert(addrs.size == 1);
|
||||
|
||||
// Courtesy Mailsploit https://www.mailsploit.com
|
||||
addrs = new MailboxAddresses.from_rfc822_string("\"=?utf-8?Q?=42=45=47=49=4E=20=2F=20=28=7C=29=7C=3C=7C=3E=7C=40=7C=2C=7C=3B=7C=3A=7C=5C=7C=22=7C=2F=7C=5B=7C=5D=7C=3F=7C=2E=7C=3D=20=2F=20=00=20=50=41=53=53=45=44=20=4E=55=4C=4C=20=42=59=54=45=20=2F=20=0D=0A=20=50=41=53=53=45=44=20=43=52=4C=46=20=2F=20?==?utf-8?b?RU5E=?=\", <demo@mailsploit.com>");
|
||||
assert(addrs.size == 2);
|
||||
}
|
||||
|
||||
public void to_rfc822_string() {
|
||||
assert(new_addreses({ "test1@example.com" }).to_rfc822_string() ==
|
||||
"test1@example.com");
|
||||
assert(new_addreses({ "test1@example.com", "test2@example.com" }).to_rfc822_string() ==
|
||||
"test1@example.com, test2@example.com");
|
||||
}
|
||||
|
||||
private MailboxAddresses new_addreses(string[] address_strings) {
|
||||
Gee.List<MailboxAddress> addresses = new Gee.LinkedList<MailboxAddress>();
|
||||
foreach (string address in address_strings) {
|
||||
addresses.add(new MailboxAddress(null, address));
|
||||
}
|
||||
return new MailboxAddresses(addresses);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ geary_test_engine_sources = [
|
|||
'engine/imap-engine/account-processor-test.vala',
|
||||
'engine/mime-content-type-test.vala',
|
||||
'engine/rfc822-mailbox-address-test.vala',
|
||||
'engine/rfc822-mailbox-addresses-test.vala',
|
||||
'engine/rfc822-message-test.vala',
|
||||
'engine/rfc822-message-data-test.vala',
|
||||
'engine/rfc822-utils-test.vala',
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ int main(string[] args) {
|
|||
engine.add_suite(new Geary.JS.Test().get_suite());
|
||||
engine.add_suite(new Geary.Mime.ContentTypeTest().get_suite());
|
||||
engine.add_suite(new Geary.RFC822.MailboxAddressTest().get_suite());
|
||||
engine.add_suite(new Geary.RFC822.MailboxAddressesTest().get_suite());
|
||||
engine.add_suite(new Geary.RFC822.MessageTest().get_suite());
|
||||
engine.add_suite(new Geary.RFC822.MessageDataTest().get_suite());
|
||||
engine.add_suite(new Geary.RFC822.Utils.Test().get_suite());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue