Commit 80b3d590 authored by Barry Warsaw's avatar Barry Warsaw

Finally remove code we're not going to use.

parent 4d9afb3d
This list is by no means complete. I'm just using it to track short term
things that I need to do.
Get rid of PickleTypes
Get rid of MailList class! (done for test suite!)
Add tests for bin/newlist and bin/rmlist
Add tests for plugins
Rework MTA plugins and add tests
Address XXX and FIXME
Fix the roster creation cruft for mailing lists
Remove Date: header from messagestore requirements (see list thread)
Handle moderation flag (see Mailman.app.membership)
Eradicate MailList.Lock() and friends.
Eradicate MemberAdapter and friends.
This diff is collapsed.
This diff is collapsed.
# Copyright (C) 1998-2009 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman 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 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman 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
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Mixin class with message delivery routines."""
from __future__ import with_statement
import logging
from email.MIMEMessage import MIMEMessage
from email.MIMEText import MIMEText
from mailman import Errors
from mailman import Message
from mailman import Utils
from mailman import i18n
from mailman.configuration import config
_ = i18n._
log = logging.getLogger('mailman.error')
mlog = logging.getLogger('mailman.mischief')
class Deliverer:
def MailUserPassword(self, user):
listfullname = self.fqdn_listname
requestaddr = self.GetRequestEmail()
# find the lowercased version of the user's address
adminaddr = self.GetBouncesEmail()
assert self.isMember(user)
if not self.getMemberPassword(user):
# The user's password somehow got corrupted. Generate a new one
# for him, after logging this bogosity.
log.error('User %s had a false password for list %s',
user, self.internal_name())
waslocked = self.Locked()
if not waslocked:
self.Lock()
try:
self.setMemberPassword(user, Utils.MakeRandomPassword())
self.Save()
finally:
if not waslocked:
self.Unlock()
# Now send the user his password
cpuser = self.getMemberCPAddress(user)
recipient = self.GetMemberAdminEmail(cpuser)
subject = _('%(listfullname)s mailing list reminder')
# Get user's language and charset
lang = self.getMemberLanguage(user)
cset = Utils.GetCharSet(lang)
password = self.getMemberPassword(user)
# TK: Make unprintables to ?
# The list owner should allow users to set language options if they
# want to use non-us-ascii characters in password and send it back.
password = unicode(password, cset, 'replace').encode(cset, 'replace')
# get the text from the template
text = Utils.maketext(
'userpass.txt',
{'user' : cpuser,
'listname' : self.real_name,
'fqdn_lname' : self.GetListEmail(),
'password' : password,
'options_url': self.GetOptionsURL(user, absolute=True),
'requestaddr': requestaddr,
'owneraddr' : self.GetOwnerEmail(),
}, lang=lang, mlist=self)
msg = Message.UserNotification(recipient, adminaddr, subject, text,
lang)
msg['X-No-Archive'] = 'yes'
msg.send(self, verp=config.VERP_PERSONALIZED_DELIVERIES)
def ForwardMessage(self, msg, text=None, subject=None, tomoderators=True):
# Wrap the message as an attachment
if text is None:
text = _('No reason given')
if subject is None:
text = _('(no subject)')
text = MIMEText(Utils.wrap(text),
_charset=Utils.GetCharSet(self.preferred_language))
attachment = MIMEMessage(msg)
notice = Message.OwnerNotification(
self, subject, tomoderators=tomoderators)
# Make it look like the message is going to the -owner address
notice.set_type('multipart/mixed')
notice.attach(text)
notice.attach(attachment)
notice.send(self)
def SendHostileSubscriptionNotice(self, listname, address):
# Some one was invited to one list but tried to confirm to a different
# list. We inform both list owners of the bogosity, but be careful
# not to reveal too much information.
selfname = self.internal_name()
mlog.error('%s was invited to %s but confirmed to %s',
address, listname, selfname)
# First send a notice to the attacked list
msg = Message.OwnerNotification(
self,
_('Hostile subscription attempt detected'),
Utils.wrap(_("""%(address)s was invited to a different mailing
list, but in a deliberate malicious attempt they tried to confirm the
invitation to your list. We just thought you'd like to know. No further
action by you is required.""")))
msg.send(self)
# Now send a notice to the invitee list
try:
# Avoid import loops
from mailman.MailList import MailList
mlist = MailList(listname, lock=False)
except Errors.MMListError:
# Oh well
return
with i18n.using_language(mlist.preferred_language):
msg = Message.OwnerNotification(
mlist,
_('Hostile subscription attempt detected'),
Utils.wrap(_("""You invited %(address)s to your list, but in a
deliberate malicious attempt, they tried to confirm the invitation to a
different list. We just thought you'd like to know. No further action by you
is required.""")))
msg.send(mlist)
def sendProbe(self, member, msg):
listname = self.real_name
# Put together the substitution dictionary.
d = {'listname': listname,
'address': member,
'optionsurl': self.GetOptionsURL(member, absolute=True),
'owneraddr': self.GetOwnerEmail(),
}
text = Utils.maketext('probe.txt', d,
lang=self.getMemberLanguage(member),
mlist=self)
# Calculate the VERP'd sender address for bounce processing of the
# probe message.
token = self.pend_new(Pending.PROBE_BOUNCE, member, msg)
probedict = {
'bounces': self.internal_name() + '-bounces',
'token': token,
}
probeaddr = '%[email protected]%s' % ((config.VERP_PROBE_FORMAT % probedict),
self.host_name)
# Calculate the Subject header, in the member's preferred language
ulang = self.getMemberLanguage(member)
with i18n.using_language(ulang):
subject = _('%(listname)s mailing list probe message')
outer = Message.UserNotification(member, probeaddr, subject,
lang=ulang)
outer.set_type('multipart/mixed')
text = MIMEText(text, _charset=Utils.GetCharSet(ulang))
outer.attach(text)
outer.attach(MIMEMessage(msg))
# Turn off further VERP'ing in the final delivery step. We set
# probe_token for the OutgoingRunner to more easily handling local
# rejects of probe messages.
outer.send(self, envsender=probeaddr, verp=False, probe_token=token)
# Copyright (C) 1998-2009 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman 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 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman 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
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Mixin class with list-digest handling methods and settings."""
import os
import errno
from mailman import Errors
from mailman import Utils
from mailman.Handlers import ToDigest
from mailman.configuration import config
from mailman.i18n import _
class Digester:
def send_digest_now(self):
# Note: Handler.ToDigest.send_digests() handles bumping the digest
# volume and issue number.
digestmbox = os.path.join(self.fullpath(), 'digest.mbox')
try:
try:
mboxfp = None
# See if there's a digest pending for this mailing list
if os.stat(digestmbox).st_size > 0:
mboxfp = open(digestmbox)
ToDigest.send_digests(self, mboxfp)
os.unlink(digestmbox)
finally:
if mboxfp:
mboxfp.close()
except OSError, e:
if e.errno <> errno.ENOENT:
raise
# List has no outstanding digests
return False
return True
def bump_digest_volume(self):
self.volume += 1
self.next_digest_number = 1
This diff is collapsed.
# Copyright (C) 1998-2009 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman 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 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman 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
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Extend mailbox.UnixMailbox.
"""
import sys
import email
import mailbox
from email.errors import MessageParseError
from email.generator import Generator
from mailman.Message import Message
from mailman.config import config
def _safeparser(fp):
try:
return email.message_from_file(fp, Message)
except MessageParseError:
# Don't return None since that will stop a mailbox iterator
return ''
class Mailbox(mailbox.PortableUnixMailbox):
def __init__(self, fp):
mailbox.PortableUnixMailbox.__init__(self, fp, _safeparser)
# msg should be an rfc822 message or a subclass.
def AppendMessage(self, msg):
# Check the last character of the file and write a newline if it isn't
# a newline (but not at the beginning of an empty file).
try:
self.fp.seek(-1, 2)
except IOError, e:
# Assume the file is empty. We can't portably test the error code
# returned, since it differs per platform.
pass
else:
if self.fp.read(1) <> '\n':
self.fp.write('\n')
# Seek to the last char of the mailbox
self.fp.seek(1, 2)
# Create a Generator instance to write the message to the file
g = Generator(self.fp)
g.flatten(msg, unixfrom=True)
# Add one more trailing newline for separation with the next message
# to be appended to the mbox.
print >> self.fp
# This stuff is used by pipermail.py:processUnixMailbox(). It provides an
# opportunity for the built-in archiver to scrub archived messages of nasty
# things like attachments and such...
def _archfactory(mailbox):
# The factory gets a file object, but it also needs to have a MailList
# object, so the clearest <wink> way to do this is to build a factory
# function that has a reference to the mailbox object, which in turn holds
# a reference to the mailing list. Nested scopes would help here, BTW,
# but we can't rely on them being around (e.g. Python 2.0).
def scrubber(fp, mailbox=mailbox):
msg = _safeparser(fp)
if msg == '':
return msg
return mailbox.scrub(msg)
return scrubber
class ArchiverMailbox(Mailbox):
# This is a derived class which is instantiated with a reference to the
# MailList object. It is build such that the factory calls back into its
# scrub() method, giving the scrubber module a chance to do its thing
# before the message is archived.
def __init__(self, fp, mlist):
scrubber_module = config.scrubber.archive_scrubber
if scrubber_module:
__import__(scrubber_module)
self._scrubber = sys.modules[scrubber_module].process
else:
self._scrubber = None
self._mlist = mlist
mailbox.PortableUnixMailbox.__init__(self, fp, _archfactory(self))
def scrub(self, msg):
if self._scrubber:
return self._scrubber(self._mlist, msg)
else:
return msg
This diff is collapsed.
# Copyright (C) 1998-2009 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman 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 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman 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
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import codecs
from cStringIO import StringIO
from email.utils import parseaddr
from mailman import Utils
from mailman import i18n
from mailman.app.membership import add_member
from mailman.config import config
from mailman.core import errors
from mailman.email.message import UserNotification
from mailman.interfaces.member import AlreadySubscribedError, DeliveryMode
from mailman.options import SingleMailingListOptions
_ = i18n._
class ScriptOptions(SingleMailingListOptions):
usage=_("""\
%prog [options]
Add members to a list. 'listname' is the name of the Mailman list you are
adding members to; the list must already exist.
You must supply at least one of -r and -d options. At most one of the
files can be '-'.
""")
def add_options(self):
super(ScriptOptions, self).add_options()
self.parser.add_option(
'-r', '--regular-members-file',
type='string', dest='regular', help=_("""\
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."""))
self.parser.add_option(
'-d', '--digest-members-file',
type='string', dest='digest', help=_("""\
Similar to -r, but these people become digest members."""))
self.parser.add_option(
'-w', '--welcome-msg',
type='yesno', metavar='<y|n>', help=_("""\
Set whether or not to send the list members a welcome message, overriding
whatever the list's 'send_welcome_msg' setting is."""))
self.parser.add_option(
'-a', '--admin-notify',
type='yesno', metavar='<y|n>', help=_("""\
Set whether or not to send the list administrators a notification on the
success/failure of these subscriptions, overriding whatever the list's
'admin_notify_mchanges' setting is."""))
def sanity_check(self):
if not self.options.listname:
self.parser.error(_('Missing listname'))
if len(self.arguments) > 0:
self.parser.print_error(_('Unexpected arguments'))
if self.options.regular is None and self.options.digest is None:
parser.error(_('At least one of -r or -d is required'))
if self.options.regular == '-' and self.options.digest == '-':
parser.error(_("-r and -d cannot both be '-'"))
def readfile(filename):
if filename == '-':
fp = sys.stdin
else:
# XXX Need to specify other encodings.
fp = codecs.open(filename, encoding='utf-8')
# Strip all the lines of whitespace and discard blank lines
try:
return set(line.strip() for line in fp if line)
finally:
if fp is not sys.stdin:
fp.close()
class Tee:
def __init__(self, outfp):
self._outfp = outfp
def write(self, msg):
sys.stdout.write(msg)
self._outfp.write(msg)
def addall(mlist, subscribers, delivery_mode, ack, admin_notify, outfp):
tee = Tee(outfp)
for subscriber in subscribers:
try:
fullname, address = parseaddr(subscriber)
# Watch out for the empty 8-bit string.
if not fullname:
fullname = u''
password = Utils.MakeRandomPassword()
add_member(mlist, address, fullname, password, delivery_mode,
unicode(config.mailman.default_language))
# XXX Support ack and admin_notify
except AlreadySubscribedError:
print >> tee, _('Already a member: $subscriber')
except errors.InvalidEmailAddress:
if not address:
print >> tee, _('Bad/Invalid email address: blank line')
else:
print >> tee, _('Bad/Invalid email address: $subscriber')
else:
print >> tee, _('Subscribing: $subscriber')
def main():
options = ScriptOptions()
options.initialize()
fqdn_listname = options.options.listname
mlist = config.db.list_manager.get(fqdn_listname)
if mlist is None:
parser.error(_('No such list: $fqdn_listname'))
# Set up defaults.
send_welcome_msg = (options.options.welcome_msg
if options.options.welcome_msg is not None
else mlist.send_welcome_msg)
admin_notify = (options.options.admin_notify
if options.options.admin_notify is not None
else mlist.admin_notify)
with i18n.using_language(mlist.preferred_language):
if options.options.digest:
dmembers = readfile(options.options.digest)
else:
dmembers = set()
if options.options.regular:
nmembers = readfile(options.options.regular)
else:
nmembers = set()
if not dmembers and not nmembers:
print _('Nothing to do.')
sys.exit(0)
outfp = StringIO()
if nmembers:
addall(mlist, nmembers, DeliveryMode.regular,
send_welcome_msg, admin_notify, outfp)
if dmembers:
addall(mlist, dmembers, DeliveryMode.mime_digests,
send_welcome_msg, admin_notify, outfp)
config.db.commit()
if admin_notify:
subject = _('$mlist.real_name subscription notification')
msg = UserNotification(
mlist.owner, mlist.no_reply_address, subject,
outfp.getvalue(), mlist.preferred_language)
msg.send(mlist)
if __name__ == '__main__':
main()
#! @[email protected]
#
# Copyright (C) 1998,1999,2000,2001,2002 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Clone a member address.
Cloning a member address means that a new member will be added who has all the
same options and passwords as the original member address. Note that this
operation is fairly trusting of the user who runs it -- it does no
verification to the new address, it does not send out a welcome message, etc.
The existing member's subscription is usually not modified in any way. If you
want to remove the old address, use the -r flag. If you also want to change
any list admin addresses, use the -a flag.
Usage:
clone_member [options] fromoldaddr tonewaddr
Where:
--listname=listname
-l listname
Check and modify only the named mailing lists. If -l is not given,
then all mailing lists are scanned from the address. Multiple -l
options can be supplied.
--remove
-r
Remove the old address from the mailing list after it's been cloned.
--admin
-a
Scan the list admin addresses for the old address, and clone or change
them too.
--quiet
-q
Do the modifications quietly.
--nomodify
-n
Print what would be done, but don't actually do it. Inhibits the
--quiet flag.
--help
-h
Print this help message and exit.
fromoldaddr (`from old address') is the old address of the user. tonewaddr
(`to new address') is the new address of the user.
"""
import sys
import getopt
import paths
from Mailman import MailList
from Mailman import Utils
from Mailman import Errors
from Mailman.i18n import _
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 dolist(mlist, options):
SPACE = ' '
if not options.quiet:
print _('processing mailing list:'), mlist.internal_name()
# scan the list owners. TBD: mlist.owner keys should be lowercase?
oldowners = mlist.owner[:]
oldowners.sort()
if options.admintoo:
if not options.quiet:
print _(' scanning list owners:'), SPACE.join(oldowners)
newowners = {}
foundp = 0
for owner in mlist.owner:
if options.lfromaddr == owner.lower():
foundp = 1
if options.remove:
continue
newowners[owner] = 1
if foundp:
newowners[options.toaddr] = 1
newowners = newowners.keys()
newowners.sort()
if options.modify:
mlist.owner = newowners
if not options.quiet:
if newowners <> oldowners:
print
print _(' new list owners:'), SPACE.join(newowners)
else:
print _('(no change)')
# see if the fromaddr is a digest member or regular member
if options.lfromaddr in mlist.getDigestMemberKeys():
digest = 1
elif options.lfromaddr in mlist.getRegularMemberKeys():
digest = 0
else:
if not options.quiet:
print _(' address not found:'), options.fromaddr
return
# Now change the membership address
try:
if options.modify:
mlist.changeMemberAddress(options.fromaddr, options.toaddr,
not options.remove)
if not options.quiet:
print _(' clone address added:'), options.toaddr
except Errors.MMAlreadyAMember:
if not options.quiet:
print _(' clone address is already a member:'), options.toaddr
if options.remove:
print _(' original address removed:'), options.fromaddr
def main():
# default options
class Options:
listnames = None
remove = 0
admintoo = 0
quiet = 0
modify = 1
# scan sysargs
try:
opts, args = getopt.getopt(
sys.argv[1:], 'arl:qnh',