summaryrefslogtreecommitdiff
path: root/src/leap/mail/smtp/gateway.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-01-22 17:51:47 -0600
committerKali Kaneko <kali@leap.se>2015-02-11 14:05:44 -0400
commitf211669206d30088181f7299aaa0ffb65a89becc (patch)
treef02346d4a38efa524096d10536a7b718412c21eb /src/leap/mail/smtp/gateway.py
parent66adeda5603aa5a1a29f027bfe6a8536c488ac97 (diff)
Fix SMTP async tests
Diffstat (limited to 'src/leap/mail/smtp/gateway.py')
-rw-r--r--src/leap/mail/smtp/gateway.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/leap/mail/smtp/gateway.py b/src/leap/mail/smtp/gateway.py
index 1a187cf..9d78474 100644
--- a/src/leap/mail/smtp/gateway.py
+++ b/src/leap/mail/smtp/gateway.py
@@ -204,22 +204,24 @@ class SMTPDelivery(object):
signal(proto.SMTP_RECIPIENT_ACCEPTED_ENCRYPTED, user.dest.addrstr)
def not_found(failure):
- if failure.check(KeyNotFound):
- # if key was not found, check config to see if will send anyway
- if self._encrypted_only:
- signal(proto.SMTP_RECIPIENT_REJECTED, user.dest.addrstr)
- raise smtp.SMTPBadRcpt(user.dest.addrstr)
- log.msg("Warning: will send an unencrypted message (because "
- "encrypted_only' is set to False).")
- signal(
- proto.SMTP_RECIPIENT_ACCEPTED_UNENCRYPTED,
- user.dest.addrstr)
- else:
- return failure
-
- d = self._km.get_key(address, OpenPGPKey) # might raise KeyNotFound
+ failure.trap(KeyNotFound)
+
+ # if key was not found, check config to see if will send anyway
+ if self._encrypted_only:
+ signal(proto.SMTP_RECIPIENT_REJECTED, user.dest.addrstr)
+ raise smtp.SMTPBadRcpt(user.dest.addrstr)
+ log.msg("Warning: will send an unencrypted message (because "
+ "encrypted_only' is set to False).")
+ signal(
+ proto.SMTP_RECIPIENT_ACCEPTED_UNENCRYPTED,
+ user.dest.addrstr)
+
+ def encrypt_func(_):
+ return lambda: EncryptedMessage(user, self._outgoing_mail)
+
+ d = self._km.get_key(address, OpenPGPKey)
d.addCallbacks(found, not_found)
- d.addCallback(lambda _: EncryptedMessage(user, self._outgoing_mail))
+ d.addCallback(encrypt_func)
return d
def validateFrom(self, helo, origin):