aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/mime.py
diff options
context:
space:
mode:
authorJ08nY2017-06-26 23:03:58 +0200
committerJ08nY2017-06-26 23:03:58 +0200
commite071f25345dbb8e52c4f22c93da7b1eb7d330793 (patch)
tree451f39955206390b3c24455c6c25c2dacb429428 /src/mailman_pgp/pgp/mime.py
parentd181f52e6f406317416959378153531cce6c5a3a (diff)
downloadmailman-pgp-e071f25345dbb8e52c4f22c93da7b1eb7d330793.tar.gz
mailman-pgp-e071f25345dbb8e52c4f22c93da7b1eb7d330793.tar.zst
mailman-pgp-e071f25345dbb8e52c4f22c93da7b1eb7d330793.zip
Diffstat (limited to 'src/mailman_pgp/pgp/mime.py')
-rw-r--r--src/mailman_pgp/pgp/mime.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py
index 751b9e5..92ee72b 100644
--- a/src/mailman_pgp/pgp/mime.py
+++ b/src/mailman_pgp/pgp/mime.py
@@ -21,9 +21,9 @@ from email import message_from_string
from email.encoders import encode_7or8bit
from email.iterators import walk
from email.mime.application import MIMEApplication
-from email.mime.multipart import MIMEMultipart
from email.utils import collapse_rfc2231_value
+from mailman.email.message import Message, MultipartDigestMessage
from pgpy import PGPKey, PGPMessage, PGPSignature
from pgpy.constants import HashAlgorithm, SymmetricKeyAlgorithm
from public import public
@@ -43,6 +43,11 @@ class MIMEWrapper:
_encrypted_type = 'application/' + _encryption_subtype
_keys_type = 'application/' + _keys_subtype
+ _signature_preamble = \
+ 'This is an OpenPGP/MIME signed message (RFC 4880 and 3156)'
+ _encryption_preamble = \
+ 'This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)'
+
def __init__(self, msg):
"""
Wrap the given message.
@@ -170,9 +175,9 @@ class MIMEWrapper:
signature = key.sign(pmsg, hash=hash)
micalg = self._micalg(signature.hash_algorithm)
- out = MIMEMultipart('signed', micalg=micalg,
- protocol=MIMEWrapper._signed_type)
- out.preamble = 'This is an OpenPGP/MIME signed message (RFC 4880 and 3156)'
+ out = MultipartDigestMessage('signed', micalg=micalg,
+ protocol=MIMEWrapper._signed_type)
+ out.preamble = MIMEWrapper._signature_preamble
second_part = MIMEApplication(_data=str(signature),
_subtype=MIMEWrapper._signature_subtype,
@@ -200,7 +205,7 @@ class MIMEWrapper:
msg_text = self.msg.get_payload(1).get_payload()
pmsg = PGPMessage.from_blob(msg_text)
decrypted = key.decrypt(pmsg)
- out = message_from_string(decrypted.message)
+ out = message_from_string(decrypted.message, _class=Message)
copy_headers(self.msg, out)
return out
@@ -225,9 +230,9 @@ class MIMEWrapper:
session_key=session_key)
del session_key
- out = MIMEMultipart('encrypted',
- protocol=MIMEWrapper._encrypted_type)
- out.preamble = 'This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)'
+ out = MultipartDigestMessage('encrypted',
+ protocol=MIMEWrapper._encrypted_type)
+ out.preamble = MIMEWrapper._encryption_preamble
first_part = MIMEApplication(_data='Version: 1',
_subtype=MIMEWrapper._encryption_subtype,