1 # Copyright (C) 2007-2008 by the Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 """A mailing list manager."""
22 from zope
.interface
import implements
24 from mailman
import Errors
25 from mailman
.Utils
import split_listname
, fqdn_listname
26 from mailman
.configuration
import config
27 from mailman
.database
.mailinglist
import MailingList
28 from mailman
.interfaces
import IListManager
, ListAlreadyExistsError
32 class ListManager(object):
33 """An implementation of the `IListManager` interface."""
35 implements(IListManager
)
37 def create(self
, fqdn_listname
):
38 """See `IListManager`."""
39 listname
, hostname
= split_listname(fqdn_listname
)
40 mlist
= config
.db
.store
.find(
42 MailingList
.list_name
== listname
,
43 MailingList
.host_name
== hostname
).one()
45 raise ListAlreadyExistsError(fqdn_listname
)
46 mlist
= MailingList(fqdn_listname
)
47 mlist
.created_at
= datetime
.datetime
.now()
48 config
.db
.store
.add(mlist
)
51 def get(self
, fqdn_listname
):
52 """See `IListManager`."""
53 listname
, hostname
= split_listname(fqdn_listname
)
54 mlist
= config
.db
.store
.find(MailingList
,
56 host_name
=hostname
).one()
62 def delete(self
, mlist
):
63 """See `IListManager`."""
64 config
.db
.store
.remove(mlist
)
67 def mailing_lists(self
):
68 """See `IListManager`."""
69 for fqdn_listname
in self
.names
:
70 yield self
.get(fqdn_listname
)
74 """See `IListManager`."""
75 for mlist
in config
.db
.store
.find(MailingList
):
76 yield fqdn_listname(mlist
.list_name
, mlist
.host_name
)