summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Briles2016-07-28 09:51:47 -0700
committerBarry Warsaw2016-10-31 20:05:27 -0400
commit7a584735bd890a736ea2f27d0f488177b52d90b0 (patch)
tree215e236dedcd2c23b9679f43be4a9a1065932988
parent366dc6517716b7c77c4b7a76559b1b6b5996fc8e (diff)
downloadmailman-7a584735bd890a736ea2f27d0f488177b52d90b0.tar.gz
mailman-7a584735bd890a736ea2f27d0f488177b52d90b0.tar.zst
mailman-7a584735bd890a736ea2f27d0f488177b52d90b0.zip
-rw-r--r--port_me/checkdbs.py2
-rw-r--r--src/mailman/app/tests/test_moderation.py10
-rw-r--r--src/mailman/app/tests/test_subscriptions.py7
-rw-r--r--src/mailman/chains/hold.py2
-rw-r--r--src/mailman/chains/tests/test_hold.py11
-rw-r--r--src/mailman/email/message.py9
6 files changed, 33 insertions, 8 deletions
diff --git a/port_me/checkdbs.py b/port_me/checkdbs.py
index 9e5213b4c..ac6dd2ad0 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, tomoderators=True)
finally:
mlist.Unlock()
diff --git a/src/mailman/app/tests/test_moderation.py b/src/mailman/app/tests/test_moderation.py
index 20584da49..45f94f27b 100644
--- a/src/mailman/app/tests/test_moderation.py
+++ b/src/mailman/app/tests/test_moderation.py
@@ -23,6 +23,7 @@ from mailman.app.lifecycle import create_list
from mailman.app.moderator import (
handle_message, handle_unsubscription, hold_message, hold_unsubscription)
from mailman.interfaces.action import Action
+from mailman.interfaces.member import MemberRole
from mailman.interfaces.messages import IMessageStore
from mailman.interfaces.requests import IListRequests
from mailman.interfaces.subscriptions import ISubscriptionManager
@@ -31,7 +32,7 @@ from mailman.runners.incoming import IncomingRunner
from mailman.runners.outgoing import OutgoingRunner
from mailman.runners.pipeline import PipelineRunner
from mailman.testing.helpers import (
- get_queue_messages, make_testable_runner,
+ get_queue_messages, make_testable_runner, set_preferred,
specialized_message_from_string as mfs)
from mailman.testing.layers import SMTPLayer
from mailman.utilities.datetime import now
@@ -164,9 +165,16 @@ class TestUnsubscription(unittest.TestCase):
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)
+ 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]
+ self.assertEqual(
+ moderator_message.msgdata['recipients'], {'bart@example.com'})
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 19198307d..e72da6b01 100644
--- a/src/mailman/app/tests/test_subscriptions.py
+++ b/src/mailman/app/tests/test_subscriptions.py
@@ -24,7 +24,7 @@ from mailman.app.lifecycle import create_list
from mailman.app.subscriptions import SubscriptionWorkflow
from mailman.interfaces.bans import IBanManager
from mailman.interfaces.mailinglist import SubscriptionPolicy
-from mailman.interfaces.member import MembershipIsBannedError
+from mailman.interfaces.member import MembershipIsBannedError, MemberRole
from mailman.interfaces.pending import IPendings
from mailman.interfaces.subscriptions import TokenOwner
from mailman.interfaces.usermanager import IUserManager
@@ -436,12 +436,17 @@ 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)
+ self._mlist.subscribe(address, MemberRole.moderator)
workflow = SubscriptionWorkflow(self._mlist, anne,
pre_verified=True,
pre_confirmed=True)
# Consume the entire state machine.
list(workflow)
items = get_queue_messages('virgin', expected_count=1)
+ messagedata = items[0].msgdata
+ self.assertEqual(messagedata['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 f1bd42961..b8c59358e 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, **dict(tomoderators=True))
+ nmsg.send(mlist, tomoderators=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 0957fe880..677ce2f0f 100644
--- a/src/mailman/chains/tests/test_hold.py
+++ b/src/mailman/chains/tests/test_hold.py
@@ -24,10 +24,11 @@ from mailman.app.lifecycle import create_list
from mailman.chains.hold import autorespond_to_sender
from mailman.core.chains import process as process_chain
from mailman.interfaces.autorespond import IAutoResponseSet, Response
+from mailman.interfaces.member import MemberRole
from mailman.interfaces.messages import IMessageStore
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import (
- LogFileMark, configuration, get_queue_messages,
+ LogFileMark, configuration, get_queue_messages, set_preferred,
specialized_message_from_string as mfs)
from mailman.testing.layers import ConfigLayer
from pkg_resources import resource_filename
@@ -94,6 +95,7 @@ class TestHoldChain(unittest.TestCase):
def setUp(self):
self._mlist = create_list('test@example.com')
+ self._user_manager = getUtility(IUserManager)
def test_hold_chain(self):
msg = mfs("""\
@@ -133,6 +135,9 @@ 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)
+ self._mlist.subscribe(address, MemberRole.moderator)
path = resource_filename('mailman.chains.tests', 'issue144.eml')
with open(path, 'rb') as fp:
msg = mfb(fp.read())
@@ -142,8 +147,8 @@ A message body.
# delivery to the moderators.
items = get_queue_messages('virgin', expected_count=1)
msgdata = items[0].msgdata
- self.assertTrue(msgdata['tomoderators'])
- self.assertEqual(msgdata['recipients'], {'test-owner@example.com'})
+ # Should get sent to moderators.
+ self.assertEqual(msgdata['recipients'], {'bart@example.com'})
# Ensure that the subject looks correct in the postauth.txt.
msg = items[0].msg
value = None
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):