Commit 6c8cbfc3 authored by Barry Warsaw's avatar Barry Warsaw

* A welcome message is sent when the user confirms their subscription via

   email.

Also:
- The user's Full Name is included on the To line of a welcome message.
- Clean up some tests.
- The welcome_message_uri for lists using the default style is set to
  mailman:///welcome.txt so a welcome message is sent by default.
parent fe855654
......@@ -77,6 +77,7 @@ def send_welcome_message(mlist, address, language, delivery_mode, text=''):
# Find the IMember object which is subscribed to the mailing list, because
# from there, we can get the member's options url.
member = mlist.members.get_member(address)
user_name = member.user.real_name
options_url = member.options_url
# Get the text from the template.
text = expand(welcome, dict(
......@@ -84,7 +85,7 @@ def send_welcome_message(mlist, address, language, delivery_mode, text=''):
list_name=mlist.real_name,
listinfo_uri=mlist.script_url('listinfo'),
list_requests=mlist.request_address,
user_name=member.user.real_name,
user_name=user_name,
user_address=address,
user_options_uri=options_url,
))
......@@ -93,7 +94,8 @@ def send_welcome_message(mlist, address, language, delivery_mode, text=''):
else:
digmode = ''
msg = UserNotification(
address, mlist.request_address,
formataddr((user_name, address)),
mlist.request_address,
_('Welcome to the "$mlist.real_name" mailing list${digmode}'),
text, language)
msg['X-No-Archive'] = 'yes'
......
......@@ -31,6 +31,7 @@ from pkg_resources import resource_string
from zope.component import getUtility
from zope.interface import implements
from mailman.app.notifications import send_welcome_message
from mailman.core.i18n import _
from mailman.email.message import UserNotification
from mailman.interfaces.address import IEmailValidator
......@@ -148,13 +149,18 @@ class Registrar:
pass
address.verified_on = now()
# If this registration is tied to a mailing list, subscribe the person
# to the list right now.
# to the list right now, and possibly send a welcome message.
list_name = pendable.get('list_name')
if list_name is not None:
mlist = getUtility(IListManager).get(list_name)
if mlist:
member = mlist.subscribe(address, MemberRole.member)
member.preferences.delivery_mode = delivery_mode
if mlist.send_welcome_message:
send_welcome_message(mlist,
address.email,
mlist.preferred_language,
delivery_mode)
return True
def discard(self, token):
......
......@@ -33,6 +33,7 @@ No address to join
------------------
>>> mlist = create_list('[email protected]')
>>> mlist.send_welcome_message = False
When no address argument is given, the message's From address will be used.
If that's missing though, then an error is returned.
......
# Copyright (C) 2012 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Test the `confirm` command."""
from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'TestConfirm',
]
import unittest
from zope.component import getUtility
from mailman.app.lifecycle import create_list
from mailman.commands.eml_confirm import Confirm
from mailman.email.message import Message
from mailman.interfaces.command import ContinueProcessing
from mailman.interfaces.registrar import IRegistrar
from mailman.runners.command import Results
from mailman.testing.helpers import get_queue_messages, reset_the_world
from mailman.testing.layers import ConfigLayer
class TestConfirm(unittest.TestCase):
"""Test the `confirm` command."""
layer = ConfigLayer
def setUp(self):
self._mlist = create_list('[email protected]')
self._token = getUtility(IRegistrar).register(
self._mlist, '[email protected]', 'Anne Person')
self._command = Confirm()
# Clear the virgin queue.
get_queue_messages('virgin')
def tearDown(self):
reset_the_world()
def test_welcome_message(self):
# A confirmation causes a welcome message to be sent to the member, if
# enabled by the mailing list.
#
status = self._command.process(
self._mlist, Message(), {}, (self._token,), Results())
self.assertEqual(status, ContinueProcessing.yes)
# There should be one messages in the queue; the welcome message.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
# Grab the welcome message.
welcome = messages[0].msg
self.assertEqual(welcome['subject'],
'Welcome to the "Test" mailing list')
self.assertEqual(welcome['to'], 'Anne Person <[email protected]>')
def test_no_welcome_message(self):
# When configured not to send a welcome message, none is sent.
self._mlist.send_welcome_message = False
status = self._command.process(
self._mlist, Message(), {}, (self._token,), Results())
self.assertEqual(status, ContinueProcessing.yes)
# There will be no messages in the queue.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 0)
......@@ -70,6 +70,8 @@ Commands
`digest=` argument now accepts the following values: `no` (for regular
delivery), `mime`, or `plain`.
* Added a `help` email command.
* A welcome message is sent when the user confirms their subscription via
email.
Bug fixes
---------
......
......@@ -41,6 +41,7 @@ confirmation emails can come from some place. You also need the email
address of the user who is registering.
>>> mlist = create_list('[email protected]')
>>> mlist.send_welcome_message = False
Some amount of sanity checks are performed on the email address, although
honestly, not as much as probably should be done. Still, some patently bad
......
This diff is collapsed.
......@@ -61,7 +61,7 @@ All readable attributes for a list are available on a sub-resource.
send_welcome_message: True
volume: 1
web_host: lists.example.com
welcome_message_uri:
welcome_message_uri: mailman:///welcome.txt
Changing the full configuration
......
......@@ -8,6 +8,7 @@ number of email commands out of the box. These are processed when a message
is sent to the list's ``-request`` address.
>>> mlist = create_list('[email protected]')
>>> mlist.send_welcome_messages = False
A command in the Subject
......@@ -33,14 +34,14 @@ the sender. The command can be in the ``Subject`` header.
>>> command.run()
And now the response is in the ``virgin`` queue.
::
>>> from mailman.core.switchboard import Switchboard
>>> virgin_queue = config.switchboards['virgin']
>>> len(virgin_queue.files)
1
>>> from mailman.testing.helpers import get_queue_messages
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
>>> messages = get_queue_messages('virgin')
>>> len(messages)
1
>>> print messages[0].msg.as_string()
Subject: The results of your email commands
From: [email protected]
To: [email protected]
......@@ -59,7 +60,8 @@ And now the response is in the ``virgin`` queue.
<BLANKLINE>
- Done.
<BLANKLINE>
>>> dump_msgdata(item.msgdata)
>>> dump_msgdata(messages[0].msgdata)
_parsemsg : False
listname : [email protected]
nodecorate : True
......@@ -85,10 +87,11 @@ message is plain text.
>>> inject_message(mlist, msg, switchboard='command')
>>> command.run()
>>> len(virgin_queue.files)
>>> messages = get_queue_messages('virgin')
>>> len(messages)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
>>> print messages[0].msg.as_string()
Subject: The results of your email commands
From: [email protected]
To: [email protected]
......@@ -132,13 +135,10 @@ address, and the other is the results of his email command.
>>> inject_message(mlist, msg, switchboard='command', subaddress='join')
>>> command.run()
>>> len(virgin_queue.files)
>>> messages = get_queue_messages('virgin', sort_on='subject')
>>> len(messages)
2
>>> def sortkey(item):
... return str(item.msg['subject'])
>>> messages = sorted(get_queue_messages('virgin'), key=sortkey)
>>> from mailman.interfaces.registrar import IRegistrar
>>> from zope.component import getUtility
>>> registrar = getUtility(IRegistrar)
......@@ -152,6 +152,9 @@ address, and the other is the results of his email command.
Subject: The results of your email commands
Subject: confirm ...
.. Clear the queue
>>> ignore = get_queue_messages('virgin')
Similarly, to leave a mailing list, the user need only email the ``-leave`` or
``-unsubscribe`` address (the latter is deprecated).
::
......@@ -164,10 +167,11 @@ Similarly, to leave a mailing list, the user need only email the ``-leave`` or
>>> inject_message(mlist, msg, switchboard='command', subaddress='leave')
>>> command.run()
>>> len(virgin_queue.files)
>>> messages = get_queue_messages('virgin')
>>> len(messages)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
>>> print messages[0].msg.as_string()
Subject: The results of your email commands
From: [email protected]
To: [email protected]
......@@ -198,10 +202,11 @@ The ``-confirm`` address is also available as an implicit command.
>>> inject_message(mlist, msg, switchboard='command', subaddress='confirm')
>>> command.run()
>>> len(virgin_queue.files)
>>> messages = get_queue_messages('virgin')
>>> len(messages)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
>>> print messages[0].msg.as_string()
Subject: The results of your email commands
From: [email protected]
To: [email protected]
......@@ -241,10 +246,11 @@ looked at by the command queue.
>>> inject_message(mlist, msg, switchboard='command')
>>> command.run()
>>> len(virgin_queue.files)
>>> messages = get_queue_messages('virgin')
>>> len(messages)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
>>> print messages[0].msg.as_string()
Subject: The results of your email commands
...
<BLANKLINE>
......@@ -272,10 +278,11 @@ The ``stop`` command is an alias for ``end``.
>>> inject_message(mlist, msg, switchboard='command')
>>> command.run()
>>> len(virgin_queue.files)
>>> messages = get_queue_messages('virgin')
>>> len(messages)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
>>> print messages[0].msg.as_string()
Subject: The results of your email commands
...
<BLANKLINE>
......
......@@ -52,6 +52,7 @@ class TestConfirm(unittest.TestCase):
# Register a subscription requiring confirmation.
registrar = getUtility(IRegistrar)
self._mlist = create_list('[email protected]')
self._mlist.send_welcome_message = False
self._token = registrar.register(self._mlist, '[email protected]')
self._commandq = config.switchboards['command']
self._runner = make_testable_runner(CommandRunner, 'command')
......@@ -231,3 +232,32 @@ From: Anne Person <[email protected]>
in_results = True
self.assertEqual(len(confirmation_lines), 1)
self.assertFalse('did not match' in confirmation_lines[0])
def test_welcome_message_after_confirmation(self):
# Confirmations with a welcome message set.
self._mlist.send_welcome_message = True
self._mlist.welcome_message_uri = 'mailman:///welcome.txt'
# 'confirm' in the Subject and in the To header should not try to
# confirm the token twice.
#
# Clear out the virgin queue so that the test below only sees the
# reply to the confirmation message.
get_queue_messages('virgin')
subject = 'Re: confirm {0}'.format(self._token)
to = 'test-confirm+{0}@example.com'.format(self._token)
msg = mfs("""\
From: Anne Person <[email protected]>
""")
msg['Subject'] = subject
msg['To'] = to
self._commandq.enqueue(msg, dict(listname='[email protected]',
subaddress='confirm'))
self._runner.run()
# Now there's a email command notification and a welcome message. All
# we care about for this test is the welcome message.
messages = get_queue_messages('virgin', sort_on='subject')
self.assertEqual(len(messages), 2)
message = messages[1].msg
self.assertEqual(str(message['subject']),
'Welcome to the "Test" mailing list')
......@@ -87,7 +87,7 @@ from: .*@uplinkpro.com
mlist.anonymous_list = False
mlist.description = ''
mlist.info = ''
mlist.welcome_message_uri = ''
mlist.welcome_message_uri = 'mailman:///welcome.txt'
mlist.goodbye_message_uri = ''
mlist.subscribe_policy = 1
mlist.subscribe_auto_approval = []
......
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