summaryrefslogtreecommitdiff
path: root/src/mailman_pgp/archivers/local_mbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/archivers/local_mbox.py')
-rw-r--r--src/mailman_pgp/archivers/local_mbox.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/mailman_pgp/archivers/local_mbox.py b/src/mailman_pgp/archivers/local_mbox.py
index 2a08c4a..99264c2 100644
--- a/src/mailman_pgp/archivers/local_mbox.py
+++ b/src/mailman_pgp/archivers/local_mbox.py
@@ -19,12 +19,17 @@
Archives messages to a mbox, locally, encrypted (TBD how),
similar to Mailman's prototype archiver.
"""
+import os
+from mailbox import mbox
+from flufl.lock import Lock
from mailman.interfaces.archiver import IArchiver
from public import public
from zope.interface import implementer
+from mailman_pgp.config import config, mm_config
from mailman_pgp.model.list import PGPMailingList
+from mailman_pgp.pgp.mime import MIMEWrapper
@public
@@ -35,17 +40,33 @@ class LocalMailboxArchiver:
name = 'pgp-mbox-local'
is_enabled = False
- def list_url(self, mlist):
+ @staticmethod
+ def list_url(mlist):
"""See `IArchiver`."""
return None
- def permalink(self, mlist, msg):
+ @staticmethod
+ def permalink(mlist, msg):
"""See `IArchiver`."""
return None
- def archive_message(self, mlist, msg):
+ @staticmethod
+ def archive_message(mlist, msg):
"""See `IArchiver`."""
pgp_list = PGPMailingList.for_list(mlist)
if not pgp_list:
return None
+ mailbox_dir = config.get_value('archiving', 'mailbox_dir')
+ mailbox_dir.mkdir(parents=True, exist_ok=True)
+
+ list_dir = mailbox_dir.joinpath(mlist.fqdn_listname)
+ mailbox = mbox(str(list_dir))
+ lock_file = os.path.join(mm_config.LOCK_DIR,
+ '{}-{}.lock'.format(mlist.fqdn_listname,
+ LocalMailboxArchiver.name)
+ )
+ wrapped = MIMEWrapper(msg)
+ encrypted = wrapped.encrypt(pgp_list.pubkey)
+ with Lock(lock_file):
+ mailbox.add(encrypted)
return None