From 7a584735bd890a736ea2f27d0f488177b52d90b0 Mon Sep 17 00:00:00 2001 From: Tom Briles Date: Thu, 28 Jul 2016 09:51:47 -0700 Subject: Issue 68: send messages to list moderators when tomoderators=True --- src/mailman/email/message.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/mailman/email/message.py') diff --git a/src/mailman/email/message.py b/src/mailman/email/message.py index 994d44cce..7c811d797 100644 --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -31,6 +31,7 @@ from email.header import Header from email.mime.multipart import MIMEMultipart from mailman import public from mailman.config import config +from mailman.interfaces.member import DeliveryStatus COMMASPACE = ', ' @@ -131,7 +132,7 @@ class UserNotification(Message): self['To'] = recipients self.recipients = set([recipients]) - def send(self, mlist, add_precedence=True, **_kws): + def send(self, mlist, add_precedence=True, tomoderators=False, **_kws): """Sends the message by enqueuing it to the 'virgin' queue. This is used for all internally crafted messages. @@ -158,6 +159,12 @@ class UserNotification(Message): # don't override an existing Precedence: header. if 'precedence' not in self and add_precedence: self['Precedence'] = 'bulk' + if tomoderators: + self.recipients = set( + member.address.email + for member in mlist.moderators.members + if member.delivery_status == DeliveryStatus.enabled) + self['To'] = COMMASPACE.join(self.recipients) self._enqueue(mlist, **_kws) def _enqueue(self, mlist, **_kws): -- cgit v1.2.3-70-g09d2 From 589c4c62d4fa0b79dd4e742c50cf79bd8d4558ca Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 31 Oct 2016 20:09:23 -0400 Subject: tomoderators -> to_moderators. --- src/mailman/email/message.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/mailman/email/message.py') diff --git a/src/mailman/email/message.py b/src/mailman/email/message.py index 7c811d797..786dc11d0 100644 --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -132,7 +132,7 @@ class UserNotification(Message): self['To'] = recipients self.recipients = set([recipients]) - def send(self, mlist, add_precedence=True, tomoderators=False, **_kws): + def send(self, mlist, *, add_precedence=True, to_moderators=False, **_kws): """Sends the message by enqueuing it to the 'virgin' queue. This is used for all internally crafted messages. @@ -142,6 +142,9 @@ class UserNotification(Message): :param add_precedence: Flag indicating whether a `Precedence: bulk` header should be added to the message or not. :type add_precedence: bool + :param to_moderators: Flag indicating whether the message should be + sent to the list's moderators instead of the list's membership. + :type to_moderators: bool This function also accepts arbitrary keyword arguments. The key/value pairs for **kws is added to the metadata dictionary associated with @@ -159,7 +162,7 @@ class UserNotification(Message): # don't override an existing Precedence: header. if 'precedence' not in self and add_precedence: self['Precedence'] = 'bulk' - if tomoderators: + if to_moderators: self.recipients = set( member.address.email for member in mlist.moderators.members -- cgit v1.2.3-70-g09d2 From c50b3ee558eabd00624b0efc7ad9324535df1709 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Sun, 13 Nov 2016 22:03:40 -0500 Subject: Closes: #68 Messages sent to the list's moderators now include the actual recipient addresses. Given by Tom Briles. --- port_me/checkdbs.py | 2 +- src/mailman/app/moderator.py | 2 +- src/mailman/app/subscriptions.py | 4 ++-- src/mailman/app/tests/test_moderation.py | 19 +++++++++++++------ src/mailman/app/tests/test_subscriptions.py | 13 +++++++++---- src/mailman/chains/hold.py | 2 +- src/mailman/chains/tests/test_hold.py | 4 ++-- src/mailman/docs/NEWS.rst | 2 ++ src/mailman/email/message.py | 2 +- 9 files changed, 32 insertions(+), 18 deletions(-) (limited to 'src/mailman/email/message.py') diff --git a/port_me/checkdbs.py b/port_me/checkdbs.py index ac6dd2ad0..7f46e97d4 100644 --- a/port_me/checkdbs.py +++ b/port_me/checkdbs.py @@ -199,7 +199,7 @@ def main(): mlist.GetBouncesEmail(), subject, text, mlist.preferred_language) - msg.send(mlist, tomoderators=True) + msg.send(mlist, to_moderators=True) finally: mlist.Unlock() diff --git a/src/mailman/app/moderator.py b/src/mailman/app/moderator.py index c3347c1ff..9d3856f33 100644 --- a/src/mailman/app/moderator.py +++ b/src/mailman/app/moderator.py @@ -204,7 +204,7 @@ def hold_unsubscription(mlist, email): msg = UserNotification( mlist.owner_address, mlist.owner_address, subject, text, mlist.preferred_language) - msg.send(mlist, tomoderators=True) + msg.send(mlist, to_moderators=True) return request_id diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py index 9e915a25d..9e8d8dd9d 100644 --- a/src/mailman/app/subscriptions.py +++ b/src/mailman/app/subscriptions.py @@ -286,7 +286,7 @@ class SubscriptionWorkflow(_SubscriptionWorkflowCommon): msg = UserNotification( self.mlist.owner_address, self.mlist.owner_address, subject, text, self.mlist.preferred_language) - msg.send(self.mlist, tomoderators=True) + msg.send(self.mlist, to_moderators=True) # The workflow must stop running here. raise StopIteration @@ -434,7 +434,7 @@ class UnSubscriptionWorkflow(_SubscriptionWorkflowCommon): msg = UserNotification( self.mlist.owner_address, self.mlist.owner_address, subject, text, self.mlist.preferred_language) - msg.send(self.mlist, tomoderators=True) + msg.send(self.mlist, to_moderators=True) # The workflow must stop running here raise StopIteration diff --git a/src/mailman/app/tests/test_moderation.py b/src/mailman/app/tests/test_moderation.py index 45f94f27b..bb3958cd7 100644 --- a/src/mailman/app/tests/test_moderation.py +++ b/src/mailman/app/tests/test_moderation.py @@ -159,22 +159,29 @@ class TestUnsubscription(unittest.TestCase): def test_unsubscribe_defer(self): # When unsubscriptions must be approved by the moderator, but the # moderator defers this decision. - anne = getUtility(IUserManager).create_address( - 'anne@example.org', 'Anne Person') + user_manager = getUtility(IUserManager) + anne = user_manager.create_address('anne@example.org', 'Anne Person') token, token_owner, member = self._manager.register( anne, pre_verified=True, pre_confirmed=True, pre_approved=True) self.assertIsNone(token) self.assertEqual(member.address.email, 'anne@example.org') - mod = self._user_manager.create_user('bart@example.com', 'Bart User') - address = set_preferred(mod) + bart = user_manager.create_user('bart@example.com', 'Bart User') + address = set_preferred(bart) self._mlist.subscribe(address, MemberRole.moderator) # Now hold and handle an unsubscription request. token = hold_unsubscription(self._mlist, 'anne@example.org') handle_unsubscription(self._mlist, token, Action.defer) items = get_queue_messages('virgin', expected_count=2) - moderator_message = items[1] + # Find the moderator message. + for item in items: + if item.msg['to'] == 'test-owner@example.com': + break + else: + raise AssertionError('No moderator email found') + self.assertEqual(item.msgdata['recipients'], {'bart@example.com'}) self.assertEqual( - moderator_message.msgdata['recipients'], {'bart@example.com'}) + item.msg['subject'], + 'New unsubscription request from Test by anne@example.org') def test_bogus_token(self): # Try to handle an unsubscription with a bogus token. diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py index e72da6b01..5d49590ca 100644 --- a/src/mailman/app/tests/test_subscriptions.py +++ b/src/mailman/app/tests/test_subscriptions.py @@ -436,17 +436,22 @@ class TestSubscriptionWorkflow(unittest.TestCase): self._mlist.admin_immed_notify = True self._mlist.subscription_policy = SubscriptionPolicy.moderate anne = self._user_manager.create_address(self._anne) - mod = self._user_manager.create_user('bart@example.com', 'Bart User') - address = set_preferred(mod) + bart = self._user_manager.create_user('bart@example.com', 'Bart User') + address = set_preferred(bart) self._mlist.subscribe(address, MemberRole.moderator) workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True, pre_confirmed=True) # Consume the entire state machine. list(workflow) + # Find the moderator message. items = get_queue_messages('virgin', expected_count=1) - messagedata = items[0].msgdata - self.assertEqual(messagedata['recipients'], {'bart@example.com'}) + for item in items: + if item.msg['to'] == 'test-owner@example.com': + break + else: + raise AssertionError('No moderator email found') + self.assertEqual(item.msgdata['recipients'], {'bart@example.com'}) message = items[0].msg self.assertEqual(message['From'], 'test-owner@example.com') self.assertEqual(message['To'], 'test-owner@example.com') diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index b8c59358e..f111aee3c 100644 --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -246,7 +246,7 @@ also appear in the first line of the body of the reply.""")), nmsg.attach(text) nmsg.attach(MIMEMessage(msg)) nmsg.attach(MIMEMessage(dmsg)) - nmsg.send(mlist, tomoderators=True) + nmsg.send(mlist, to_moderators=True) # Log the held message. Log messages are not translated, so recast # the reasons in the English. with _.using('en'): diff --git a/src/mailman/chains/tests/test_hold.py b/src/mailman/chains/tests/test_hold.py index 677ce2f0f..13dd1b40e 100644 --- a/src/mailman/chains/tests/test_hold.py +++ b/src/mailman/chains/tests/test_hold.py @@ -135,8 +135,8 @@ A message body. # Issue #144 - UnicodeEncodeError in the hold chain. self._mlist.admin_immed_notify = True self._mlist.respond_to_post_requests = False - mod = self._user_manager.create_user('bart@example.com', 'Bart User') - address = set_preferred(mod) + bart = self._user_manager.create_user('bart@example.com', 'Bart User') + address = set_preferred(bart) self._mlist.subscribe(address, MemberRole.moderator) path = resource_filename('mailman.chains.tests', 'issue144.eml') with open(path, 'rb') as fp: diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index f72498a1d..fdde0589f 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -97,6 +97,8 @@ Bugs (Closes: #283) * Remove the digest mbox files after the digests are sent. Given by Aurélien Bompard. (Closes: #259) + * Messages sent to the list's moderators now include the actual recipient + addresses. Given by Tom Briles. (Closes: #68) Configuration ------------- diff --git a/src/mailman/email/message.py b/src/mailman/email/message.py index 786dc11d0..ebfef9d9b 100644 --- a/src/mailman/email/message.py +++ b/src/mailman/email/message.py @@ -166,7 +166,7 @@ class UserNotification(Message): self.recipients = set( member.address.email for member in mlist.moderators.members - if member.delivery_status == DeliveryStatus.enabled) + if member.delivery_status is DeliveryStatus.enabled) self['To'] = COMMASPACE.join(self.recipients) self._enqueue(mlist, **_kws) -- cgit v1.2.3-70-g09d2