Commit d8de0837 authored by Nick Mathewson's avatar Nick Mathewson 👉
Browse files

r15737@tombo: nickm | 2007-12-27 18:17:35 -0500

 Make the "ignore . characters in email addresses" logic configurable and domain-specific.


svn:r12997
parent dcbd28d1
......@@ -70,6 +70,14 @@ EMAIL_DOMAINS = [ "gmail.com", "yahoo.com" ]
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=[]
......
......@@ -147,7 +147,7 @@ def extractAddrSpec(addr):
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 @@ def normalizeEmail(addr, domainmap):
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 @@ class EmailBasedDistributor(bridgedb.Bridges.BridgeHolder):
## 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 @@ class EmailBasedDistributor(bridgedb.Bridges.BridgeHolder):
# 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 @@ class EmailBasedDistributor(bridgedb.Bridges.BridgeHolder):
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):
......
......@@ -58,6 +58,8 @@ CONFIG = Conf(
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 @@ def startup(cfg):
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment