diff options
| author | J08nY | 2017-07-17 19:18:54 +0200 |
|---|---|---|
| committer | J08nY | 2017-07-17 19:18:54 +0200 |
| commit | 20317c3444e0b11d8d4676dec23c34222d4d7340 (patch) | |
| tree | 42914fe88de12ecc986cc50451b7727f7a52f3fd | |
| parent | 8fe73c6364c873e1bd52286353c3f79a4486127a (diff) | |
| download | mailman-pgp-20317c3444e0b11d8d4676dec23c34222d4d7340.tar.gz mailman-pgp-20317c3444e0b11d8d4676dec23c34222d4d7340.tar.zst mailman-pgp-20317c3444e0b11d8d4676dec23c34222d4d7340.zip | |
| -rw-r--r-- | src/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman_pgp/pgp/mime.py | 2 | ||||
| -rw-r--r-- | src/mailman_pgp/rules/signature.py | 12 | ||||
| -rw-r--r-- | src/mailman_pgp/runners/incoming.py | 15 | ||||
| -rw-r--r-- | src/mailman_pgp/utils/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman_pgp/utils/email.py (renamed from src/mailman_pgp/pgp/utils.py) | 5 | ||||
| -rw-r--r-- | src/mailman_pgp/utils/moderation.py | 32 | ||||
| -rw-r--r-- | src/mailman_pgp/workflows/key_change.py | 2 | ||||
| -rw-r--r-- | src/mailman_pgp/workflows/pubkey.py | 2 |
9 files changed, 46 insertions, 24 deletions
diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/__init__.py diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py index 611c1f2..27dafa6 100644 --- a/src/mailman_pgp/pgp/mime.py +++ b/src/mailman_pgp/pgp/mime.py @@ -28,7 +28,7 @@ from pgpy import PGPKey, PGPMessage, PGPSignature from pgpy.constants import HashAlgorithm, SymmetricKeyAlgorithm from public import public -from mailman_pgp.pgp.utils import copy_headers +from mailman_pgp.utils.email import copy_headers @public diff --git a/src/mailman_pgp/rules/signature.py b/src/mailman_pgp/rules/signature.py index 7d0d348..55b9b87 100644 --- a/src/mailman_pgp/rules/signature.py +++ b/src/mailman_pgp/rules/signature.py @@ -16,7 +16,6 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """Signature checking rule for the pgp-posting-chain.""" -import logging from email.utils import parseaddr from mailman.core.i18n import _ @@ -30,16 +29,7 @@ from zope.interface import implementer from mailman_pgp.model.address import PGPAddress from mailman_pgp.model.list import PGPMailingList from mailman_pgp.pgp.wrapper import PGPWrapper - -log = logging.getLogger('mailman.plugin.pgp') - - -def record_action(msg, msgdata, action, sender, reason): - log.info('[pgp] {}{}: {}'.format( - action.name, msg.get('message-id', 'n/a'), reason)) - msgdata['moderation_action'] = action.name - msgdata['moderation_sender'] = sender - msgdata.setdefault('moderation_reasons', []).append(reason) +from mailman_pgp.utils.moderation import record_action @public diff --git a/src/mailman_pgp/runners/incoming.py b/src/mailman_pgp/runners/incoming.py index d25479c..1c81908 100644 --- a/src/mailman_pgp/runners/incoming.py +++ b/src/mailman_pgp/runners/incoming.py @@ -29,6 +29,7 @@ from public import public from mailman_pgp.config import config from mailman_pgp.model.list import PGPMailingList from mailman_pgp.pgp.wrapper import PGPWrapper +from mailman_pgp.utils.moderation import record_action log = logging.getLogger('mailman.plugin.pgp') @@ -62,10 +63,12 @@ class IncomingRunner(Runner): try: msg = wrapped.decrypt(list_key) except PGPError: - msgdata['moderation_action'] = Action.reject.name - msgdata['moderation_sender'] = msg.sender - msgdata.setdefault('moderation_reasons', []).append( - 'Message could not be decrypted.') + reason = 'Message could not be decrypted.' + log.info('[pgp] {}{}: {}'.format( + Action.reject.name, msg.get('message-id', 'n/a'), + reason)) + record_action(msg, msgdata, Action.reject, msg.sender, + reason) msgdata['pgp_moderate'] = True else: # Take the `nonencrypted_msg_action` @@ -76,9 +79,7 @@ class IncomingRunner(Runner): reason = 'Message was not encrypted.' log.info('[pgp] {}{}: {}'.format( action.name, msg.get('message-id', 'n/a'), reason)) - msgdata['moderation_action'] = action.name - msgdata['moderation_sender'] = msg.sender - msgdata.setdefault('moderation_reasons', []).append(reason) + record_action(msg, msgdata, action, msg.sender, reason) msgdata['pgp_moderate'] = True _pass_default(msg, msgdata, mlist.list_id) diff --git a/src/mailman_pgp/utils/__init__.py b/src/mailman_pgp/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/mailman_pgp/utils/__init__.py diff --git a/src/mailman_pgp/pgp/utils.py b/src/mailman_pgp/utils/email.py index a824138..4d08d8a 100644 --- a/src/mailman_pgp/pgp/utils.py +++ b/src/mailman_pgp/utils/email.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. -"""Various pgp and email utilities.""" - +"""""" def copy_headers(from_msg, to_msg, overwrite=False): """ @@ -33,4 +32,4 @@ def copy_headers(from_msg, to_msg, overwrite=False): if key not in to_msg: to_msg[key] = value if to_msg.get_unixfrom() is None: - to_msg.set_unixfrom(from_msg.get_unixfrom()) + to_msg.set_unixfrom(from_msg.get_unixfrom())
\ No newline at end of file diff --git a/src/mailman_pgp/utils/moderation.py b/src/mailman_pgp/utils/moderation.py new file mode 100644 index 0000000..a27ec48 --- /dev/null +++ b/src/mailman_pgp/utils/moderation.py @@ -0,0 +1,32 @@ +# 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/>. + +"""""" + +def record_action(msg, msgdata, action, sender, reason): + """ + + :param msg: + :param msgdata: + :param action: + :param sender: + :param reason: + :return: + """ + msgdata['moderation_action'] = action.name + msgdata['moderation_sender'] = sender + msgdata.setdefault('moderation_reasons', []).append(reason) diff --git a/src/mailman_pgp/workflows/key_change.py b/src/mailman_pgp/workflows/key_change.py index cc5b9fc..50a6c5b 100644 --- a/src/mailman_pgp/workflows/key_change.py +++ b/src/mailman_pgp/workflows/key_change.py @@ -29,7 +29,7 @@ from zope.interface import implementer from mailman_pgp.database import transaction from mailman_pgp.model.address import PGPAddress from mailman_pgp.model.list import PGPMailingList -from mailman_pgp.pgp.utils import copy_headers +from mailman_pgp.utils.email import copy_headers from mailman_pgp.pgp.wrapper import PGPWrapper CHANGE_CONFIRM_REQUEST = """\ diff --git a/src/mailman_pgp/workflows/pubkey.py b/src/mailman_pgp/workflows/pubkey.py index e9ce348..8196eef 100644 --- a/src/mailman_pgp/workflows/pubkey.py +++ b/src/mailman_pgp/workflows/pubkey.py @@ -5,7 +5,7 @@ from pgpy import PGPKey from mailman_pgp.database import transaction from mailman_pgp.model.address import PGPAddress from mailman_pgp.model.list import PGPMailingList -from mailman_pgp.pgp.utils import copy_headers +from mailman_pgp.utils.email import copy_headers from mailman_pgp.pgp.wrapper import PGPWrapper KEY_REQUEST = """\ |
