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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
#! @PYTHON@
#
# Copyright (C) 1998-2005 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.
"""Create a new, unpopulated mailing list.
Usage: %(PROGRAM)s [options] [listname [listadmin-addr [admin-password]]]
Options:
-l language
--language=language
Make the list's preferred language `language', which must be a two
letter language code.
-u urlhost
--urlhost=urlhost
Gives the list's web interface host name.
-e emailhost
--emailhost=emailhost
Gives the list's email domain name.
-q/--quiet
Normally the administrator is notified by email (after a prompt) that
their list has been created. This option suppresses the prompt and
notification.
-h/--help
Print this help text and exit.
You can specify as many of the arguments as you want on the command line:
you will be prompted for the missing ones.
Every Mailman list has two parameters which define the default host name for
outgoing email, and the default URL for all web interfaces. When you
configured Mailman, certain defaults were calculated, but if you are running
multiple virtual Mailman sites, then the defaults may not be appropriate for
the list you are creating.
You also specify the domain to create your new list in by typing the command
like so:
newlist --urlhost=www.mydom.ain mylist
where `www.mydom.ain' should be the base hostname for the URL to this virtual
hosts's lists. E.g. with this setting people will view the general list
overviews at http://www.mydom.ain/mailman/listinfo. Also, www.mydom.ain
should be a key in the VIRTUAL_HOSTS mapping in mm_cfg.py/Defaults.py if
the email hostname to be automatically determined.
If you want the email hostname to be different from the one looked up by the
VIRTUAL_HOSTS or if urlhost is not registered in VIRTUAL_HOSTS, you can specify
`emailhost' like so:
newlist --urlhost=www.mydom.ain --emailhost=mydom.ain mylist
where `mydom.ain' is the mail domain name. If you don't specify emailhost but
urlhost is not in the virtual host list, then mm_cfg.DEFAULT_EMAIL_HOST will
be used for the email interface.
For backward compatibility, you can also specify the domain to create your
new list in by spelling the listname like so:
mylist@www.mydom.ain
where www.mydom.ain is used for `urlhost' but it will also be used for
`emailhost' if it is not found in the virtual host table. Note that
'--urlhost' and '--emailhost' have precedence to this notation.
If you spell the list name as just `mylist', then the email hostname will be
taken from DEFAULT_EMAIL_HOST and the url will be taken from DEFAULT_URL (as
defined in your Defaults.py file or overridden by settings in mm_cfg.py).
Note that listnames are forced to lowercase.
"""
import sys
import os
import getpass
import getopt
import sha
import paths
from Mailman import mm_cfg
from Mailman import MailList
from Mailman import Utils
from Mailman import Errors
from Mailman import Message
from Mailman import i18n
_ = i18n._
PROGRAM = sys.argv[0]
def usage(code, msg=''):
if code:
fd = sys.stderr
else:
fd = sys.stdout
print >> fd, _(__doc__)
if msg:
print >> fd, msg
sys.exit(code)
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'hql:u:e:',
['help', 'quiet', 'language=',
'urlhost=', 'emailhost='])
except getopt.error, msg:
usage(1, msg)
lang = mm_cfg.DEFAULT_SERVER_LANGUAGE
quiet = 0
urlhost = None
emailhost = None
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
if opt in ('-q', '--quiet'):
quiet = 1
if opt in ('-l', '--language'):
lang = arg
if opt in ('-u', '--urlhost'):
urlhost = arg
if opt in ('-e', '--emailhost'):
emailhost = arg
# Is the language known?
if lang not in mm_cfg.LC_DESCRIPTIONS.keys():
usage(1, _('Unknown language: %(lang)s'))
if len(args) > 0:
listname = args[0]
else:
listname = raw_input(_('Enter the name of the list: '))
listname = listname.lower()
if '@' in listname:
# note that --urlhost and --emailhost have precedence
listname, domain = listname.split('@', 1)
urlhost = urlhost or domain
emailhost = emailhost or mm_cfg.VIRTUAL_HOSTS.get(domain, domain)
urlhost = urlhost or mm_cfg.DEFAULT_URL_HOST
host_name = emailhost or \
mm_cfg.VIRTUAL_HOSTS.get(urlhost, mm_cfg.DEFAULT_EMAIL_HOST)
web_page_url = mm_cfg.DEFAULT_URL_PATTERN % urlhost
if Utils.list_exists(listname):
usage(1, _('List already exists: %(listname)s'))
if len(args) > 1:
owner_mail = args[1]
else:
owner_mail = raw_input(
_('Enter the email of the person running the list: '))
if len(args) > 2:
listpasswd = args[2]
else:
listpasswd = getpass.getpass(_('Initial %(listname)s password: '))
# List passwords cannot be empty
listpasswd = listpasswd.strip()
if not listpasswd:
usage(1, _('The list password cannot be empty'))
mlist = MailList.MailList()
try:
pw = sha.new(listpasswd).hexdigest()
# Guarantee that all newly created files have the proper permission.
# proper group ownership should be assured by the autoconf script
# enforcing that all directories have the group sticky bit set
oldmask = os.umask(002)
try:
try:
mlist.Create(listname, owner_mail, pw)
finally:
os.umask(oldmask)
except Errors.BadListNameError, s:
usage(1, _('Illegal list name: %(s)s'))
except Errors.EmailAddressError, s:
usage(1, _('Bad owner email address: %(s)s'))
except Errors.MMListAlreadyExistsError:
usage(1, _('List already exists: %(listname)s'))
# Assign domain-specific attributes
mlist.host_name = host_name
mlist.web_page_url = web_page_url
# And assign the preferred language
mlist.preferred_language = lang
mlist.Save()
finally:
mlist.Unlock()
# Now do the MTA-specific list creation tasks
if mm_cfg.MTA:
modname = 'Mailman.MTA.' + mm_cfg.MTA
__import__(modname)
sys.modules[modname].create(mlist)
# And send the notice to the list owner
if not quiet:
print _('Hit enter to notify %(listname)s owner...'),
sys.stdin.readline()
siteowner = Utils.get_site_email(mlist.host_name, 'owner')
text = Utils.maketext(
'newlist.txt',
{'listname' : listname,
'password' : listpasswd,
'admin_url' : mlist.GetScriptURL('admin', absolute=1),
'listinfo_url': mlist.GetScriptURL('listinfo', absolute=1),
'requestaddr' : mlist.GetRequestEmail(),
'siteowner' : siteowner,
}, mlist=mlist)
# Set the I18N language to the list's preferred language so the header
# will match the template language. Stashing and restoring the old
# translation context is just (healthy? :) paranoia.
otrans = i18n.get_translation()
i18n.set_language(mlist.preferred_language)
try:
msg = Message.UserNotification(
owner_mail, siteowner,
_('Your new mailing list: %(listname)s'),
text, mlist.preferred_language)
msg.send(mlist)
finally:
i18n.set_translation(otrans)
if __name__ == '__main__':
main()
|