-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmm.py
More file actions
37 lines (29 loc) · 1.21 KB
/
mm.py
File metadata and controls
37 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3
"""Wrapper script to work around mailman cli limitations in debian buster."""
# pylint: disable=import-error
from mailman.app.membership import add_member, delete_member
from mailman.core.initialize import initialize
from mailman.database.transaction import transactional
from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.member import DeliveryMode
from mailman.interfaces.subscriptions import RequestRecord
from zope.component import getUtility
# initialize on import
initialize()
class ListManager:
"""Helper class to manage a mailman3 mailinglist."""
def __init__(self, mailinglist):
self.list = getUtility(IListManager).get(mailinglist)
@transactional
def add(self, email):
"""Add email to mailinglist."""
add_member(self.list, RequestRecord(email, '', DeliveryMode.regular,
self.list.preferred_language.code))
@transactional
def delete(self, email):
"""Remove email from mailinglist."""
delete_member(self.list, email)
@property
def members(self):
"""List of members on the mailinglist."""
return [a.email for a in self.list.members.addresses]