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

* Fix the processing of subscription confirmation messages when the mailing

   list is set to confirm-then-moderate.  (Closes #114)
parent 8a07200b
Pipeline #216330 passed with stage
......@@ -54,11 +54,16 @@ class Confirm:
results.confirms = tokens
token, token_owner, member = IRegistrar(mlist).confirm(token)
if token is None:
new_token, token_owner, member = IRegistrar(mlist).confirm(token)
if new_token is None:
assert token_owner is TokenOwner.no_one, token_owner
assert member is not None, member
succeeded = True
elif token_owner is TokenOwner.moderator:
# This must have been a confirm-then-moderator subscription.
assert new_token != token
assert member is None, member
succeeded = True
assert token_owner is not TokenOwner.no_one, token_owner
assert member is None, member
......@@ -19,6 +19,7 @@
__all__ = [
......@@ -26,12 +27,14 @@ import unittest
from import create_list
from mailman.commands.eml_confirm import Confirm
from mailman.config import config
from import Message
from mailman.interfaces.command import ContinueProcessing
from mailman.interfaces.mailinglist import SubscriptionPolicy
from mailman.interfaces.registrar import IRegistrar
from mailman.interfaces.usermanager import IUserManager
from mailman.runners.command import Results
from mailman.testing.helpers import get_queue_messages
from mailman.runners.command import CommandRunner, Results
from mailman.testing.helpers import get_queue_messages, make_testable_runner
from mailman.testing.layers import ConfigLayer
from zope.component import getUtility
......@@ -76,3 +79,82 @@ class TestConfirm(unittest.TestCase):
# There will be no messages in the queue.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 0)
class TestEmailResponses(unittest.TestCase):
"""Test the `confirm` command through the command runner."""
layer = ConfigLayer
def setUp(self):
self._mlist = create_list('[email protected]')
def test_confirm_then_moderate_workflow(self):
# Issue #114 describes a problem when confirming the moderation email.
self._mlist.subscription_policy = \
bart = getUtility(IUserManager).create_address(
'[email protected]', 'Bart Person')
# Clear any previously queued confirmation messages.
self._token, token_owner, member = IRegistrar(self._mlist).register(
# There should now be one email message in the virgin queue, i.e. the
# confirmation message sent to Bart.
items = get_queue_messages('virgin')
self.assertEqual(len(items), 1)
msg = items[0].msg
# Confirmations come first, so this one goes to the subscriber.
self.assertEqual(msg['to'], '[email protected]')
confirm, token = str(msg['subject']).split()
self.assertEqual(confirm, 'confirm')
self.assertEqual(token, self._token)
# Craft a confirmation response with the expected tokens.
user_response = Message()
user_response['From'] = '[email protected]'
user_response['To'] = 'test-confirm+{}'.format(token)
user_response['Subject'] = 'Re: confirm {}'.format(token)
# Process the message through the command runner.
user_response, listid='')
make_testable_runner(CommandRunner, 'command').run()
# There are now two messages in the virgin queue. One is going to the
# subscriber containing the results of their confirmation message, and
# the other is to the moderators informing them that they need to
# handle the moderation queue.
items = get_queue_messages('virgin')
self.assertEqual(len(items), 2)
if items[0].msg['to'] == '[email protected]':
results = items[0].msg
moderator_msg = items[1].msg
results = items[1].msg
moderator_msg = items[0].msg
# Check the moderator message first.
self.assertEqual(moderator_msg['to'], '[email protected]')
'New subscription request to Test from [email protected]')
lines = moderator_msg.get_payload().splitlines()
'For: Bart Person <[email protected]>')
self.assertEqual(lines[-1].strip(), 'List: [email protected]')
# Now check the results message.
str(results['subject']), 'The results of your email commands')
self.assertMultiLineEqual(results.get_payload(), """\
The results of your email command are provided below.
- Original message details:
From: [email protected]
Subject: Re: confirm {}
Date: n/a
Message-ID: n/a
- Results:
- Done.
......@@ -43,6 +43,8 @@ Bugs
* Collapse multiple ``Re:`` in Subject headers. Given by Mark Sapiro.
(Closes: #147)
* Added Trove classifiers to (Closes: #152)
* Fix the processing of subscription confirmation messages when the mailing
list is set to confirm-then-moderate. (Closes #114)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment