aboutsummaryrefslogtreecommitdiff
path: root/src/pgpmailman/plugin.py
blob: 820d0a97d7bb9064c719c81368ec94acd02468bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""A PGP plugin for GNU Mailman."""
from mailman.app import events
from mailman.config import config as mailman_config
from mailman.interfaces.listmanager import ListDeletedEvent
from mailman.interfaces.plugin import IPlugin
from mailman.utilities.modules import expand_path
from public import public
from zope.interface import implementer

from pgpmailman.config import config
from pgpmailman.database import Database, transaction
from pgpmailman.model.list import EncryptedMailingList
from pgpmailman.rest.root import RESTRoot


@public
@implementer(IPlugin)
class PGPMailman:
    def pre_hook(self):
        """See `IPlugin`."""
        config.read(
            expand_path(
                dict(mailman_config.plugin_configs)[self.name].configuration))
        config.db = Database()
        config.name = self.name

    def post_hook(self):
        """See `IPlugin`."""
        pass

    def rest_object(self):
        """See `IPlugin`."""
        return RESTRoot()


@events.subscribe(ListDeletedEvent)
def on_delete(mlist):
    encrypted_list = config.db.session.query(EncryptedMailingList).filter_by(
        list_id=mlist.list_id).first()
    if encrypted_list:
        with transaction():
            config.db.session.delete(encrypted_list)