diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-03-09 11:33:00 +0000 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-03-09 11:33:00 +0000 |
commit | a1d61b59186acf4e148baae656df86556f575b9e (patch) | |
tree | 698b6d1aba621d19a86d2f04cd9282c49f3ef027 | |
parent | c7a80b9e38b4313a2f589031462575c2093eecc9 (diff) | |
download | pykolab-a1d61b59186acf4e148baae656df86556f575b9e.tar.gz |
Simplify the use of email here as well
-rw-r--r-- | wallace/module_optout.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/wallace/module_optout.py b/wallace/module_optout.py index 79cafb7..1aedc7e 100644 --- a/wallace/module_optout.py +++ b/wallace/module_optout.py @@ -25,6 +25,10 @@ import time from urlparse import urlparse import urllib +from email import message_from_file +from email.utils import formataddr +from email.utils import getaddresses + import modules import pykolab @@ -46,6 +50,7 @@ def description(): return """Consult the opt-out service.""" def execute(*args, **kw): + # TODO: Test for correct call. filepath = args[0] if kw.has_key('stage'): @@ -60,13 +65,12 @@ def execute(*args, **kw): log.debug(_("Consulting opt-out service for %r, %r") % (args, kw), level=8) - import email - message = email.message_from_file(open(filepath, 'r')) - envelope_sender = email.utils.getaddresses(message.get_all('From', [])) + message = message_from_file(open(filepath, 'r')) + envelope_sender = getaddresses(message.get_all('From', [])) recipients = { - "To": email.utils.getaddresses(message.get_all('To', [])), - "Cc": email.utils.getaddresses(message.get_all('Cc', [])) + "To": getaddresses(message.get_all('To', [])), + "Cc": getaddresses(message.get_all('Cc', [])) # TODO: Are those all recipient addresses? } @@ -123,8 +127,8 @@ def execute(*args, **kw): new_filepath = os.path.join(mybasepath, answer, os.path.basename(filepath)) # Write out a message file representing the new contents for the message - # use email.formataddr(recipient) - _message = email.message_from_file(open(filepath, 'r')) + # use formataddr(recipient) + _message = message_from_file(open(filepath, 'r')) use_this = False @@ -134,7 +138,7 @@ def execute(*args, **kw): _message.__setitem__( recipient_type, ',\n '.join( - [email.utils.formataddr(x) for x in _recipients[answer][recipient_type]] + [formataddr(x) for x in _recipients[answer][recipient_type]] ) ) |