aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/plugin.py')
-rw-r--r--src/mailman_pgp/plugin.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mailman_pgp/plugin.py b/src/mailman_pgp/plugin.py
new file mode 100644
index 0000000..e6eec4f
--- /dev/null
+++ b/src/mailman_pgp/plugin.py
@@ -0,0 +1,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 mailman_pgp.config import config
+from mailman_pgp.database import Database, transaction
+from mailman_pgp.model.list import EncryptedMailingList
+from mailman_pgp.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)