Commit 9ad8c1e5 authored by Barry Warsaw's avatar Barry Warsaw

Instead of using an adapter, use a utility to get the mailing list manager.

parent 0ce2f827
......@@ -96,8 +96,9 @@ case second `m'. Any other spelling is incorrect.""",
'locknix',
'munepy',
'storm',
'zope.schema',
'zope.component',
'zope.interface',
'zope.schema',
],
setup_requires = [
'setuptools_bzr',
......
......@@ -43,6 +43,7 @@ from email.Header import decode_header, make_header
from lazr.config import as_boolean
from locknix.lockfile import Lock
from string import Template
from zope.component import getUtility
from mailman import Utils
from mailman import i18n
......@@ -320,7 +321,7 @@ class Article(pipermail.Article):
listname = d.get('__listname')
if listname:
del d['__listname']
d['_mlist'] = IListManager(config).get(listname)
d['_mlist'] = getUtility(IListManager).get(listname)
if not d.has_key('_lang'):
if hasattr(self, '_mlist'):
self._lang = self._mlist.preferred_language
......
......@@ -30,6 +30,8 @@ import os
import shutil
import logging
from zope.component import getUtility
from mailman.config import config
from mailman.email.validate import validate
from mailman.interfaces.domain import (
......@@ -52,7 +54,7 @@ def create_list(fqdn_listname, owners=None):
listname, domain = fqdn_listname.split('@', 1)
if domain not in IDomainManager(config):
raise BadDomainSpecificationError(domain)
mlist = IListManager(config).create(fqdn_listname)
mlist = getUtility(IListManager).create(fqdn_listname)
for style in config.style_manager.lookup(mlist):
style.apply(mlist)
# Coordinate with the MTA, as defined in the configuration file.
......@@ -81,7 +83,7 @@ def remove_list(fqdn_listname, mailing_list=None, archives=True):
for member in mailing_list.subscribers.members:
member.unsubscribe()
# Delete the mailing list from the database.
IListManager(config).delete(mailing_list)
getUtility(IListManager).delete(mailing_list)
# Do the MTA-specific list deletion tasks
call_name(config.mta.incoming).create(mailing_list)
# Remove the list directory.
......
......@@ -28,6 +28,7 @@ __all__ = [
import datetime
from pkg_resources import resource_string
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
......@@ -137,7 +138,7 @@ class Registrar:
# to the list right now.
list_name = pendable.get('list_name')
if list_name is not None:
mlist = IListManager(config).get(list_name)
mlist = getUtility(IListManager).get(list_name)
if mlist:
addr.subscribe(mlist, MemberRole.member)
return True
......
......@@ -19,6 +19,7 @@ import os
import sys
from email import message_from_string
from zope.component import getUtility
from mailman import Utils
from mailman.configuration import config
......@@ -72,7 +73,7 @@ def main():
options.parser.error(_('Bad queue directory: $qdir'))
fqdn_listname = options.options.listname
mlist = IListManager(config).get(fqdn_listname)
mlist = getUtility(IListManager).get(fqdn_listname)
if mlist is None:
options.parser.error(_('No such list: $fqdn_listname'))
......
......@@ -18,6 +18,7 @@
import sys
from email.Utils import formataddr
from zope.component import getUtility
from mailman.config import config
from mailman.core import errors
......@@ -143,7 +144,7 @@ def main():
else:
fp = sys.stdout
mlist = IListManager(config).get(fqdn_listname)
mlist = getUtility(IListManager).get(fqdn_listname)
if mlist is None:
options.parser.error(_('No such list: $fqdn_listname'))
......
......@@ -18,8 +18,9 @@
import sys
import optparse
from zope.component import getUtility
from mailman.MailList import MailList
from mailman.configuration import config
from mailman.i18n import _
from mailman.initialize import initialize
from mailman.interfaces.listmanager import IListManager
......@@ -54,12 +55,12 @@ def main():
parser, opts, args = parseargs()
initialize(opts.config)
listmgr = IListManager(config)
listnames = set(args or listmgr.names)
list_manager = getUtility(IListManager)
listnames = set(args or list_manager.names)
bylist = {}
for listname in listnames:
mlist = listmgr.get(listname)
mlist = list_manager.get(listname)
addrs = [addr.address for addr in mlist.owners.addresses]
if opts.moderators:
addrs.extend([addr.address for addr in mlist.moderators.addresses])
......
......@@ -19,6 +19,8 @@ import os
import sys
import optparse
from zope.component import getUtility
from mailman import interact
from mailman.config import config
from mailman.core.initialize import initialize
......@@ -41,7 +43,7 @@ def do_list(listname, args, func):
# XXX FIXME Remove this when this script is converted to
# MultipleMailingListOptions.
listname = listname.decode(sys.getdefaultencoding())
mlist = IListManager(config).get(listname)
mlist = getUtility(IListManager).get(listname)
if mlist is None:
print >> sys.stderr, _('Unknown list: $listname')
else:
......@@ -202,7 +204,7 @@ def main():
r = None
if opts.all:
r = [do_list(listname, args, func)
for listname in config.list_manager.names]
for listname in getUtility(IListManager).names]
elif dolist:
listname = args.pop(0).lower().strip()
r = do_list(listname, args, func)
......
......@@ -27,6 +27,7 @@ __all__ = [
]
from zope.component import getUtility
from zope.interface import implements
from mailman.Utils import maketext
......@@ -76,7 +77,7 @@ class Lists:
def process(self, args):
"""See `ICLISubCommand`."""
mailing_lists = []
list_manager = IListManager(config)
list_manager = getUtility(IListManager)
# Gather the matching mailing lists.
for fqdn_name in sorted(list_manager.names):
mlist = list_manager.get(fqdn_name)
......@@ -252,7 +253,7 @@ remove any residual archives."""))
assert len(args.listname) == 1, (
'Unexpected positional arguments: %s' % args.listname)
fqdn_listname = args.listname[0]
mlist = IListManager(config).get(fqdn_listname)
mlist = getUtility(IListManager).get(fqdn_listname)
if mlist is None:
if args.archives:
log(_('No such list: $fqdn_listname; '
......
......@@ -29,6 +29,7 @@ import sys
import codecs
from email.utils import parseaddr
from zope.component import getUtility
from zope.interface import implements
from mailman.app.membership import add_member
......@@ -68,7 +69,7 @@ class Members:
assert len(args.listname) == 1, (
'Unexpected positional arguments: %s' % args.listname)
fqdn_listname = args.listname[0]
mlist = IListManager(config).get(fqdn_listname)
mlist = getUtility(IListManager).get(fqdn_listname)
if mlist is None:
self.parser.error(_('No such list: $fqdn_listname'))
if args.filename == '-':
......
......@@ -37,7 +37,8 @@ the mailing list and domain will be created.
Now both the domain and the mailing list exist in the database.
>>> from mailman.interfaces.listmanager import IListManager
>>> list_manager = IListManager(config)
>>> from zope.component import getUtility
>>> list_manager = getUtility(IListManager)
>>> list_manager.get('[email protected]')
<mailing list "[email protected]" at ...>
......
......@@ -9,7 +9,8 @@ A system administrator can remove mailing lists by the command line.
<mailing list "[email protected]" at ...>
>>> from mailman.interfaces.listmanager import IListManager
>>> list_manager = IListManager(config)
>>> from zope.component import getUtility
>>> list_manager = getUtility(IListManager)
>>> list_manager.get('[email protected]')
<mailing list "[email protected]" at ...>
......
......@@ -6,12 +6,6 @@
<!-- adapters -->
<adapter
for="mailman.config.config.IConfiguration"
provides="mailman.interfaces.listmanager.IListManager"
factory="mailman.database.listmanager.ListManager"
/>
<adapter
for="mailman.interfaces.domain.IDomain"
provides="mailman.interfaces.registrar.IRegistrar"
......@@ -36,4 +30,10 @@
factory="mailman.database.domain.DomainManager"
/>
<!-- utilities -->
<utility
factory="mailman.database.listmanager.ListManager"
provides="mailman.interfaces.listmanager.IListManager"
/>
</configure>
......@@ -55,7 +55,6 @@ class StockDatabase:
def __init__(self):
self.url = None
self.list_manager = None
self.user_manager = None
self.message_store = None
self.pendings = None
......
......@@ -29,31 +29,23 @@ import datetime
from zope.interface import implements
from mailman.config import config
from mailman.database.mailinglist import MailingList
from mailman.interfaces.listmanager import IListManager, ListAlreadyExistsError
from mailman.interfaces.rest import IResolvePathNames
class ListManager(object):
class ListManager:
"""An implementation of the `IListManager` interface."""
implements(IListManager, IResolvePathNames)
def __init__(self, config):
"""Create a list manager.
:param config: The configuration object.
:type config: `IConfiguration`
"""
self.config = config
self.store = config.db.store
# pylint: disable-msg=R0201
def create(self, fqdn_listname):
"""See `IListManager`."""
listname, hostname = fqdn_listname.split('@', 1)
mlist = self.store.find(
mlist = config.db.store.find(
MailingList,
MailingList.list_name == listname,
MailingList.host_name == hostname).one()
......@@ -61,13 +53,13 @@ class ListManager(object):
raise ListAlreadyExistsError(fqdn_listname)
mlist = MailingList(fqdn_listname)
mlist.created_at = datetime.datetime.now()
self.store.add(mlist)
config.db.store.add(mlist)
return mlist
def get(self, fqdn_listname):
"""See `IListManager`."""
listname, hostname = fqdn_listname.split('@', 1)
mlist = self.store.find(MailingList,
mlist = config.db.store.find(MailingList,
list_name=listname,
host_name=hostname).one()
if mlist is not None:
......@@ -77,7 +69,7 @@ class ListManager(object):
def delete(self, mlist):
"""See `IListManager`."""
self.store.remove(mlist)
config.db.store.remove(mlist)
@property
def mailing_lists(self):
......@@ -88,7 +80,7 @@ class ListManager(object):
@property
def names(self):
"""See `IListManager`."""
for mlist in self.store.find(MailingList):
for mlist in config.db.store.find(MailingList):
yield '{0}@{1}'.format(mlist.list_name, mlist.host_name)
def get_mailing_lists(self):
......
......@@ -14,7 +14,8 @@ essentially equivalent to rejecting the message with notification. Mailing
lists can bounce a message with an optional error message.
>>> from mailman.interfaces.listmanager import IListManager
>>> mlist = IListManager(config).create('[email protected]')
>>> from zope.component import getUtility
>>> mlist = getUtility(IListManager).create('[email protected]')
>>> mlist.preferred_language = 'en'
Any message can be bounced.
......
Application level list lifecycle
--------------------------------
=================================
Application level list life cycle
=================================
The low-level way to create and delete a mailing list is to use the
IListManager interface. This interface simply adds or removes the appropriate
......@@ -20,7 +21,7 @@ which performs additional tasks such as:
Posting address validation
--------------------------
==========================
If you try to use the higher-level interface to create a mailing list with a
bogus posting address, you get an exception.
......@@ -40,7 +41,7 @@ Mailman yet, you get an exception.
Creating a list applies its styles
----------------------------------
==================================
Start by registering a test style.
......@@ -71,7 +72,7 @@ list styles.
Creating a list with owners
---------------------------
===========================
You can also specify a list of owner email addresses. If these addresses are
not yet known, they will be registered, and new users will be linked to them.
......@@ -118,7 +119,7 @@ the system, they won't be created again.
Removing a list
---------------
===============
Removing a mailing list deletes the list, all its subscribers, and any related
artifacts.
......@@ -127,7 +128,8 @@ artifacts.
>>> remove_list(mlist_2.fqdn_listname, mlist_2, True)
>>> from mailman.interfaces.listmanager import IListManager
>>> print IListManager(config).get('[email protected]')
>>> from zope.component import getUtility
>>> print getUtility(IListManager).get('[email protected]')
None
We should now be able to completely recreate the mailing list.
......
......@@ -8,7 +8,8 @@ configuration variable MANAGERS_INIT_FUNCTION. The instance is accessible
on the global config object.
>>> from mailman.interfaces.listmanager import IListManager
>>> list_manager = IListManager(config)
>>> from zope.component import getUtility
>>> list_manager = getUtility(IListManager)
Creating a mailing list
......
======================
Mailing list addresses
======================
Every mailing list has a number of addresses which are publicly available.
These are defined in the IMailingListAddresses interface.
>>> from mailman.interfaces.listmanager import IListManager
>>> mlist = IListManager(config).create('[email protected]')
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('[email protected]')
The posting address is where people send messages to be posted to the mailing
list. This is exactly the same as the fully qualified list name.
......@@ -56,7 +57,7 @@ deprecated.
Email confirmations
-------------------
===================
Email confirmation messages are sent when actions such as subscriptions need
to be confirmed. It requires that a cookie be provided, which will be
......
......@@ -15,7 +15,9 @@ modify the mailing list any way it wants.
Let's start with a vanilla mailing list and a default style manager.
>>> from mailman.interfaces.listmanager import IListManager
>>> mlist = IListManager(config).create('[email protected]')
>>> from zope.component import getUtility
>>> mlist = getUtility(IListManager).create('[email protected]')
>>> from mailman.styles.manager import StyleManager
>>> style_manager = StyleManager()
>>> style_manager.populate()
......
......@@ -84,9 +84,6 @@ class IDatabase(Interface):
def abort():
"""Abort the current transaction."""
list_manager = Attribute(
"""The IListManager instance provided by the database layer.""")
user_manager = Attribute(
"""The IUserManager instance provided by the database layer.""")
......
......@@ -34,6 +34,7 @@ import logging
import datetime
from locknix.lockfile import Lock
from zope.component import getUtility
from zope.interface import implements
from mailman import Utils
......@@ -80,7 +81,7 @@ class LMTP:
# Sort all existing mailing list names first by domain, then my local
# part. For postfix we need a dummy entry for the domain.
by_domain = {}
for mailing_list in IListManager(config).mailing_lists:
for mailing_list in getUtility(IListManager).mailing_lists:
by_domain.setdefault(mailing_list.host_name, []).append(
mailing_list.list_name)
with open(path + '.new', 'w') as fp:
......
......@@ -47,6 +47,7 @@ import traceback
from cStringIO import StringIO
from lazr.config import as_boolean, as_timedelta
from zope.component import getUtility
from zope.interface import implements
from mailman import i18n
......@@ -418,7 +419,7 @@ class Runner:
#
# Find out which mailing list this message is destined for.
listname = unicode(msgdata.get('listname'))
mlist = IListManager(config).get(listname)
mlist = getUtility(IListManager).get(listname)
if mlist is None:
elog.error('Dequeuing message destined for missing list: %s',
listname)
......
......@@ -37,6 +37,7 @@ import logging
import asyncore
from email.utils import parseaddr
from zope.component import getUtility
from mailman.config import config
from mailman.database.transaction import txn
......@@ -134,7 +135,7 @@ class LMTPRunner(Runner, smtpd.SMTPServer):
try:
# Refresh the list of list names every time we process a message
# since the set of mailing lists could have changed.
listnames = set(IListManager(config).names)
listnames = set(getUtility(IListManager).names)
qlog.debug('listnames: %s', listnames)
# Parse the message data. If there are any defects in the
# message, reject it right away; it's probably spam.
......
......@@ -55,7 +55,8 @@ instead of posting directly to the URL.
The mailing list exists in the database.
>>> from mailman.interfaces.listmanager import IListManager
>>> IListManager(config).get('[email protected]')
>>> from zope.component import getUtility
>>> getUtility(IListManager).get('[email protected]')
<mailing list "[email protected]" at ...>
# The above starts a Storm transaction, which will lock the database
......
......@@ -28,6 +28,7 @@ __all__ = [
import logging
from zope.component import getUtility
from zope.interface import implements
from zope.traversing.browser.interfaces import IAbsoluteURL
......@@ -82,7 +83,7 @@ class FallbackURLMapper(BasicURLMapper):
return ''
urls = {
system: 'system',
IListManager(config): 'lists',
getUtility(IListManager): 'lists',
}
return urls[ob]
......
......@@ -35,6 +35,7 @@ import logging
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
from lazr.restful.simple import Request
from zope.component import getUtility
from zope.interface import implements
from zope.publisher.publish import publish
......@@ -80,7 +81,7 @@ class AdminWebServiceApplication:
top_level = dict(
system=system,
domains=IDomainCollection(IDomainManager(config)),
lists=IListManager(config),
lists=getUtility(IListManager),
)
next_step = top_level.get(name)
log.debug('Top level name: %s -> %s', name, next_step)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment