summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAurélien Bompard2012-09-17 19:37:53 +0200
committerAurélien Bompard2012-09-17 19:37:53 +0200
commitfa7e38b649dba0c0b920c94ad001c0ae136a86e8 (patch)
treebc4551517ad502a44d52eab2d52ccf509e4ce525 /src
parentd20bb305a007f156ded813f5823fcf7ded66075b (diff)
downloadmailman-fa7e38b649dba0c0b920c94ad001c0ae136a86e8.tar.gz
mailman-fa7e38b649dba0c0b920c94ad001c0ae136a86e8.tar.zst
mailman-fa7e38b649dba0c0b920c94ad001c0ae136a86e8.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/archiving/mailarchive.py19
-rw-r--r--src/mailman/archiving/mhonarc.py19
-rw-r--r--src/mailman/config/config.py31
-rw-r--r--src/mailman/config/mail_archive.cfg28
-rw-r--r--src/mailman/config/mhonarc.cfg27
-rw-r--r--src/mailman/config/schema.cfg18
6 files changed, 111 insertions, 31 deletions
diff --git a/src/mailman/archiving/mailarchive.py b/src/mailman/archiving/mailarchive.py
index e61683a09..f1427dd61 100644
--- a/src/mailman/archiving/mailarchive.py
+++ b/src/mailman/archiving/mailarchive.py
@@ -43,16 +43,18 @@ class MailArchive:
name = 'mail-archive'
- @staticmethod
- def list_url(mlist):
+ def __init__(self):
+ # Read our specific configuration file
+ self.config = config.archiver_config("mail_archive")
+
+ def list_url(self, mlist):
"""See `IArchiver`."""
if mlist.archive_policy is ArchivePolicy.public:
- return urljoin(config.archiver.mail_archive.base_url,
+ return urljoin(self.config.get("general", "base_url"),
quote(mlist.posting_address))
return None
- @staticmethod
- def permalink(mlist, msg):
+ def permalink(self, mlist, msg):
"""See `IArchiver`."""
if mlist.archive_policy is not ArchivePolicy.public:
return None
@@ -62,13 +64,12 @@ class MailArchive:
message_id_hash = msg.get('x-message-id-hash')
if message_id_hash is None:
return None
- return urljoin(config.archiver.mail_archive.base_url, message_id_hash)
+ return urljoin(self.config.get("general", "base_url"), message_id_hash)
- @staticmethod
- def archive_message(mlist, msg):
+ def archive_message(self, mlist, msg):
"""See `IArchiver`."""
if mlist.archive_policy is ArchivePolicy.public:
config.switchboards['out'].enqueue(
msg,
listname=mlist.fqdn_listname,
- recipients=[config.archiver.mail_archive.recipient])
+ recipients=[self.config.get("general", "recipient")])
diff --git a/src/mailman/archiving/mhonarc.py b/src/mailman/archiving/mhonarc.py
index 7f0af6cd6..14dcc8300 100644
--- a/src/mailman/archiving/mhonarc.py
+++ b/src/mailman/archiving/mhonarc.py
@@ -46,18 +46,20 @@ class MHonArc:
name = 'mhonarc'
- @staticmethod
- def list_url(mlist):
+ def __init__(self):
+ # Read our specific configuration file
+ self.config = config.archiver_config("mhonarc")
+
+ def list_url(self, mlist):
"""See `IArchiver`."""
# XXX What about private MHonArc archives?
- return expand(config.archiver.mhonarc.base_url,
+ return expand(self.config.get("general", "base_url"),
dict(listname=mlist.fqdn_listname,
hostname=mlist.domain.url_host,
fqdn_listname=mlist.fqdn_listname,
))
- @staticmethod
- def permalink(mlist, msg):
+ def permalink(self, mlist, msg):
"""See `IArchiver`."""
# XXX What about private MHonArc archives?
# It is the LMTP server's responsibility to ensure that the message
@@ -66,14 +68,13 @@ class MHonArc:
message_id_hash = msg.get('x-message-id-hash')
if message_id_hash is None:
return None
- return urljoin(MHonArc.list_url(mlist), message_id_hash)
+ return urljoin(self.list_url(mlist), message_id_hash)
- @staticmethod
- def archive_message(mlist, msg):
+ def archive_message(self, mlist, msg):
"""See `IArchiver`."""
substitutions = config.__dict__.copy()
substitutions['listname'] = mlist.fqdn_listname
- command = expand(config.archiver.mhonarc.command, substitutions)
+ command = expand(self.config.get("general", "command"), substitutions)
proc = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True)
diff --git a/src/mailman/config/config.py b/src/mailman/config/config.py
index f6c39fcec..3b662553e 100644
--- a/src/mailman/config/config.py
+++ b/src/mailman/config/config.py
@@ -27,9 +27,10 @@ __all__ = [
import os
import sys
+from ConfigParser import SafeConfigParser
from lazr.config import ConfigSchema, as_boolean
-from pkg_resources import resource_stream
+from pkg_resources import resource_stream, resource_exists
from string import Template
from zope.component import getUtility
from zope.event import notify
@@ -235,3 +236,31 @@ class Configuration:
"""Iterate over all the language configuration sections."""
for section in self._config.getByCategory('language', []):
yield section
+
+ def get_additional_config(self, name, keyname):
+ """Return an external ini-file as specified by the keyname."""
+ add_config = SafeConfigParser()
+ if resource_exists('mailman.config', '%s.cfg' % name):
+ included_config_file = resource_stream('mailman.config',
+ '%s.cfg' % name)
+ add_config.readfp(included_config_file)
+ # Resolve the path value from the key name
+ path = self._config
+ for key in keyname.split("."):
+ path = getattr(path, key)
+ # Load the file
+ configured_path = os.path.expanduser(path) # TODO: allow URLs
+ if not configured_path.startswith("/"):
+ # Consider it relative to the mailman.cfg file
+ for overlay in self.overlays:
+ if os.sep in overlay.filename:
+ configured_path = os.path.join(
+ os.path.dirname(overlay.filename),
+ configured_path)
+ break
+ r = add_config.read([configured_path])
+ return add_config
+
+ def archiver_config(self, name):
+ """A shortcut to self.get_additional_config() for achivers."""
+ return self.get_additional_config(name, "archiver.%s.configure" % name)
diff --git a/src/mailman/config/mail_archive.cfg b/src/mailman/config/mail_archive.cfg
new file mode 100644
index 000000000..29e716dae
--- /dev/null
+++ b/src/mailman/config/mail_archive.cfg
@@ -0,0 +1,28 @@
+# Copyright (C) 2008-2012 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman 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
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+# This is the configuration file for the mail-archive.com archiver
+
+[general]
+# The base url for the archiver. This is used to to calculate links to
+# individual messages in the archive.
+base_url: http://www.mail-archive.com/
+
+# If the archiver works by getting a copy of the message, this is the address
+# to send the copy to.
+# See: http://www.mail-archive.com/faq.html#newlist
+recipient: archive@mail-archive.com
diff --git a/src/mailman/config/mhonarc.cfg b/src/mailman/config/mhonarc.cfg
new file mode 100644
index 000000000..310c3d471
--- /dev/null
+++ b/src/mailman/config/mhonarc.cfg
@@ -0,0 +1,27 @@
+# Copyright (C) 2008-2012 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman 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
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+# This is the configuration file for the MHonArc archiver
+
+[general]
+# The base url for the archiver. This is used to to calculate links to
+# individual messages in the archive.
+base_url: http://$hostname/archives/$fqdn_listname
+
+# If the archiver works by calling a command on the local machine, this is the
+# command to call.
+command: /usr/bin/mhonarc -outdir /path/to/archive/$listname -add
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg
index e36d33c10..ee42e51b4 100644
--- a/src/mailman/config/schema.cfg
+++ b/src/mailman/config/schema.cfg
@@ -535,17 +535,8 @@ class: mailman.archiving.prototype.Prototype
# Set this to 'yes' to enable the archiver.
enable: no
-# The base url for the archiver. This is used to to calculate links to
-# individual messages in the archive.
-base_url: http://archive.example.com/
-
-# If the archiver works by getting a copy of the message, this is the address
-# to send the copy to.
-recipient: archive@archive.example.com
-
-# If the archiver works by calling a command on the local machine, this is the
-# command to call.
-command: /bin/echo
+# Additional configuration for the archiver.
+configure: /path/to/file.cfg
# When sending the message to the archiver, you have the option of
# "clobbering" the Date: header, specifically to make it more sane. Some
@@ -564,17 +555,20 @@ command: /bin/echo
clobber_date: maybe
clobber_skew: 1d
+
[archiver.mhonarc]
# This is the stock MHonArc archiver.
class: mailman.archiving.mhonarc.MHonArc
-base_url: http://$hostname/archives/$fqdn_listname
+configure: $ext_dir/mhonarc.cfg
[archiver.mail_archive]
# This is the stock mail-archive.com archiver.
class: mailman.archiving.mailarchive.MailArchive
+configure: $ext_dir/mail_archive.cfg
+
[archiver.prototype]
# This is a prototypical sample archiver.