summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/app/bounces.py4
-rw-r--r--src/mailman/app/docs/bounces.rst12
-rw-r--r--src/mailman/app/docs/message.rst61
-rw-r--r--src/mailman/app/tests/test_bounces.py19
-rw-r--r--src/mailman/archiving/tests/test_prototype.py20
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/email/message.py14
-rw-r--r--src/mailman/email/tests/__init__.py0
-rw-r--r--src/mailman/email/tests/test_message.py60
9 files changed, 159 insertions, 33 deletions
diff --git a/src/mailman/app/bounces.py b/src/mailman/app/bounces.py
index a9bed97ac..3816369fa 100644
--- a/src/mailman/app/bounces.py
+++ b/src/mailman/app/bounces.py
@@ -225,7 +225,9 @@ def send_probe(member, msg):
notice = MIMEText(text, _charset=mlist.preferred_language.charset)
probe.attach(notice)
probe.attach(MIMEMessage(msg))
- probe.send(mlist, envsender=probe_sender, verp=False, probe_token=token)
+ # Probes should not have the Precedence: bulk header.
+ probe.send(mlist, envsender=probe_sender, verp=False, probe_token=token,
+ add_precedence=False)
return token
diff --git a/src/mailman/app/docs/bounces.rst b/src/mailman/app/docs/bounces.rst
index f825064e3..5510f2207 100644
--- a/src/mailman/app/docs/bounces.rst
+++ b/src/mailman/app/docs/bounces.rst
@@ -12,12 +12,12 @@ Mailman can bounce messages back to the original sender. This is essentially
equivalent to rejecting the message with notification. Mailing lists can
bounce a message with an optional error message.
- >>> mlist = create_list('_xtest@example.com')
+ >>> mlist = create_list('text@example.com')
Any message can be bounced.
>>> msg = message_from_string("""\
- ... To: _xtest@example.com
+ ... To: text@example.com
... From: aperson@example.com
... Subject: Something important
...
@@ -36,7 +36,7 @@ to the original message author.
1
>>> print items[0].msg.as_string()
Subject: Something important
- From: _xtest-owner@example.com
+ From: text-owner@example.com
To: aperson@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="..."
@@ -54,7 +54,7 @@ to the original message author.
Content-Type: message/rfc822
MIME-Version: 1.0
<BLANKLINE>
- To: _xtest@example.com
+ To: text@example.com
From: aperson@example.com
Subject: Something important
<BLANKLINE>
@@ -74,7 +74,7 @@ passed in as an instance of a ``RejectMessage`` exception.
1
>>> print items[0].msg.as_string()
Subject: Something important
- From: _xtest-owner@example.com
+ From: text-owner@example.com
To: aperson@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="..."
@@ -92,7 +92,7 @@ passed in as an instance of a ``RejectMessage`` exception.
Content-Type: message/rfc822
MIME-Version: 1.0
<BLANKLINE>
- To: _xtest@example.com
+ To: text@example.com
From: aperson@example.com
Subject: Something important
<BLANKLINE>
diff --git a/src/mailman/app/docs/message.rst b/src/mailman/app/docs/message.rst
index 3e3293196..3c3fd8ea8 100644
--- a/src/mailman/app/docs/message.rst
+++ b/src/mailman/app/docs/message.rst
@@ -2,7 +2,7 @@
Messages
========
-Mailman has its own Message classes, derived from the standard
+Mailman has its own `Message` classes, derived from the standard
``email.message.Message`` class, but providing additional useful methods.
@@ -13,7 +13,7 @@ When Mailman needs to send a message to a user, it creates a
``UserNotification`` instance, and then calls the ``.send()`` method on this
object. This method requires a mailing list instance.
- >>> mlist = create_list('_xtest@example.com')
+ >>> mlist = create_list('test@example.com')
The ``UserNotification`` constructor takes the recipient address, the sender
address, an optional subject, optional body text, and optional language.
@@ -21,28 +21,69 @@ address, an optional subject, optional body text, and optional language.
>>> from mailman.email.message import UserNotification
>>> msg = UserNotification(
... 'aperson@example.com',
- ... '_xtest@example.com',
+ ... 'test@example.com',
... 'Something you need to know',
... 'I needed to tell you this.')
>>> msg.send(mlist)
The message will end up in the `virgin` queue.
- >>> switchboard = config.switchboards['virgin']
- >>> len(switchboard.files)
+ >>> from mailman.testing.helpers import get_queue_messages
+ >>> messages = get_queue_messages('virgin')
+ >>> len(messages)
1
- >>> filebase = switchboard.files[0]
- >>> qmsg, qmsgdata = switchboard.dequeue(filebase)
- >>> switchboard.finish(filebase)
- >>> print qmsg.as_string()
+ >>> print messages[0].msg.as_string()
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Subject: Something you need to know
- From: _xtest@example.com
+ From: test@example.com
To: aperson@example.com
Message-ID: ...
Date: ...
Precedence: bulk
<BLANKLINE>
I needed to tell you this.
+
+The message above got a `Precedence: bulk` header added by default. If the
+message we're sending already has a `Precedence:` header, it shouldn't be
+changed.
+
+ >>> del msg['precedence']
+ >>> msg['Precedence'] = 'list'
+ >>> msg.send(mlist)
+
+Again, the message will end up in the `virgin` queue but with the original
+`Precedence:` header.
+
+ >>> messages = get_queue_messages('virgin')
+ >>> len(messages)
+ 1
+ >>> print messages[0].msg['precedence']
+ list
+
+Sometimes we want to send the message without a `Precedence:` header such as
+when we send a probe message.
+
+ >>> del msg['precedence']
+ >>> msg.send(mlist, add_precedence=False)
+
+Again, the message will end up in the `virgin` queue but without the
+`Precedence:` header.
+
+ >>> messages = get_queue_messages('virgin')
+ >>> len(messages)
+ 1
+ >>> print messages[0].msg['precedence']
+ None
+
+However, if the message already has a `Precedence:` header, setting the
+`precedence=False` argument will have no effect.
+
+ >>> msg['Precedence'] = 'junk'
+ >>> msg.send(mlist, add_precedence=False)
+ >>> messages = get_queue_messages('virgin')
+ >>> len(messages)
+ 1
+ >>> print messages[0].msg['precedence']
+ junk
diff --git a/src/mailman/app/tests/test_bounces.py b/src/mailman/app/tests/test_bounces.py
index be2c5cb78..d0d94df5e 100644
--- a/src/mailman/app/tests/test_bounces.py
+++ b/src/mailman/app/tests/test_bounces.py
@@ -21,6 +21,11 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestMaybeForward',
+ 'TestProbe',
+ 'TestSendProbe',
+ 'TestSendProbeNonEnglish',
+ 'TestVERP',
]
@@ -212,7 +217,7 @@ Message-ID: <first>
self.assertEqual(set(pendable.keys()),
set(['member_id', 'message_id']))
# member_ids are pended as unicodes.
- self.assertEqual(uuid.UUID(hex=pendable['member_id']),
+ self.assertEqual(uuid.UUID(hex=pendable['member_id']),
self._member.member_id)
self.assertEqual(pendable['message_id'], '<first>')
@@ -264,10 +269,16 @@ Message-ID: <first>
# Check the headers of the outer message.
token = send_probe(self._member, self._msg)
message = get_queue_messages('virgin')[0].msg
- self.assertEqual(message['From'],
+ self.assertEqual(message['from'],
'test-bounces+{0}@example.com'.format(token))
- self.assertEqual(message['To'], 'anne@example.com')
- self.assertEqual(message['Subject'], 'Test mailing list probe message')
+ self.assertEqual(message['to'], 'anne@example.com')
+ self.assertEqual(message['subject'], 'Test mailing list probe message')
+
+ def test_no_precedence_header(self):
+ # Probe messages should not have a Precedence header (LP: #808821).
+ send_probe(self._member, self._msg)
+ message = get_queue_messages('virgin')[0].msg
+ self.assertEqual(message['precedence'], None)
diff --git a/src/mailman/archiving/tests/test_prototype.py b/src/mailman/archiving/tests/test_prototype.py
index 969043aa4..29f6ba1cb 100644
--- a/src/mailman/archiving/tests/test_prototype.py
+++ b/src/mailman/archiving/tests/test_prototype.py
@@ -92,10 +92,10 @@ but the water deserves to be swum.
dirpath = unicode(dirpath)
all_filenames.add(dirpath)
for filename in filenames:
- new_filename = os.path.join(dirpath, filename)
- if not isinstance(new_filename, unicode):
- new_filename = unicode(new_filename)
- all_filenames.add(new_filename)
+ new_filename = filename
+ if not isinstance(filename, unicode):
+ new_filename = unicode(filename)
+ all_filenames.add(os.path.join(dirpath, new_filename))
return all_filenames
def test_archive_maildir_created(self):
@@ -141,7 +141,7 @@ but the water deserves to be swum.
config.LOCK_DIR, '{0}-maildir.lock'.format(
self._mlist.fqdn_listname))
with Lock(lock_file):
- # Acquire the archiver lock, Hen make sure the archiver logs the
+ # Acquire the archiver lock, then make sure the archiver logs the
# fact that it could not acquire the lock.
archive_thread = threading.Thread(
target=Prototype.archive_message,
@@ -150,13 +150,13 @@ but the water deserves to be swum.
archive_thread.run()
# Test that the archiver output the correct error.
line = mark.readline()
- self.assertEqual(
- # Strip out the timestamp.
- line[28:-1],
+ # XXX 2012-03-15 BAW: we really should remove timestamp prefixes
+ # from the loggers when under test.
+ self.assertTrue(line.endswith(
'Unable to acquire prototype archiver lock for {0}, '
- 'discarding: {1}'.format(
+ 'discarding: {1}\n'.format(
self._mlist.fqdn_listname,
- self._msg.get('message-id')))
+ self._msg.get('message-id'))))
# Check that the message didn't get archived.
created_files = self._find(config.ARCHIVE_DIR)
self.assertEqual(self._expected_dir_structure, created_files)
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index c2e4d1e51..7888ed8fd 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -107,6 +107,8 @@ Commands
Bug fixes
---------
+ * Subscription disabled probe warning notification messages are now sent
+ without a `Precedence:` header. Given by Mark Sapiro. (LP: #808821)
* Fixed KeyError in retry runner, contributed by Stephen A. Goss.
(LP: #872391)
* Fixed bogus use of `bounce_processing` attribute (should have been
diff --git a/src/mailman/email/message.py b/src/mailman/email/message.py
index d7bf81055..efe8879b1 100644
--- a/src/mailman/email/message.py
+++ b/src/mailman/email/message.py
@@ -178,10 +178,20 @@ class UserNotification(Message):
self['To'] = recipients
self.recipients = set([recipients])
- def send(self, mlist, **_kws):
+ def send(self, mlist, add_precedence=True, **_kws):
"""Sends the message by enqueuing it to the 'virgin' queue.
This is used for all internally crafted messages.
+
+ :param mlist: The mailing list to send the message to.
+ :type mlist: `IMailingList`
+ :param add_precedence: Flag indicating whether a `Precedence: bulk`
+ header should be added to the message or not.
+ :type add_precedence: bool
+
+ This function also accepts arbitrary keyword arguments. The key/value
+ pairs for **kws is added to the metadata dictionary associated with
+ the enqueued message.
"""
# Since we're crafting the message from whole cloth, let's make sure
# this message has a Message-ID.
@@ -193,7 +203,7 @@ class UserNotification(Message):
# UserNotifications are typically for admin messages, and for messages
# other than list explosions. Send these out as Precedence: bulk, but
# don't override an existing Precedence: header.
- if 'precedence' not in self:
+ if 'precedence' not in self and add_precedence:
self['Precedence'] = 'bulk'
self._enqueue(mlist, **_kws)
diff --git a/src/mailman/email/tests/__init__.py b/src/mailman/email/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/mailman/email/tests/__init__.py
diff --git a/src/mailman/email/tests/test_message.py b/src/mailman/email/tests/test_message.py
new file mode 100644
index 000000000..ee4f6135d
--- /dev/null
+++ b/src/mailman/email/tests/test_message.py
@@ -0,0 +1,60 @@
+# 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 message API."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestMessage',
+ ]
+
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.email.message import UserNotification
+from mailman.testing.helpers import get_queue_messages
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestMessage(unittest.TestCase):
+ """Test the message API."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ self._msg = UserNotification(
+ 'aperson@example.com',
+ 'test@example.com',
+ 'Something you need to know',
+ 'I needed to tell you this.')
+
+ def test_one_precedence_header(self):
+ # Ensure that when the original message already has a Precedence:
+ # header, UserNotification.send(..., add_precedence=True, ...) does
+ # not add a second header.
+ self.assertEqual(self._msg['precedence'], None)
+ self._msg['Precedence'] = 'omg wtf bbq'
+ self._msg.send(self._mlist)
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 1)
+ self.assertEqual(messages[0].msg.get_all('precedence'),
+ ['omg wtf bbq'])