diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-11-12 18:27:46 -0200 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-11-17 14:32:13 -0200 |
commit | 040faf2bf94db227246a00b38da8f92bfa0c8fa8 (patch) | |
tree | c2d41d770ba2d7d7beb86ef462b9be6b0ee8044e /src/leap/mail/utils.py | |
parent | 6102c35586bb925de2624d3164e6b9e7d8838a0e (diff) |
Moving encrypt, sign and send logic from gateway (SMTP) to a MailService
Diffstat (limited to 'src/leap/mail/utils.py')
-rw-r--r-- | src/leap/mail/utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/leap/mail/utils.py b/src/leap/mail/utils.py index fed24b3..457097b 100644 --- a/src/leap/mail/utils.py +++ b/src/leap/mail/utils.py @@ -17,12 +17,15 @@ """ Mail utilities. """ +from email.utils import parseaddr import json import re import traceback import Queue from leap.soledad.common.document import SoledadDocument +from leap.common.check import leap_assert_type +from twisted.mail import smtp CHARSET_PATTERN = r"""charset=([\w-]+)""" @@ -224,6 +227,26 @@ def accumulator_queue(fun, lim): return _accumulator +def validate_address(address): + """ + Validate C{address} as defined in RFC 2822. + + :param address: The address to be validated. + :type address: str + + @return: A valid address. + @rtype: str + + @raise smtp.SMTPBadRcpt: Raised if C{address} is invalid. + """ + leap_assert_type(address, str) + # in the following, the address is parsed as described in RFC 2822 and + # ('', '') is returned if the parse fails. + _, address = parseaddr(address) + if address == '': + raise smtp.SMTPBadRcpt(address) + return address + # # String manipulation # |