summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/commands/eml_membership.py12
-rw-r--r--src/mailman/runners/tests/test_join.py40
2 files changed, 49 insertions, 3 deletions
diff --git a/src/mailman/commands/eml_membership.py b/src/mailman/commands/eml_membership.py
index 4f46cfac7..88f7d5722 100644
--- a/src/mailman/commands/eml_membership.py
+++ b/src/mailman/commands/eml_membership.py
@@ -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):
diff --git a/src/mailman/runners/tests/test_join.py b/src/mailman/runners/tests/test_join.py
index 69ed682e2..369880a32 100644
--- a/src/mailman/runners/tests/test_join.py
+++ b/src/mailman/runners/tests/test_join.py
@@ -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('anne@example.org' in confirmation_lines[0])
+
+ def test_join_when_already_a_member(self):
+ anne = getUtility(IUserManager).create_user('anne@example.org')
+ 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: anne@example.org
+To: test-join@example.com
+Subject: join
+
+""")
+ self._commandq.enqueue(msg, dict(listname='test@example.com'))
+ 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('anne@example.org' in confirmation_lines[0])