The split_mailbox function was to emailutils.py.

This commit is contained in:
Antoine Nguyen
2011-06-20 10:04:22 +02:00
parent 7338dd1c8f
commit 462c86136c
7 changed files with 28 additions and 22 deletions
-17
View File
@@ -197,20 +197,3 @@ def crypt_password(password):
return hashlib.md5(password).hexdigest()
return password
def split_mailbox(mailbox):
"""Try to split a mailbox in two parts
:return: a 2-uple (local part, domain)
"""
try:
mailbox.index("@")
except ValueError:
return mailbox, None
parts = mailbox.split('@')
if len(parts) == 2:
address = parts[0]
domain = parts[1]
else:
domain = parts[-1]
address = "@".join(parts[:-1])
return (address, domain)
+18
View File
@@ -176,3 +176,21 @@ class Email(object):
body = re.sub("<(/?)body", lambda m: "<%sdiv" % m.group(1), body)
body = Template(body).render(Context({}))
return body
def split_mailbox(mailbox):
"""Tries to split a mailbox in two parts (local part and domain name)
:return: a 2-uple (local part, domain)
"""
try:
mailbox.index("@")
except ValueError:
return mailbox, None
parts = mailbox.split('@')
if len(parts) == 2:
address = parts[0]
domain = parts[1]
else:
domain = parts[-1]
address = "@".join(parts[:-1])
return (address, domain)