Extra archivers for Mailman 3.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
7.8 KiB

#! /usr/bin/python
# Copyright (C) 1998-2018 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
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
"""Create a new, unpopulated mailing list.
Usage: %(PROGRAM)s [options] [listname [listadmin-addr [admin-password]]]
-l language
Make the list's preferred language `language', which must be a two
letter language code.
-u urlhost
Gives the list's web interface host name.
-e emailhost
Gives the list's email domain name.
Normally the administrator is notified by email (after a prompt) that
their list has been created. This option suppresses the prompt and
This option suppresses the prompt prior to administrator notification
but still sends the notification. It can be used to make newlist
totally non-interactive but still send the notification, assuming
listname, listadmin-addr and admin-password are all specified on the
command line.
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:
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_HOST
interpolated into DEFAULT_URL_PATTERN (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 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._
C_ = i18n.C_
PROGRAM = sys.argv[0]
def usage(code, msg=''):
if code:
fd = sys.stderr
fd = sys.stdout
print >> fd, C_(__doc__)
if msg:
print >> fd, msg
def main():
opts, args = getopt.getopt(sys.argv[1:], 'hqal:u:e:',
['help', 'quiet', 'automate', 'language=',
'urlhost=', 'emailhost='])
except getopt.error, msg:
usage(1, msg)
quiet = False
automate = False
urlhost = None
emailhost = None
for opt, arg in opts:
if opt in ('-h', '--help'):
if opt in ('-q', '--quiet'):
quiet = True
if opt in ('-a', '--automate'):
automate = True
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, C_('Unknown language: %(lang)s'))
if len(args) > 0:
listname = args[0]
listname = raw_input(C_('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, C_('List already exists: %(listname)s'))
if len(args) > 1:
owner_mail = args[1]
owner_mail = raw_input(
C_('Enter the email of the person running the list: '))
if len(args) > 2:
listpasswd = args[2]
listpasswd = getpass.getpass(C_('Initial %(listname)s password: '))
# List passwords cannot be empty
listpasswd = listpasswd.strip()
if not listpasswd:
usage(1, C_('The list password cannot be empty'))
mlist = MailList.MailList()
pw = Utils.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)
if lang == mm_cfg.DEFAULT_SERVER_LANGUAGE:
langs = [lang]
langs = [lang, mm_cfg.DEFAULT_SERVER_LANGUAGE]
mlist.Create(listname, owner_mail, pw, langs=langs,
emailhost=host_name, urlhost=urlhost)
except Errors.BadListNameError, s:
usage(1, C_('Illegal list name: %(s)s'))
except Errors.EmailAddressError, s:
usage(1, C_('Bad owner email address: %(s)s') +
C_(' - owner addresses need to be fully-qualified names'
' like "owner@example.com", not just "owner".'))
except Errors.MMListAlreadyExistsError:
usage(1, C_('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
if __name__ == '__main__':