Make RFC822.MailboxAddress.has_distinct_name is case-insensitive

This prevents mailboxes being marked as spoofed when the name part and
address part are equal but with different case.
This commit is contained in:
Michael Gratton 2019-06-27 10:35:26 +10:00
parent 783d7d7912
commit 6e137eb649
2 changed files with 9 additions and 5 deletions

View file

@ -408,14 +408,17 @@ public class Geary.RFC822.MailboxAddress :
/**
* Determines if the name part is different to the address part.
*
* @return //true// if {@link name} is not empty, and the cleaned
* versions of the name part and {@link address} are not equal.
* @return //true// if {@link name} is not empty, and the
* normalised name part and {@link address} are not equal when
* performing a case-insensitive comparison.
*/
public bool has_distinct_name() {
string clean_name = Geary.String.reduce_whitespace(this.name);
string name = Geary.String.reduce_whitespace(this.name);
return (
!Geary.String.is_empty(clean_name) &&
clean_name != Geary.String.reduce_whitespace(this.address)
!Geary.String.is_empty(name) &&
name.normalize().casefold() != Geary.String.reduce_whitespace(
this.address.normalize().casefold()
)
);
}

View file

@ -160,6 +160,7 @@ class Geary.RFC822.MailboxAddressTest : TestCase {
assert(new MailboxAddress("test test", "example@example.com").is_spoofed() == false);
assert(new MailboxAddress("test?", "example@example.com").is_spoofed() == false);
assert(new MailboxAddress("test@example.com", "test@example.com").is_spoofed() == false);
assert(new MailboxAddress("test@EXAMPLE.com", "test@example.com").is_spoofed() == false);
assert(new MailboxAddress("test@example.com", "example@example.com").is_spoofed() == true);
assert(new MailboxAddress("test @ example . com", "example@example.com").is_spoofed() == true);