cmd_unsubscribe.py [plain text]
"""
unsubscribe [password] [address=<address>]
Unsubscribe from the mailing list. If given, your password must match
your current password. If omitted, a confirmation email will be sent
to the unsubscribing address. If you wish to unsubscribe an address
other than the address you sent this request from, you may specify
`address=<address>' (no brackets around the email address, and no
quotes!)
"""
from email.Utils import parseaddr
from Mailman import Errors
from Mailman.i18n import _
STOP = 1
def gethelp(mlist):
return _(__doc__)
def process(res, args):
mlist = res.mlist
password = None
address = None
argnum = 0
for arg in args:
if arg.startswith('address='):
address = arg[8:]
elif argnum == 0:
password = arg
else:
res.results.append(_('Usage:'))
res.results.append(gethelp(mlist))
return STOP
argnum += 1
if address is None:
realname, address = parseaddr(res.msg['from'])
if not mlist.isMember(address):
listname = mlist.real_name
res.results.append(
_('%(address)s is not a member of the %(listname)s mailing list'))
return STOP
if mlist.unsubscribe_policy:
try:
mlist.DeleteMember(address, 'mailcmd')
except Errors.MMNeedApproval:
res.results.append(_("""\
Your unsubscription request has been forwarded to the list administrator for
approval."""))
elif password is None:
cpaddr = mlist.getMemberCPAddress(address)
mlist.ConfirmUnsubscription(cpaddr)
res.respond = 0
else:
oldpw = mlist.getMemberPassword(address)
if oldpw <> password:
res.results.append(_('You gave the wrong password'))
return STOP
mlist.ApprovedDeleteMember(address, 'mailcmd')
res.results.append(_('Unsubscription request succeeded.'))