Commit bd95333e authored by Barry Warsaw's avatar Barry Warsaw

Make sure that an email subscription request is ignored for addresses which

are already members of the list.
parent f58b82cd
......@@ -34,8 +34,9 @@ from zope.interface import implements
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.member import DeliveryMode
from mailman.interfaces.member import DeliveryMode, MemberRole
from mailman.interfaces.registrar import IRegistrar
from mailman.interfaces.subscriptions import ISubscriptionService
from mailman.interfaces.usermanager import IUserManager
......@@ -81,9 +82,14 @@ example:
return ContinueProcessing.yes
joins.add(address)
results.joins = joins
getUtility(IRegistrar).register(mlist, address, real_name)
members = getUtility(ISubscriptionService).find_members(address)
person = formataddr((real_name, address))
print >> results, _('Confirmation email sent to $person')
if len(members) > 0 and members[0].role is MemberRole.member:
assert(members[0].address.email == address)
print >> results, _('$person is already a member')
else:
getUtility(IRegistrar).register(mlist, address, real_name)
print >> results, _('Confirmation email sent to $person')
return ContinueProcessing.yes
def _parse_arguments(self, arguments):
......
......@@ -27,9 +27,11 @@ __all__ = [
import unittest
from email.iterators import body_line_iterator
from zope.component import getUtility
from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.interfaces.usermanager import IUserManager
from mailman.runners.command import CommandRunner
from mailman.testing.helpers import (
get_queue_messages,
......@@ -91,3 +93,41 @@ subscribe
self.assertEqual(len(confirmation_lines), 1)
# And the confirmation line should name Anne's email address.
self.assertTrue('[email protected]' in confirmation_lines[0])
def test_join_when_already_a_member(self):
anne = getUtility(IUserManager).create_user('[email protected]')
self._mlist.subscribe(list(anne.addresses)[0])
# When someone tries to join by email and they are already a member,
# ignore the request.
msg = mfs("""\
From: [email protected]
To: [email protected]
Subject: join
""")
self._commandq.enqueue(msg, dict(listname='[email protected]'))
self._runner.run()
# There will be one message in the queue - a reply to Anne notifying
# her of the status of her command email. Because Anne is already
# subscribed to the list, she gets and needs no confirmation.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0].msg['subject'],
'The results of your email commands')
# Search the contents of the results message. There should be just
# one 'Confirmation email' line.
confirmation_lines = []
in_results = False
for line in body_line_iterator(messages[0].msg, decode=True):
line = line.strip()
if in_results:
if line.startswith('- Done'):
break
if len(line) > 0:
confirmation_lines.append(line)
if line.strip() == '- Results:':
in_results = True
# There should be exactly one confirmation line.
self.assertEqual(len(confirmation_lines), 1)
# And the confirmation line should name Anne's email address.
self.assertTrue('[email protected]' in confirmation_lines[0])
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