summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
Diffstat (limited to 'alot')
-rw-r--r--alot/db/utils.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 35cd4250..37ef4c48 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -225,8 +225,18 @@ def decrypted_message_from_file(handle):
:returns: :class:`email.message.Message` possibly augmented with
decrypted data
'''
- m = email.message_from_file(handle)
+ return decrypted_message_from_message(email.message_from_file(handle))
+
+def decrypted_message_from_message(m):
+ '''Detect and decrypt OpenPGP encrypted data in an email object. If this
+ succeeds, any mime messages found in the recovered plaintext
+ message are added to the returned message object.
+
+ :param m: an email object
+ :returns: :class:`email.message.Message` possibly augmented with
+ decrypted data
+ '''
# make sure no one smuggles a token in (data from m is untrusted)
del m[X_SIGNATURE_VALID_HEADER]
del m[X_SIGNATURE_MESSAGE_HEADER]
@@ -279,11 +289,9 @@ def decrypted_message_from_string(s):
def decrypted_message_from_bytes(bytestring):
"""Create a Message from bytes.
- Attempt to guess the encoding of the bytestring.
-
:param bytes bytestring: an email message as raw bytes
"""
- return decrypted_message_from_file(io.StringIO(helper.try_decode(bytestring)))
+ return decrypted_message_from_message(email.message_from_bytes(bytestring))
def extract_headers(mail, headers=None):