From f3ed60124bf8fd418d628f10e021f1948c9ff532 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Wed, 14 Mar 2012 11:50:14 -0700 Subject: Subscription disabled warnings are now sent without a Precedence: header. (LP: #808821) --- src/mailman/app/bounces.py | 4 +++- src/mailman/docs/NEWS.rst | 2 ++ src/mailman/email/message.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mailman/app/bounces.py b/src/mailman/app/bounces.py index a9bed97ac..69250ea5a 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) + # Send without Precedence: bulk. (LP: #808821) + probe.send(mlist, envsender=probe_sender, verp=False, probe_token=token + noprecedence=True) return token diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 6869e2889..71cdcae6e 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -105,6 +105,8 @@ Commands Bug fixes --------- + * Subscription disabled warnings are now sent without a Precedence: + header. (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..7f7ee66ed 100644 --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -178,7 +178,7 @@ class UserNotification(Message): self['To'] = recipients self.recipients = set([recipients]) - def send(self, mlist, **_kws): + def send(self, mlist, noprecedence=False, **_kws): """Sends the message by enqueuing it to the 'virgin' queue. This is used for all internally crafted messages. @@ -193,7 +193,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 or not noprecedence: self['Precedence'] = 'bulk' self._enqueue(mlist, **_kws) -- cgit v1.2.3-70-g09d2 From 243e04db97e6601c471568a6e7c5fd74371fcb62 Mon Sep 17 00:00:00 2001 From: toshio Date: Wed, 14 Mar 2012 23:44:30 +0000 Subject: Fix a potential unicode traceback --- src/mailman/archiving/tests/test_prototype.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mailman/archiving/tests/test_prototype.py b/src/mailman/archiving/tests/test_prototype.py index 969043aa4..7f48c5cfd 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, -- cgit v1.2.3-70-g09d2 From 048d8b66972af87170803fd67f02f8c720694bbc Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Wed, 14 Mar 2012 17:14:56 -0700 Subject: Fixed a logic error and added more conditions to the doctest. --- src/mailman/app/docs/message.rst | 38 ++++++++++++++++++++++++++++++++++++++ src/mailman/email/message.py | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mailman/app/docs/message.rst b/src/mailman/app/docs/message.rst index 3e3293196..11ab32b22 100644 --- a/src/mailman/app/docs/message.rst +++ b/src/mailman/app/docs/message.rst @@ -46,3 +46,41 @@ The message will end up in the `virgin` queue. Precedence: bulk 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 our Precedence: +header. + + >>> switchboard = config.switchboards['virgin'] + >>> len(switchboard.files) + 1 + >>> filebase = switchboard.files[0] + >>> qmsg, qmsgdata = switchboard.dequeue(filebase) + >>> switchboard.finish(filebase) + >>> qmsg['precedence'] == 'list' + True + +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, noprecedence=True) + +Again, the message will end up in the `virgin` queue but without the +Precedence: header. + + >>> switchboard = config.switchboards['virgin'] + >>> len(switchboard.files) + 1 + >>> filebase = switchboard.files[0] + >>> qmsg, qmsgdata = switchboard.dequeue(filebase) + >>> switchboard.finish(filebase) + >>> 'precedence' in qmsg + False diff --git a/src/mailman/email/message.py b/src/mailman/email/message.py index 7f7ee66ed..28d94523f 100644 --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -193,7 +193,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 or not noprecedence: + if 'precedence' not in self and not noprecedence: self['Precedence'] = 'bulk' self._enqueue(mlist, **_kws) -- cgit v1.2.3-70-g09d2 From 0589c867988dc70cbe83a53bc9d1e2bbf3108b82 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 15 Mar 2012 10:34:26 -0700 Subject: Add a test for a corner case of UserNotification.send() as suggested by Mark. Fix a test failure found by Toshio, along with an XXX about how we should fix this problem long term. --- src/mailman/archiving/tests/test_prototype.py | 10 ++--- src/mailman/email/tests/__init__.py | 0 src/mailman/email/tests/test_message.py | 60 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/mailman/email/tests/__init__.py create mode 100644 src/mailman/email/tests/test_message.py (limited to 'src') diff --git a/src/mailman/archiving/tests/test_prototype.py b/src/mailman/archiving/tests/test_prototype.py index 7f48c5cfd..29f6ba1cb 100644 --- a/src/mailman/archiving/tests/test_prototype.py +++ b/src/mailman/archiving/tests/test_prototype.py @@ -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/email/tests/__init__.py b/src/mailman/email/tests/__init__.py new file mode 100644 index 000000000..e69de29bb 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 . + +"""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']) -- cgit v1.2.3-70-g09d2