summaryrefslogtreecommitdiff
path: root/src/leap/mx
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-11-06 14:27:24 -0300
committerTomás Touceda <chiiph@leap.se>2013-11-07 10:40:31 -0300
commit3fc38cfa269fd7a8fa602aaf2a3e025b5403b71b (patch)
tree163d8a9958b4e0612a905e741ea480f28e2c292c /src/leap/mx
parente108a2ffec444c09b3661379a1051fda1f9952cf (diff)
Refactor mail processing routine
Diffstat (limited to 'src/leap/mx')
-rw-r--r--src/leap/mx/mail_receiver.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py
index 741b99d..785be2e 100644
--- a/src/leap/mx/mail_receiver.py
+++ b/src/leap/mx/mail_receiver.py
@@ -221,6 +221,31 @@ class MailReceiver(Service):
return uuid
@defer.inlineCallbacks
+ def _step_process_mail_backend(self, filepath):
+ log.msg("Processing new mail at %r" % (filepath.path,))
+ with filepath.open("r") as f:
+ mail_data = f.read()
+ mail = message_from_string(mail_data)
+ uuid = self._get_owner(mail)
+ if uuid is None:
+ log.msg("Don't know how to deliver mail %r, skipping..." %
+ filepath.path)
+ defer.returnValue(None)
+ log.msg("Mail owner: %s" % (uuid,))
+
+ if uuid is None:
+ log.msg("BUG: There was no uuid!")
+ defer.returnValue(None)
+
+ pubkey = yield self._users_cdb.getPubKey(uuid)
+
+ log.msg("Encrypting message to %s's pubkey" % (uuid,))
+ doc = yield self._encrypt_message(pubkey, mail_data)
+
+ do_remove = yield self._export_message(uuid, doc)
+ yield self._conditional_remove(do_remove, filepath)
+
+ @defer.inlineCallbacks
def _process_incoming_email(self, otherself, filepath, mask):
"""
Callback that processes incoming email.
@@ -236,27 +261,6 @@ class MailReceiver(Service):
"""
try:
if os.path.split(filepath.dirname())[-1] == "new":
- log.msg("Processing new mail at %r" % (filepath.path,))
- with filepath.open("r") as f:
- mail_data = f.read()
- mail = message_from_string(mail_data)
- uuid = self._get_owner(mail)
- if uuid is None:
- log.msg("Don't know how to deliver mail %r, skipping..." %
- filepath.path)
- return
- log.msg("Mail owner: %s" % (uuid,))
-
- if uuid is None:
- log.msg("BUG: There was no uuid!")
- return
-
- pubkey = yield self._users_cdb.getPubKey(uuid)
-
- log.msg("Encrypting message to %s's pubkey" % (uuid,))
- doc = yield self._encrypt_message(pubkey, mail_data)
-
- do_remove = yield self._export_message(uuid, doc)
- yield self._conditional_remove(do_remove, filepath)
+ yield self._step_process_mail_backend(filepath)
except Exception:
log.err()