summaryrefslogtreecommitdiff
path: root/mailman/archiving/pipermail.py
diff options
context:
space:
mode:
authorBarry Warsaw2008-07-05 11:06:37 -0400
committerBarry Warsaw2008-07-05 11:06:37 -0400
commit08400a46afb740a0e49058707969462fa7e7dddf (patch)
tree42d18be4b2bda21680e88d5a0b19495282d4aa19 /mailman/archiving/pipermail.py
parentdda21fc619518344dfc44081c64674f6374fe404 (diff)
downloadmailman-08400a46afb740a0e49058707969462fa7e7dddf.tar.gz
mailman-08400a46afb740a0e49058707969462fa7e7dddf.tar.zst
mailman-08400a46afb740a0e49058707969462fa7e7dddf.zip
Refactor the archivers so that they live in a separate sub-package. Split out
the Pipermail, Prototype, and MailArchiver plugins into separate modules. Put the archives registry on the config object and initialize it at the right time. Update plugin entry points.
Diffstat (limited to 'mailman/archiving/pipermail.py')
-rw-r--r--mailman/archiving/pipermail.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/mailman/archiving/pipermail.py b/mailman/archiving/pipermail.py
new file mode 100644
index 000000000..1e8f4f28e
--- /dev/null
+++ b/mailman/archiving/pipermail.py
@@ -0,0 +1,109 @@
+# Copyright (C) 2007-2008 by the Free Software Foundation, Inc.
+#
+# 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 2
+# 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""Pipermail archiver."""
+
+__metaclass__ = type
+__all__ = [
+ 'Pipermail',
+ ]
+
+
+import os
+
+from cStringIO import StringIO
+from string import Template
+from zope.interface import implements
+from zope.interface.interface import adapter_hooks
+
+from mailman.configuration import config
+from mailman.interfaces.archiver import IArchiver, IPipermailMailingList
+from mailman.interfaces.mailinglist import IMailingList
+
+from mailman.Archiver.HyperArch import HyperArchive
+
+
+
+class PipermailMailingListAdapter:
+ """An adapter for MailingList objects to work with Pipermail."""
+
+ implements(IPipermailMailingList)
+
+ def __init__(self, mlist):
+ self._mlist = mlist
+
+ def __getattr__(self, name):
+ return getattr(self._mlist, name)
+
+ def archive_dir(self):
+ """See `IPipermailMailingList`."""
+ if self._mlist.archive_private:
+ basedir = config.PRIVATE_ARCHIVE_FILE_DIR
+ else:
+ basedir = config.PUBLIC_ARCHIVE_FILE_DIR
+ return os.path.join(basedir, self._mlist.fqdn_listname)
+
+
+def adapt_mailing_list_for_pipermail(iface, obj):
+ """Adapt IMailingLists to IPipermailMailingList."""
+ if IMailingList.providedBy(obj) and iface is IPipermailMailingList:
+ return PipermailMailingListAdapter(obj)
+ return None
+
+adapter_hooks.append(adapt_mailing_list_for_pipermail)
+
+
+
+class Pipermail:
+ """The stock Pipermail archiver."""
+
+ implements(IArchiver)
+
+ name = 'pipermail'
+ is_enabled = False
+
+ @staticmethod
+ def list_url(mlist):
+ """See `IArchiver`."""
+ if mlist.archive_private:
+ url = mlist.script_url('private') + '/index.html'
+ else:
+ web_host = config.domains.get(mlist.host_name, mlist.host_name)
+ url = Template(config.PUBLIC_ARCHIVE_URL).safe_substitute(
+ listname=mlist.fqdn_listname,
+ hostname=web_host,
+ fqdn_listname=mlist.fqdn_listname,
+ )
+ return url
+
+ @staticmethod
+ def permalink(mlist, message):
+ """See `IArchiver`."""
+ # Not currently implemented.
+ return None
+
+ @staticmethod
+ def archive_message(mlist, message):
+ """See `IArchiver`."""
+ text = str(message)
+ fileobj = StringIO(text)
+ h = HyperArchive(IPipermailMailingList(mlist))
+ h.processUnixMailbox(fileobj)
+ h.close()
+ fileobj.close()
+ # There's no good way to know the url for the archived message.
+ return None