"""
password [<oldpassword> <newpassword>] [address=<address>]
Retrieve or change your password. With no arguments, this returns
your current password. With arguments <oldpassword> and <newpassword>
you can change your password.
If you're posting from an address other than your membership address,
specify your membership address with `address=<address>' (no brackets
around the email address, and no quotes!). Note that in this case the
response is always sent to the subscribed address.
"""
from email.Utils import parseaddr
from Mailman import mm_cfg
from Mailman.i18n import _
STOP = 1
def gethelp(mlist):
return _(__doc__)
def process(res, args):
mlist = res.mlist
address = None
if not args:
realname, address = parseaddr(res.msg['from'])
if mlist.isMember(address):
password = mlist.getMemberPassword(address)
res.results.append(_('Your password is: %(password)s'))
return STOP
else:
listname = mlist.real_name
res.results.append(
_('You are not a member of the %(listname)s mailing list'))
return STOP
elif len(args) == 1 and args[0].startswith('address='):
address = args[0][8:]
res.returnaddr = address
if mlist.isMember(address):
password = mlist.getMemberPassword(address)
res.results.append(_('Your password is: %(password)s'))
return STOP
else:
listname = mlist.real_name
res.results.append(
_('You are not a member of the %(listname)s mailing list'))
return STOP
elif len(args) == 2:
oldpasswd = args[0]
newpasswd = args[1]
realname, address = parseaddr(res.msg['from'])
if mlist.isMember(address):
if mlist.Authenticate((mm_cfg.AuthUser, mm_cfg.AuthListAdmin),
oldpasswd, address):
mlist.setMemberPassword(address, newpasswd)
res.results.append(_('Password successfully changed.'))
else:
res.results.append(_("""\
You did not give the correct old password, so your password has not been
changed. Use the no argument version of the password command to retrieve your
current password, then try again."""))
res.results.append(_('\nUsage:'))
res.results.append(gethelp(mlist))
return STOP
else:
listname = mlist.real_name
res.results.append(
_('You are not a member of the %(listname)s mailing list'))
return STOP
elif len(args) == 3 and args[2].startswith('address='):
oldpasswd = args[0]
newpasswd = args[1]
address = args[2][8:]
res.returnaddr = address
if mlist.isMember(address):
if mlist.Authenticate((mm_cfg.AuthUser, mm_cfg.AuthListAdmin),
oldpasswd, address):
mlist.setMemberPassword(address, newpasswd)
res.results.append(_('Password successfully changed.'))
else:
res.results.append(_("""\
You did not give the correct old password, so your password has not been
changed. Use the no argument version of the password command to retrieve your
current password, then try again."""))
res.results.append(_('\nUsage:'))
res.results.append(gethelp(mlist))
return STOP
else:
listname = mlist.real_name
res.results.append(
_('You are not a member of the %(listname)s mailing list'))
return STOP