[geary/wip/email-spoofing-case] Make RFC822.MailboxAddress.has_distinct_name is case-insensitive



commit 6e137eb64984f365156ac956e42f32cd452c6141
Author: Michael Gratton <mike vee net>
Date:   Thu Jun 27 10:35:26 2019 +1000

    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.

 src/engine/rfc822/rfc822-mailbox-address.vala | 13 ++++++++-----
 test/engine/rfc822-mailbox-address-test.vala  |  1 +
 2 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-mailbox-address.vala b/src/engine/rfc822/rfc822-mailbox-address.vala
index 5ead3307..448c6c9c 100644
--- a/src/engine/rfc822/rfc822-mailbox-address.vala
+++ b/src/engine/rfc822/rfc822-mailbox-address.vala
@@ -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()
+            )
         );
     }
 
diff --git a/test/engine/rfc822-mailbox-address-test.vala b/test/engine/rfc822-mailbox-address-test.vala
index 9aa2b9e7..b6e30789 100644
--- a/test/engine/rfc822-mailbox-address-test.vala
+++ b/test/engine/rfc822-mailbox-address-test.vala
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]