aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/plugin.py
blob: 3ef771cd239f310b8e81a45338c0ce43049150c2 (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
"""A PGP plugin for GNU Mailman."""

from mailman.interfaces.listmanager import ListDeletedEvent
from mailman.interfaces.plugin import IPlugin
from public import public
from zope.event import classhandler
from zope.interface import implementer

from mailman_pgp.config import config
from mailman_pgp.database import Database, transaction
from mailman_pgp.model.list import EncryptedMailingList
from mailman_pgp.pgp import PGP
from mailman_pgp.rest.root import RESTRoot


@public
@implementer(IPlugin)
class PGPMailman:
    def pre_hook(self):
        """See `IPlugin`."""
        config.load(self.name)
        config.db = Database()
        config.pgp = PGP()

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

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


@classhandler.handler(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() as session:
            # TODO shred the list key
            session.delete(encrypted_list)