def which_emails_are_banned(cls, canons): banned = hooks.get_hook("email.get_banned").call(canons=canons) # Create a dictionary like: # d["abc.def.com"] = [ "*****@*****.**", "*****@*****.**" ] rv = {} canons_by_domain = {} # email.get_banned will return a list of lists (one layer from the # hooks system, the second from the function itself); chain them # together for easy processing for canon in itertools.chain(*banned): rv[canon] = None at_sign = canon.find("@") domain = canon[at_sign + 1 :] canons_by_domain.setdefault(domain, []) canons_by_domain[domain].append(canon) # Hand off to the domain ban system; it knows in the case of # [email protected] to check foo.bar.com, bar.com, and .com from r2.models.admintools import bans_for_domain_parts for domain, canons in canons_by_domain.iteritems(): for d in bans_for_domain_parts(domain): if d.no_email: rv[canon] = "domain" return rv
def which_emails_are_banned(cls, canons): banned = g.hardcache.get_multi(canons, prefix="email_banned-") # Filter out all the ones that are simply banned by address. # Of the remaining ones, create a dictionary like: # d["abc.def.com"] = [ "*****@*****.**", "*****@*****.**" ] rv = {} canons_by_domain = {} for canon in canons: if banned.get(canon, False): rv[canon] = "address" continue rv[canon] = None at_sign = canon.find("@") domain = canon[at_sign+1:] canons_by_domain.setdefault(domain, []) canons_by_domain[domain].append(canon) # Hand off to the domain ban system; it knows in the case of # [email protected] to check foo.bar.com, bar.com, and .com from r2.models.admintools import bans_for_domain_parts for domain, canons in canons_by_domain.iteritems(): for d in bans_for_domain_parts(domain): if d.no_email: rv[canon] = "domain" return rv
def which_emails_are_banned(cls, canons): banned = hooks.get_hook('email.get_banned').call(canons=canons) # Create a dictionary like: # d["abc.def.com"] = [ "*****@*****.**", "*****@*****.**" ] rv = {} canons_by_domain = {} # email.get_banned will return a list of lists (one layer from the # hooks system, the second from the function itself); chain them # together for easy processing for canon in itertools.chain(*banned): rv[canon] = None at_sign = canon.find("@") domain = canon[at_sign + 1:] canons_by_domain.setdefault(domain, []) canons_by_domain[domain].append(canon) # Hand off to the domain ban system; it knows in the case of # [email protected] to check foo.bar.com, bar.com, and .com from r2.models.admintools import bans_for_domain_parts for domain, canons in canons_by_domain.iteritems(): for d in bans_for_domain_parts(domain): if d.no_email: rv[canon] = "domain" return rv