diff options
author | Michael J Gruber <github@grubix.eu> | 2018-06-29 10:36:21 +0200 |
---|---|---|
committer | Michael J Gruber <github@grubix.eu> | 2018-07-11 15:54:15 +0200 |
commit | c51ad1c31b9ea0c9dd0b155b2fa1235eab8ddaa5 (patch) | |
tree | 4793013c1d54c542ff1396334307fca564f72bb7 /alot | |
parent | 101eef43e048247775847f35ec6d5e23bae68763 (diff) |
use email.message_from_bytes
.. instead of homebrew method `db.utils.message_from_bytes`.
The right way to do this is to rely on the direct bytes->message
conversion provided by pythons email module.
cf #1253
Suggested-by: Patrick Totzke <patricktotzke@gmail.com>
Diffstat (limited to 'alot')
-rw-r--r-- | alot/db/utils.py | 16 |
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): |