Commit 49d5cdcd authored by Barry Warsaw's avatar Barry Warsaw

Implement the 'leave' email command.

parent f7cbf566
==================
The 'join' command
==================
......@@ -23,7 +24,7 @@ The mail command 'join' subscribes an email address to the mailing list.
No address to join
------------------
==================
>>> from mailman.email.message import Message
>>> from mailman.queue.command import Results
......@@ -57,7 +58,7 @@ The 'subscribe' command is an alias.
Joining the sender
------------------
==================
When the message has a From field, that address will be subscribed.
......@@ -140,7 +141,7 @@ Anne is also now a member of the mailing list.
Joining a second list
---------------------
=====================
>>> mlist_2 = create_list('[email protected]')
>>> msg = message_from_string("""\
......@@ -170,3 +171,34 @@ One Anne confirms this subscription, she becomes a member of the mailing list.
>>> print mlist_2.members.get_member('[email protected]')
<Member: Anne Person <[email protected]>
on [email protected] as MemberRole.member>
Leaving a mailing list
======================
The mail command 'leave' unsubscribes an email address from the mailing list.
'unsubscribe' is an alias for 'leave'.
>>> command = config.commands['leave']
>>> print command.name
leave
>>> print command.description
Leave this mailing list. You will be asked to confirm your request.
Anne is a member of the [email protected] mailing list, when she decides to
leave it. She sends a message to the -leave address for the list and is sent
a confirmation message for her request.
>>> results = Results()
>>> print command.process(mlist_2, msg, {}, (), results)
ContinueProcessing.yes
>>> print unicode(results)
The results of your email command are provided below.
<BLANKLINE>
Anne Person <[email protected]> left [email protected]
<BLANKLINE>
Anne is no longer a member of the mailing list.
>>> print mlist_2.members.get_member('[email protected]')
None
......@@ -29,6 +29,7 @@ __all__ = [
from email.utils import formataddr, parseaddr
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
......@@ -37,6 +38,7 @@ from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.domain import IDomainManager
from mailman.interfaces.member import DeliveryMode
from mailman.interfaces.registrar import IRegistrar
from mailman.interfaces.usermanager import IUserManager
......@@ -63,7 +65,8 @@ example:
"""See `IEmailCommand`."""
# Parse the arguments.
address, delivery_mode = self._parse_arguments(arguments)
if address is None:
# address could be None or the empty string.
if not address:
real_name, address = parseaddr(msg['from'])
# Address could be None or the empty string.
if not address:
......@@ -140,11 +143,25 @@ class Leave:
name = 'leave'
argument_description = ''
description = ''
description = _(
'Leave this mailing list. You will be asked to confirm your request.')
def process(self, mlist, msg, msgdata, arguments, results):
"""See `IEmailCommand`."""
person = msg['from']
address = msg.sender
if not address:
print >> results, _(
'$self.name: No valid address found to unsubscribe')
return ContinueProcessing.no
member = mlist.members.get_member(address)
if member is None:
print >> results, _(
'$self.name: $address is not a member of $mlist.fqdn_listname')
return ContinueProcessing.no
member.unsubscribe()
# Get the user's full name.
user = getUtility(IUserManager).get_user(address)
person = formataddr((user.real_name, address))
print >> results, _('$person left $mlist.fqdn_listname')
return ContinueProcessing.yes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment