aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/mime.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/pgp/mime.py')
-rw-r--r--src/mailman_pgp/pgp/mime.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py
index e40f581..837e619 100644
--- a/src/mailman_pgp/pgp/mime.py
+++ b/src/mailman_pgp/pgp/mime.py
@@ -28,7 +28,7 @@ from pgpy import PGPDetachedSignature, PGPMessage
from pgpy.constants import HashAlgorithm, SymmetricKeyAlgorithm
from public import public
-from mailman_pgp.utils.email import copy_headers
+from mailman_pgp.utils.email import copy_headers, make_multipart
from mailman_pgp.utils.pgp import key_from_blob, revoc_from_blob
@@ -186,26 +186,27 @@ class MIMEWrapper:
continue
yield key
- def attach_key(self, key):
+ def attach_keys(self, *keys):
"""
Attach a key to this message, as per RFC3156 section 7.
- :param key: A key to attach.
- :type key: pgpy.PGPKey
+ :param keys: A key to attach.
+ :type keys: pgpy.PGPKey
:return: The message with the key attached.
:rtype: mailman.email.message.Message
"""
- filename = '0x' + key.fingerprint.keyid + '.asc'
- key_part = MIMEApplication(_data=str(key),
- _subtype=MIMEWrapper._keys_subtype,
- _encoder=encode_7or8bit,
- name=filename)
- key_part.add_header('Content-Description',
- 'OpenPGP key')
- key_part.add_header('Content-Disposition', 'attachment',
- filename=filename)
- out = copy.deepcopy(self.msg)
- out.attach(key_part)
+ out = make_multipart(self.msg)
+ for key in keys:
+ filename = '0x' + key.fingerprint.keyid + '.asc'
+ key_part = MIMEApplication(_data=str(key),
+ _subtype=MIMEWrapper._keys_subtype,
+ _encoder=encode_7or8bit,
+ name=filename)
+ key_part.add_header('Content-Description',
+ 'OpenPGP key')
+ key_part.add_header('Content-Disposition', 'attachment',
+ filename=filename)
+ out.attach(key_part)
return out
def _is_revoc(self, part):
@@ -239,26 +240,27 @@ class MIMEWrapper:
continue
yield revoc
- def attach_revoc(self, key_revocation):
+ def attach_revocs(self, *key_revocations):
"""
Attach a key revocation signature to the message, as a key subpart.
- :param key_revocation: A key revocation signature to attach.
- :type key_revocation: pgpy.PGPSignature
+ :param key_revocations: A key revocation signature to attach.
+ :type key_revocations: pgpy.PGPSignature
:return: The message with the signature attached.
:rtype: mailman.email.message.Message
"""
- filename = '0x' + key_revocation.signer + '.asc'
- key_part = MIMEApplication(_data=str(key_revocation),
- _subtype=MIMEWrapper._keys_subtype,
- _encoder=encode_7or8bit,
- name=filename)
- key_part.add_header('Content-Description',
- 'OpenPGP key')
- key_part.add_header('Content-Disposition', 'attachment',
- filename=filename)
- out = copy.deepcopy(self.msg)
- out.attach(key_part)
+ out = make_multipart(self.msg)
+ for key_revocation in key_revocations:
+ filename = '0x' + key_revocation.signer + '.asc'
+ revoc_part = MIMEApplication(_data=str(key_revocation),
+ _subtype=MIMEWrapper._keys_subtype,
+ _encoder=encode_7or8bit,
+ name=filename)
+ revoc_part.add_header('Content-Description',
+ 'OpenPGP key')
+ revoc_part.add_header('Content-Disposition', 'attachment',
+ filename=filename)
+ out.attach(revoc_part)
return out
def verify(self, key):