aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman_pgp/chains/default.py1
-rw-r--r--src/mailman_pgp/pgp/tests/base.py4
-rw-r--r--src/mailman_pgp/pgp/tests/test_wrapper.py2
-rw-r--r--src/mailman_pgp/rules/encryption.py37
-rw-r--r--src/mailman_pgp/runners/incoming.py27
5 files changed, 64 insertions, 7 deletions
diff --git a/src/mailman_pgp/chains/default.py b/src/mailman_pgp/chains/default.py
index 8fc22bf..0a833d3 100644
--- a/src/mailman_pgp/chains/default.py
+++ b/src/mailman_pgp/chains/default.py
@@ -33,6 +33,7 @@ class PGPChain:
description = _('The PGP enabled moderation chain.')
_link_descriptions = (
+ ('encryption', LinkAction.jump, 'moderation'),
('signature', LinkAction.jump, 'moderation'),
('truth', LinkAction.jump, 'default-posting-chain')
)
diff --git a/src/mailman_pgp/pgp/tests/base.py b/src/mailman_pgp/pgp/tests/base.py
index d64116d..ccdf7dd 100644
--- a/src/mailman_pgp/pgp/tests/base.py
+++ b/src/mailman_pgp/pgp/tests/base.py
@@ -16,8 +16,8 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
""""""
-import unittest
from email import message_from_file
+from unittest import TestCase
from pgpy import PGPKey
from pkg_resources import resource_filename
@@ -34,7 +34,7 @@ def load_key(path):
return key
-class WrapperTestCase(unittest.TestCase):
+class WrapperTestCase(TestCase):
wrapper = None
def is_signed(self, message, signed):
diff --git a/src/mailman_pgp/pgp/tests/test_wrapper.py b/src/mailman_pgp/pgp/tests/test_wrapper.py
index c16152f..7cd5541 100644
--- a/src/mailman_pgp/pgp/tests/test_wrapper.py
+++ b/src/mailman_pgp/pgp/tests/test_wrapper.py
@@ -18,7 +18,7 @@
"""Tests for the combined wrapper."""
from parameterized import parameterized
-from mailman_pgp.pgp.tests.base import WrapperTestCase, load_message, load_key
+from mailman_pgp.pgp.tests.base import load_key, load_message, WrapperTestCase
from mailman_pgp.pgp.wrapper import PGPWrapper
diff --git a/src/mailman_pgp/rules/encryption.py b/src/mailman_pgp/rules/encryption.py
new file mode 100644
index 0000000..b2deb8d
--- /dev/null
+++ b/src/mailman_pgp/rules/encryption.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+""""""
+
+from mailman.core.i18n import _
+from mailman.interfaces.rules import IRule
+from public.public import public
+from zope.interface import implementer
+
+
+@public
+@implementer(IRule)
+class Encryption:
+ """"""
+
+ name = 'encryption'
+ description = _("""""")
+ record = True
+
+ def check(self, mlist, msg, msgdata):
+ """See `IRule`."""
+ return msgdata.get('pgp_moderate', False)
diff --git a/src/mailman_pgp/runners/incoming.py b/src/mailman_pgp/runners/incoming.py
index 5d55780..4a01b14 100644
--- a/src/mailman_pgp/runners/incoming.py
+++ b/src/mailman_pgp/runners/incoming.py
@@ -28,6 +28,12 @@ from mailman_pgp.model.list import PGPMailingList
from mailman_pgp.pgp.wrapper import PGPWrapper
+def _pass_default(msg, msgdata, listid):
+ inq = config.get('queues', 'in')
+ mailman_config.switchboards[inq].enqueue(msg, msgdata,
+ listid=listid)
+
+
@public
class IncomingRunner(Runner):
def _dispose(self, mlist: MailingList, msg: Message, msgdata: dict):
@@ -37,14 +43,27 @@ class IncomingRunner(Runner):
pgp_list = PGPMailingList.query().filter_by(
list_id=mlist.list_id).first()
if not pgp_list:
- inq = config.get('queues', 'in')
- mailman_config.switchboards[inq].enqueue(msg, msgdata,
- listid=mlist.list_id)
+ _pass_default(msg, msgdata, mlist.list_id)
return False
wrapped = PGPWrapper(msg)
# Is the message encrypted?
if wrapped.is_encrypted():
+ list_key = pgp_list.key
+ if list_key is None:
+ raise ValueError('List key not found.')
+ decrypted = wrapped.decrypt(list_key) # noqa
pass
else:
- pass
+ # Take the `nonencrypted_msg_action`
+ # just set some data for our `encryption` rule which will
+ # jump to the moderation chain if `pgp_moderate` is True
+ action = pgp_list.nonencrypted_msg_action
+ if action is not None:
+ msgdata['moderation_action'] = action
+ msgdata['moderation_sender'] = msg.sender
+ msgdata['moderation_reason'] = 'Message was not encrypted.'
+ msgdata['pgp_moderate'] = True
+
+ _pass_default(msg, msgdata, mlist.list_id)
+ return False