whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: WHIMSY-241 - Allow for GMail aliasing when checking subscriptions
Date Sat, 02 Mar 2019 14:58:45 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e8b07d  WHIMSY-241 - Allow for GMail aliasing when checking subscriptions
6e8b07d is described below

commit 6e8b07d7ffc0703014fe79ddeca2ecf15083c08b
Author: Sebb <sebb@apache.org>
AuthorDate: Sat Mar 2 14:58:38 2019 +0000

    WHIMSY-241 - Allow for GMail aliasing when checking subscriptions
    
    Initial checkin:
    Add code to canonicalise GMail addresses
---
 lib/whimsy/asf/mail.rb | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/whimsy/asf/mail.rb b/lib/whimsy/asf/mail.rb
index c8a6bc1..7ce7a97 100644
--- a/lib/whimsy/asf/mail.rb
+++ b/lib/whimsy/asf/mail.rb
@@ -143,7 +143,31 @@ module ASF
       return list if dom == 'apache.org'
       dom.sub(".apache.org",'-') + list
     end
-    
+
+    # Canonicalise an email address, removing aliases and ignored punctuation
+    # and downcasing the name if safe to do so
+    #
+    # Currently only handles aliases for @gmail.com and @googlemail.com
+    #
+    # All domains are converted to lower-case
+    #
+    # The case of the name part is preserved since some providers may be case-sensitive
+    # Almost all providers ignore case in names, however that is not guaranteed
+    def self.to_canonical(email)
+      email.match %r{^([^@]+)@(.+)$} do |m|
+        name,dom = m.captures
+        dom.downcase!
+        if dom.match %r{^(?:gmail|googlemail)\.com$}
+          return name.sub(/\+.*/,'').gsub('.','').downcase + '@' + dom
+        else
+          # only downcase the domain (done above)
+          return name + '@' + dom
+        end
+      end
+      # Invalid; return input rather than failing
+      return email
+    end
+
   end
 
   class Person < Base


Mime
View raw message