aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ08nY2017-06-19 19:35:44 +0200
committerJ08nY2017-06-19 19:35:44 +0200
commit01d1c164eb5b1734ffe03ff642e46707ffdce3df (patch)
tree935d52249e41a56d06780bb47b81dc9275f8e6ff /src
parentea3c9c3778e79b8fcef648e59aee7affe724791b (diff)
downloadmailman-pgp-01d1c164eb5b1734ffe03ff642e46707ffdce3df.tar.gz
mailman-pgp-01d1c164eb5b1734ffe03ff642e46707ffdce3df.tar.zst
mailman-pgp-01d1c164eb5b1734ffe03ff642e46707ffdce3df.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman_pgp/pgp/mime.py36
-rw-r--r--src/mailman_pgp/runners/incoming.py7
2 files changed, 40 insertions, 3 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py
index f3b0d32..08bd111 100644
--- a/src/mailman_pgp/pgp/mime.py
+++ b/src/mailman_pgp/pgp/mime.py
@@ -1 +1,37 @@
""""""
+from email.message import Message
+from email.utils import collapse_rfc2231_value
+
+
+class PGPMIMEWrapper:
+ def __init__(self, msg: Message):
+ self.msg = msg
+
+ def _is_mime(self):
+ is_multipart = self.msg.is_multipart()
+ payloads = len(self.msg.get_payload())
+ first_part = self.msg.get_payload(0)
+ return is_multipart and payloads == 2 and 'Version: 1' in first_part
+
+ def is_mime_signed(self):
+ """
+ Whether the whole message is MIME signed as per RFC3156 section 5.
+ :return:
+ """
+ protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol'))
+ content_subtype = self.msg.get_content_subtype()
+ return self._is_mime() and \
+ content_subtype == 'signed' and \
+ protocol_param == 'application/pgp-signature'
+
+ def is_mime_encrypted(self):
+ """
+ Whether the whole message is MIME encrypted as per RFC3156 section 4.
+ :return:
+ """
+ content_subtype = self.msg.get_content_subtype()
+ protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol'))
+
+ return self._is_mime() and \
+ content_subtype == 'encrypted' and \
+ protocol_param == 'application/pgp-encrypted'
diff --git a/src/mailman_pgp/runners/incoming.py b/src/mailman_pgp/runners/incoming.py
index ddc08aa..3c69a23 100644
--- a/src/mailman_pgp/runners/incoming.py
+++ b/src/mailman_pgp/runners/incoming.py
@@ -1,6 +1,5 @@
"""The encryption-aware incoming runner."""
-from gpgmime import is_encrypted, is_signed
from mailman.config import config as mailman_config
from mailman.core.runner import Runner
from mailman.email.message import Message
@@ -9,6 +8,7 @@ from public import public
from mailman_pgp.config import config
from mailman_pgp.model.list import EncryptedMailingList
+from mailman_pgp.pgp.mime import PGPMIMEWrapper
@public
@@ -25,10 +25,11 @@ class IncomingRunner(Runner):
listid=mlist.list_id)
return False
# Is the message encrypted?
- if is_signed(msg):
+ mime = PGPMIMEWrapper(msg)
+ if mime.is_mime_signed():
# only signed.
pass
- elif is_encrypted(msg):
+ elif mime.is_mime_encrypted():
# definitely encrypted, might still be signed
pass
else: