-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailman9.py
79 lines (68 loc) · 1.95 KB
/
mailman9.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
sys.path.append('/usr/lib/mailman')
from Mailman import MailList
from Mailman import MemberAdaptor
class UserDesc:
def __init__(self, userTitle, email):
self.fullname = userTitle
self.address = email
def getMembers(mlist):
members = mlist.getRegularMemberKeys()
for member in members:
if mlist.getDeliveryStatus(member) == MemberAdaptor.ENABLED:
print member
def addMember(mlist, userTitle, email):
if mlist.isMember(email):
mlist.setDeliveryStatus(email, MemberAdaptor.ENABLED)
mlist.setMemberName(email, userTitle)
else:
userdesc = UserDesc(userTitle, email)
mlist.ApprovedAddMember(userdesc, ack=False, admin_notif=False)
mlist.Save()
mlist.Unlock()
def addSendMember(mlist, userTitle, email):
userdesc = UserDesc(userTitle, email)
mlist.ApprovedAddMember(userdesc, ack=False, admin_notif=False)
mlist.setDeliveryStatus(email, MemberAdaptor.UNKNOWN)
mlist.Save()
mlist.Unlock()
def delMember(mlist, email):
mlist.DeleteMember(email, userack=True, admin_notif=False)
mlist.Save()
mlist.Unlock()
def getAdmins(mlist):
for admin in mlist.owner:
print admin
def addAdmin(mlist, email):
mlist.owner.append(email)
mlist.Save()
mlist.Unlock()
def delAdmin(mlist, email):
mlist.owner.remove(email)
mlist.Save()
mlist.Unlock()
def main():
args = sys.argv[1:]
method = args[0]
listname = args[1]
mlist = MailList.MailList(listname, lock=True)
try:
if method == 'getmembers':
getMembers(mlist)
elif method == 'addmember':
addMember(mlist, args[2], args[3])
elif method == 'addsendmember':
addSendMember(mlist, args[2], args[3])
elif method == 'delmember':
delMember(mlist, args[2])
elif method == 'getadmins':
getAdmins(mlist)
elif method == 'addadmin':
addAdmin(mlist, args[2])
elif method == 'deladmin':
delAdmin(mlist, args[2])
except Exception, e:
print e
mlist.Unlock()
if __name__ == '__main__':
main()