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

[or-cvs] r12997: Make the "ignore . characters in email addresses" logic conf (in bridgedb/trunk: . lib/bridgedb)



Author: nickm
Date: 2007-12-27 18:17:41 -0500 (Thu, 27 Dec 2007)
New Revision: 12997

Modified:
   bridgedb/trunk/
   bridgedb/trunk/bridgedb.conf
   bridgedb/trunk/lib/bridgedb/Dist.py
   bridgedb/trunk/lib/bridgedb/Main.py
Log:
 r15737@tombo:  nickm | 2007-12-27 18:17:35 -0500
 Make the "ignore . characters in email addresses" logic configurable and domain-specific.



Property changes on: bridgedb/trunk
___________________________________________________________________
 svk:merge ticket from /bridgedb/trunk [r15737] on d9e39d38-0f13-419c-a857-e10a0ce2aa0c

Modified: bridgedb/trunk/bridgedb.conf
===================================================================
--- bridgedb/trunk/bridgedb.conf	2007-12-27 14:20:30 UTC (rev 12996)
+++ bridgedb/trunk/bridgedb.conf	2007-12-27 23:17:41 UTC (rev 12997)
@@ -70,6 +70,14 @@
 EMAIL_DOMAIN_MAP = { "mail.google.com" : "gmail.com",
                      "googlemail.com" : "gmail.com",
                      }
+# Map from canonical domain to list of options for that domain.  Recognized
+# options are:
+#     "ignore_dots" -- the service ignores "." characters in email addresses.
+#
+# Note that unrecognized options are ignored; be sure to spell them right!
+EMAIL_DOMAIN_RULES = { 'gmail.com' : ["ignore_dots"],
+                       'yahoo.com' : [ ]
+                       }
 # If there are any IPs in this list, only allow incoming connections from
 # those IPs.
 EMAIL_RESTRICT_IPS=[]

Modified: bridgedb/trunk/lib/bridgedb/Dist.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Dist.py	2007-12-27 14:20:30 UTC (rev 12996)
+++ bridgedb/trunk/lib/bridgedb/Dist.py	2007-12-27 23:17:41 UTC (rev 12997)
@@ -147,7 +147,7 @@
     localpart, domain = m.groups()
     return localpart, domain
 
-def normalizeEmail(addr, domainmap):
+def normalizeEmail(addr, domainmap, domainrules):
     """Given the contents of a from line, and a map of supported email
        domains (in lowercase), raise BadEmail or return a normalized
        email address.
@@ -165,8 +165,10 @@
     idx = localpart.find('+')
     if idx >= 0:
         localpart = localpart[:idx]
-    # j.doe@ is the same as jdoe@.
-    localpart = localpart.replace(".", "")
+    rules = domainrules.get(domain, [])
+    if 'ignore_dots' in rules:
+        # j.doe@ is the same as jdoe@.
+        localpart = localpart.replace(".", "")
 
     return "%s@%s"%(localpart, domain)
 
@@ -181,7 +183,7 @@
     ##   store -- a database object to remember what we've given to whom.
     ##   domainmap -- a map from lowercase domains that we support mail from
     ##       to their canonical forms.
-    def __init__(self, key, store, domainmap):
+    def __init__(self, key, store, domainmap, domainrules):
         key1 = bridgedb.Bridges.get_hmac(key, "Map-Addresses-To-Ring")
         self.emailHmac = bridgedb.Bridges.get_hmac_fn(key1, hex=False)
 
@@ -191,6 +193,7 @@
         # XXXX clear the store when the period rolls over!
         self.store = store
         self.domainmap = domainmap
+        self.domainrules = domainrules
 
     def insert(self, bridge):
         """Assign a bridge to this distributor."""
@@ -203,7 +206,8 @@
                be any string, so long as it changes with every period.
            N -- the number of bridges to try to give back.
         """
-        emailaddress = normalizeEmail(emailaddress, self.domainmap)
+        emailaddress = normalizeEmail(emailaddress, self.domainmap,
+                                      self.domainrules)
         if emailaddress is None:
             return [] #XXXX raise an exception.
         if self.store.has_key(emailaddress):

Modified: bridgedb/trunk/lib/bridgedb/Main.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Main.py	2007-12-27 14:20:30 UTC (rev 12996)
+++ bridgedb/trunk/lib/bridgedb/Main.py	2007-12-27 23:17:41 UTC (rev 12997)
@@ -58,6 +58,8 @@
     EMAIL_DOMAINS = [ "gmail.com", "yahoo.com", "catbus.wangafu.net" ],
     EMAIL_DOMAIN_MAP = { "mail.google.com" : "gmail.com",
                          "googlemail.com" : "gmail.com", },
+    EMAIL_DOMAIN_RULES = { 'gmail.com' : ["ignore_dots"],
+                           'yahoo.com' : [] },
     EMAIL_RESTRICT_IPS=[],
     EMAIL_BIND_IP=None,
     EMAIL_PORT=6725,
@@ -191,7 +193,8 @@
         emailDistributor = Dist.EmailBasedDistributor(
             Bridges.get_hmac(key, "Email-Dist-Key"),
             Bridges.PrefixStore(store, "em|"),
-            cfg.EMAIL_DOMAIN_MAP.copy())
+            cfg.EMAIL_DOMAIN_MAP.copy(),
+            cfg.EMAIL_DOMAIN_RULES.copy())
         splitter.addRing(emailDistributor, "email", cfg.EMAIL_SHARE)
         emailSchedule = Time.IntervalSchedule("day", 1)