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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#! /usr/bin/env python
#
# Copyright (C) 1998 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""List all the members of a mailing list.
Usage: %(program)s [-o file] [-r] [-d] [-p] [-h] listname
Where:
--output file
-o file
Write output to specified file instead of standard out.
--regular
-r
Print just the regular (non-digest) members.
--digest
-d
Print just the digest members.
--preserve
-p
Output member addresses case preserved the way they were added to the
list. Otherwise, addresses are printed in all lowercase.
--help
-h
Print this help message and exit.
listname is the name of the mailing list to use.
Note that if neither -r or -d is supplied, both regular members are printed
first, followed by digest members, but no indication is given as to address
status.
"""
import sys
import getopt
import paths
from Mailman import MailList
from Mailman import Errors
program = sys.argv[0]
def usage(status, msg=''):
print __doc__ % globals()
if msg:
print msg
sys.exit(status)
def main():
try:
opts, args = getopt.getopt(
sys.argv[1:],
'dpro:h',
['digest', 'regular', 'preserve', 'output=', 'help'])
except getopt.error, msg:
usage(1, msg)
if len(args) <> 1:
usage(1)
listname = args[0]
outfile = None
regular = None
digest = None
preserve = None
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-o', '--output'):
outfile = arg
elif opt in ('-r', '--regular'):
regular = 1
elif opt in ('-d', '--digest'):
digest = 1
elif opt in ('-p', '--preserve'):
preserve = 1
if regular is None and digest is None:
regular = digest = 1
if outfile:
try:
fp = open(outfile, 'w')
except IOError:
print 'Could not open file for writing:', outfile
sys.exit(1)
else:
fp = sys.stdout
try:
mlist = MailList.MailList(listname, lock=0)
except Errors.MMUnknownListError:
print 'No list:', listname
sys.exit(1)
if preserve:
rmembers = mlist.GetDeliveryMembers()
dmembers = mlist.GetDigestDeliveryMembers()
else:
rmembers = mlist.GetMembers()
dmembers = mlist.GetDigestMembers()
if regular:
for addr in rmembers:
print addr
if digest:
for addr in dmembers:
print addr
if __name__ == '__main__':
main()
|