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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#! /usr/bin/env python
#
# Copyright (C) 1998,1999,2000 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.
#
# argv[1] should be the name of the list.
# argv[2] should be the list of non-digested users.
# argv[3] should be the list of digested users.
# Make sure that the list of email addresses doesn't contain any comments,
# like majordomo may throw in. For now, you just have to remove them manually.
"""Add members to a list from the command line.
Usage:
add_members [-n <file>] [-d <file>] [-c <y|n>] [-w <y|n>] [-h] listname
Where:
--non-digest-members-file <file>
-n <file>
A file containing addresses of the members to be added, one
address per line. This list of people become non-digest
members. If <file> is `-', read addresses from stdin.
--digest-members-file <file>
-d <file>
Similar to above, but these people become digest members.
--changes-msg=<y|n>
-c <y|n>
set whether or not to send the list members the `there's going to be
big changes to your list' message. defaults to no.
--welcome-msg=<y|n>
-w <y|n>
set whether or not to send the list members a welcome message,
overriding whatever the list's `send_welcome_msg' setting is.
--help
-h
Print this help message and exit.
listname
The name of the Mailman list you are adding members to. It must
already exist.
You must supply at least one of -n and -d options. At most one of the
files can be `-'.
"""
import sys
import os
import getopt
import paths
from Mailman import MailList
from Mailman import Utils
from Mailman import Message
from Mailman import Errors
from Mailman import mm_cfg
from Mailman.Handlers import HandlerAPI
from Mailman.i18n import _
def usage(status, msg=''):
print >> sys.stderr, _(__doc__)
if msg:
print >> sys.stderr, msg
sys.exit(status)
def readfile(filename):
if filename == '-':
fp = sys.stdin
closep = 0
else:
fp = open(filename)
closep = 1
# strip all the lines of whitespace and discard blank lines
lines = filter(None, [line.strip() for line in fp.readlines()])
if closep:
fp.close()
return lines
def SendExplanation(mlist, users):
adminaddr = mlist.GetAdminEmail()
d = {'listname' : mlist.real_name,
'listhost' : mlist.host_name,
'listaddr' : mlist.GetListEmail(),
'listinfo_url': mlist.GetScriptURL('listinfo', absolute=1),
'requestaddr' : mlist.GetRequestEmail(),
'adminaddr' : adminaddr,
'version' : mm_cfg.VERSION,
}
text = Utils.maketext('convert.txt', d)
subject = _('Big change in %(listname)s@%(listhost)s mailing list') % d
msg = Message.OutgoingMessage(text)
msg['From'] = adminaddr
msg['Subject'] = subject
HandlerAPI.DeliverToUser(mlist, msg, {'recips': users})
def main():
try:
opts, args = getopt.getopt(sys.argv[1:],
'n:d:c:w:h',
['non-digest-members-file=',
'digest-members-file=',
'changes-msg=',
'welcome-msg=',
'help'])
except getopt.error, msg:
usage(1, msg)
if len(args) <> 1:
usage(1)
listname = args[0].lower().strip()
nfile = None
dfile = None
send_changes_msg = 0
send_welcome_msg = -1
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-d', '--digest-members-file'):
dfile = arg
elif opt in ('-n', '--non-digest-members-file'):
nfile = arg
elif opt in ('-c', '--changes-msg'):
if arg == 'y':
send_changes_msg = 1
elif arg == 'n':
send_changes_msg = 0
else:
usage(1)
elif opt in ('-w', '--welcome-msg'):
if arg == 'y':
send_welcome_msg = 1
elif arg == 'n':
send_welcome_msg = 0
else:
usage(1)
if dfile is None and nfile is None:
usage(1)
if dfile == "-" and nfile == "-":
usage(1, _('Cannot read both digest and normal members '
'from standard input.'))
try:
ml = MailList.MailList(listname)
except Errors.MMUnknownListError:
usage(1, _('You must first create the list by running: '
'newlist %(listname)s'))
if send_welcome_msg == -1:
send_welcome_msg = ml.send_welcome_msg
try:
dmembers = []
if dfile:
try:
dmembers = readfile(dfile)
except IOError:
pass
nmembers = []
if nfile:
try:
nmembers = readfile(nfile)
except IOError:
pass
if not dmembers and not nmembers:
usage(1)
if nmembers:
nres = ml.ApprovedAddMembers(nmembers, None, 0, send_welcome_msg)
else:
nres = {}
if dmembers:
dres = ml.ApprovedAddMembers(dmembers, None, 1, send_welcome_msg)
else:
dres = {}
for result in (nres, dres):
for name in result.keys():
if result[name] is None:
pass
else:
# `name' was not subscribed, find out why. On failures,
# result[name] is set from sys.exc_info()[:2]
e, v = result[name]
if e is Errors.MMAlreadyAMember:
print >> sys.stderr, \
_('Already subscribed (skipping):'), name
elif issubclass(e, Errors.EmailAddressError):
if not name:
name = _('( blank line )')
print >> sys.stderr, \
_('Not a valid email address:'), name
if send_changes_msg:
SendExplanation(ml, nmembers + dmembers)
finally:
ml.Unlock()
main()
|