diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman_pgp/chains/default.py | 1 | ||||
| -rw-r--r-- | src/mailman_pgp/commands/eml_key.py | 4 | ||||
| -rw-r--r-- | src/mailman_pgp/config/config.py | 12 | ||||
| -rw-r--r-- | src/mailman_pgp/database/__init__.py | 6 | ||||
| -rw-r--r-- | src/mailman_pgp/mta/deliver.py | 2 | ||||
| -rw-r--r-- | src/mailman_pgp/mta/tests/test_deliver.py | 6 | ||||
| -rw-r--r-- | src/mailman_pgp/rules/mark.py | 36 | ||||
| -rw-r--r-- | src/mailman_pgp/styles/base.py | 20 | ||||
| -rw-r--r-- | src/mailman_pgp/styles/tests/test_base.py | 6 |
9 files changed, 75 insertions, 18 deletions
diff --git a/src/mailman_pgp/chains/default.py b/src/mailman_pgp/chains/default.py index 314d8b8..7806a6e 100644 --- a/src/mailman_pgp/chains/default.py +++ b/src/mailman_pgp/chains/default.py @@ -35,6 +35,7 @@ class PGPChain: _link_descriptions = ( ('pgp-encryption', LinkAction.jump, 'moderation'), ('pgp-signature', LinkAction.jump, 'moderation'), + ('pgp-mark', LinkAction.defer, None), ('truth', LinkAction.jump, 'default-posting-chain') ) diff --git a/src/mailman_pgp/commands/eml_key.py b/src/mailman_pgp/commands/eml_key.py index 447ecf4..5799b8f 100644 --- a/src/mailman_pgp/commands/eml_key.py +++ b/src/mailman_pgp/commands/eml_key.py @@ -16,6 +16,7 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """The key email command.""" +import logging import copy from email.mime.text import MIMEText @@ -44,6 +45,8 @@ from mailman_pgp.workflows.key_change import (CHANGE_CONFIRM_REQUEST, from mailman_pgp.workflows.key_confirm import CONFIRM_REQUEST from mailman_pgp.workflows.key_revoke import KeyRevokeWorkflow +log = logging.getLogger('mailman.plugin.pgp.commands') + def _cmd_set(pgp_list, mlist, msg, msgdata, arguments, results): """ @@ -443,4 +446,5 @@ class KeyCommand: return ContinueProcessing.no command = SUBCOMMANDS[arguments[0]] + log.debug('key {}'.format(arguments[0])) return command(pgp_list, mlist, msg, msgdata, arguments, results) diff --git a/src/mailman_pgp/config/config.py b/src/mailman_pgp/config/config.py index 0b5fe4f..eea4f43 100644 --- a/src/mailman_pgp/config/config.py +++ b/src/mailman_pgp/config/config.py @@ -16,6 +16,7 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """Mailman PGP configuration module.""" +import logging from configparser import ConfigParser from mailman.config import config as mailman_config @@ -26,6 +27,8 @@ from public.public import public from mailman_pgp.config.converter import ConfigConverter from mailman_pgp.config.validator import ConfigValidator +log = logging.getLogger('mailman.plugin.pgp.config') + @public class Config(ConfigParser): @@ -50,12 +53,19 @@ class Config(ConfigParser): self.name = name self.read(expand_path( dict(mailman_config.plugin_configs)[self.name].configuration)) + log.debug('Config loaded.') def validate(self): - self.validator.validate(self) + try: + self.validator.validate(self) + except ValueError: + log.exception('Config did not validate.') + raise + log.debug('Config validated.') def convert(self): self.dict = self.converter.convert(self) + log.debug('Config converted.') def get_value(self, section, option): return self.dict[section][option] diff --git a/src/mailman_pgp/database/__init__.py b/src/mailman_pgp/database/__init__.py index 11ea387..2bd1feb 100644 --- a/src/mailman_pgp/database/__init__.py +++ b/src/mailman_pgp/database/__init__.py @@ -16,7 +16,7 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """Common database functions and class.""" - +import logging from contextlib import contextmanager from mailman.config import config as mailman_config @@ -29,6 +29,8 @@ from sqlalchemy.orm import scoped_session, sessionmaker from mailman_pgp.config import config from mailman_pgp.model.base import Base +log = logging.getLogger('mailman.plugin.pgp.database') + @public class Database: @@ -37,10 +39,12 @@ class Database: def __init__(self): url = config.get('db', 'url') self._url = expand(url, None, mailman_config.paths) + log.debug('Creating database at {}'.format(self._url)) self.engine = create_engine(self._url) self.scoped_session = scoped_session(sessionmaker(bind=self.engine)) Base.metadata.create_all(self.engine) self.session.commit() + log.debug('Database successfully created.') @property def session(self): diff --git a/src/mailman_pgp/mta/deliver.py b/src/mailman_pgp/mta/deliver.py index 050a740..ef4713a 100644 --- a/src/mailman_pgp/mta/deliver.py +++ b/src/mailman_pgp/mta/deliver.py @@ -50,7 +50,7 @@ def deliver(mlist, msg, msgdata): bulk_agent = BulkDelivery pgp_list = PGPMailingList.for_list(mlist) - if pgp_list: + if pgp_list and msgdata.get('pgp_is_posting', False): personalized_agent = PGPPersonalizedDelivery bulk_agent = PGPBulkDelivery diff --git a/src/mailman_pgp/mta/tests/test_deliver.py b/src/mailman_pgp/mta/tests/test_deliver.py index 3b0594f..3406d02 100644 --- a/src/mailman_pgp/mta/tests/test_deliver.py +++ b/src/mailman_pgp/mta/tests/test_deliver.py @@ -72,13 +72,15 @@ Some text. """) def test_deliver(self): - msgdata = dict(recipients=['anne@example.org', 'bart@example.org']) + msgdata = dict(recipients=['anne@example.org', 'bart@example.org'], + pgp_is_posting=True) deliver(self.mlist, self.msg, msgdata) def test_deliver_no_key(self): with transaction(): self.pgp_anne.key = None - msgdata = dict(recipients=['anne@example.org', 'bart@example.org']) + msgdata = dict(recipients=['anne@example.org', 'bart@example.org'], + pgp_is_posting=True) with self.assertRaises(SomeRecipientsFailed) as err: deliver(self.mlist, self.msg, msgdata) self.assertEqual(err.exception.temporary_failures, diff --git a/src/mailman_pgp/rules/mark.py b/src/mailman_pgp/rules/mark.py new file mode 100644 index 0000000..eda9ecf --- /dev/null +++ b/src/mailman_pgp/rules/mark.py @@ -0,0 +1,36 @@ +# 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.interfaces.rules import IRule +from public import public +from zope.interface import implementer + + +@public +@implementer(IRule) +class MarkPosting: + """""" + + name = 'pgp-mark' + description = '' + record = False + + def check(self, mlist, msg, msgdata): + """See `IRule`.""" + msgdata['pgp_is_posting'] = True + return False diff --git a/src/mailman_pgp/styles/base.py b/src/mailman_pgp/styles/base.py index 348cb04..b6e4c49 100644 --- a/src/mailman_pgp/styles/base.py +++ b/src/mailman_pgp/styles/base.py @@ -16,6 +16,8 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """""" +import logging + from public import public from mailman_pgp.config import config, mm_config @@ -23,6 +25,8 @@ from mailman_pgp.database import transaction from mailman_pgp.model.list import PGPMailingList from mailman_pgp.pgp.keygen import ListKeyGenerator +log = logging.getLogger('mailman.plugin.pgp.styles') + @public class PGPStyle: @@ -30,6 +34,12 @@ class PGPStyle: """Creates the encrypted mailing list instance for the list it's applied to. """ + pgp_list = PGPMailingList.for_list(mailing_list) + if pgp_list: + return + + generate = config.get_value('keypairs', 'autogenerate') + mailing_list.posting_chain = 'pgp-posting-chain' old_policy = mailing_list.subscription_policy.name @@ -37,15 +47,11 @@ class PGPStyle: if new_policy_name in mm_config.workflows: mailing_list.subscription_policy = new_policy_name - pgp_list = PGPMailingList.for_list(mailing_list) - if pgp_list: - return - - generate = config.get_value('keypairs', 'autogenerate') - with transaction() as session: + log.debug( + 'Creating a PGP mailing list {}.'.format(mailing_list.list_id)) pgp_list = PGPMailingList(mailing_list) if generate: keygen = ListKeyGenerator(pgp_list) - keygen.generate(True) + keygen.generate() session.add(pgp_list) diff --git a/src/mailman_pgp/styles/tests/test_base.py b/src/mailman_pgp/styles/tests/test_base.py index 6726d3a..6bb56f7 100644 --- a/src/mailman_pgp/styles/tests/test_base.py +++ b/src/mailman_pgp/styles/tests/test_base.py @@ -53,9 +53,3 @@ class TestBaseStyle(TestCase): # Manually apply base PGPStyle. base_style = PGPStyle() base_style.apply(mlist) - - pgp_list = PGPMailingList.for_list(mlist) - - # Test that we have our PGPMailingList - self.assertIsNotNone(pgp_list) - self.assertIsNotNone(pgp_list.key) |
