28
28
from zope.event import notify
29
29
from zope.interface import implements
31
from mailman.config import config
31
from mailman.database.transaction import dbconnection
32
32
from mailman.interfaces.address import InvalidEmailAddressError
33
33
from mailman.interfaces.listmanager import (
34
34
IListManager, ListAlreadyExistsError, ListCreatedEvent, ListCreatingEvent,
44
44
implements(IListManager)
46
def create(self, fqdn_listname):
47
def create(self, store, fqdn_listname):
47
48
"""See `IListManager`."""
48
49
listname, at, hostname = fqdn_listname.partition('@')
49
50
if len(hostname) == 0:
50
51
raise InvalidEmailAddressError(fqdn_listname)
51
52
notify(ListCreatingEvent(fqdn_listname))
52
mlist = config.db.store.find(
54
55
MailingList.list_name == listname,
55
56
MailingList.mail_host == hostname).one()
57
58
raise ListAlreadyExistsError(fqdn_listname)
58
59
mlist = MailingList(fqdn_listname)
59
60
mlist.created_at = now()
60
config.db.store.add(mlist)
61
62
notify(ListCreatedEvent(mlist))
64
def get(self, fqdn_listname):
66
def get(self, store, fqdn_listname):
65
67
"""See `IListManager`."""
66
68
listname, at, hostname = fqdn_listname.partition('@')
67
return config.db.store.find(MailingList,
69
mail_host=hostname).one()
69
return store.find(MailingList,
71
mail_host=hostname).one()
71
def delete(self, mlist):
74
def delete(self, store, mlist):
72
75
"""See `IListManager`."""
73
76
fqdn_listname = mlist.fqdn_listname
74
77
notify(ListDeletingEvent(mlist))
75
config.db.store.remove(mlist)
76
79
notify(ListDeletedEvent(fqdn_listname))
79
def mailing_lists(self):
83
def mailing_lists(self, store):
80
84
"""See `IListManager`."""
81
for mlist in config.db.store.find(MailingList):
85
for mlist in store.find(MailingList):
89
def __iter__(self, store):
85
90
"""See `IListManager`."""
86
for mlist in config.db.store.find(MailingList):
91
for mlist in store.find(MailingList):
96
def names(self, store):
91
97
"""See `IListManager`."""
92
result_set = config.db.store.find(MailingList)
93
for mail_host, list_name in result_set.values(MailingList.mail_host,
98
result_set = store.find(MailingList)
99
for mail_host, list_name in result_set.values(MailingList.mail_host,
94
100
MailingList.list_name):
95
101
yield '{0}@{1}'.format(list_name, mail_host)
98
def name_components(self):
105
def name_components(self, store):
99
106
"""See `IListManager`."""
100
result_set = config.db.store.find(MailingList)
101
for mail_host, list_name in result_set.values(MailingList.mail_host,
107
result_set = store.find(MailingList)
108
for mail_host, list_name in result_set.values(MailingList.mail_host,
102
109
MailingList.list_name):
103
110
yield list_name, mail_host