summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/commands/tests/test_send_digests.py66
-rw-r--r--src/mailman/handlers/to_digest.py15
2 files changed, 74 insertions, 7 deletions
diff --git a/src/mailman/commands/tests/test_send_digests.py b/src/mailman/commands/tests/test_send_digests.py
index 937922d7c..d0218ea12 100644
--- a/src/mailman/commands/tests/test_send_digests.py
+++ b/src/mailman/commands/tests/test_send_digests.py
@@ -285,3 +285,69 @@ Subject: message 3
digest_contents = str(bee)
self.assertIn('Subject: message 3', digest_contents)
self.assertIn('Subject: message 4', digest_contents)
+
+ def test_send_digests_for_all_lists(self):
+ # Populate ant's digest.
+ msg = mfs("""\
+To: ant@example.com
+From: anne@example.com
+Subject: message 1
+
+""")
+ self._handler.process(self._mlist, msg, {})
+ del msg['subject']
+ msg['subject'] = 'message 2'
+ self._handler.process(self._mlist, msg, {})
+ # Create the second list.
+ bee = create_list('bee@example.com')
+ bee.digests_enabled = True
+ bee.digest_size_threshold = 100000
+ bee.send_welcome_message = False
+ member = subscribe(bee, 'Bart')
+ member.preferences.delivery_mode = DeliveryMode.plaintext_digests
+ # Populate bee's digest.
+ msg = mfs("""\
+To: bee@example.com
+From: bart@example.com
+Subject: message 3
+
+""")
+ self._handler.process(bee, msg, {})
+ del msg['subject']
+ msg['subject'] = 'message 4'
+ self._handler.process(bee, msg, {})
+ # There are no digests for either list already being sent, but the
+ # mailing lists do have a digest mbox collecting messages.
+ ant_mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
+ self.assertGreater(os.path.getsize(ant_mailbox_path), 0)
+ # Check bee's digest.
+ bee_mailbox_path = os.path.join(bee.data_path, 'digest.mmdf')
+ self.assertGreater(os.path.getsize(bee_mailbox_path), 0)
+ # Both.
+ items = get_queue_messages('digest')
+ self.assertEqual(len(items), 0)
+ # Process all mailing list digests by not setting any arguments.
+ self._command.process(FakeArgs())
+ self._runner.run()
+ # Now, neither list has a digest mbox and but there are plaintext
+ # digest in the outgoing queue for both.
+ self.assertFalse(os.path.exists(ant_mailbox_path))
+ self.assertFalse(os.path.exists(bee_mailbox_path))
+ items = get_queue_messages('virgin')
+ self.assertEqual(len(items), 2)
+ # Figure out which digest is going to ant and which to bee.
+ if items[0].msg['to'] == 'ant@example.com':
+ ant = items[0].msg
+ bee = items[1].msg
+ else:
+ assert items[0].msg['to'] == 'bee@example.com'
+ ant = items[1].msg
+ bee = items[0].msg
+ # Check ant's digest.
+ digest_contents = str(ant)
+ self.assertIn('Subject: message 1', digest_contents)
+ self.assertIn('Subject: message 2', digest_contents)
+ # Check bee's digest.
+ digest_contents = str(bee)
+ self.assertIn('Subject: message 3', digest_contents)
+ self.assertIn('Subject: message 4', digest_contents)
diff --git a/src/mailman/handlers/to_digest.py b/src/mailman/handlers/to_digest.py
index d9c707e12..1b1ed84f1 100644
--- a/src/mailman/handlers/to_digest.py
+++ b/src/mailman/handlers/to_digest.py
@@ -130,22 +130,23 @@ def maybe_send_digest_now(mlist=None, force=False):
# actually be, but it's the most easily available metric to decide
# whether the size threshold has been reached.
size = os.path.getsize(mailbox_path)
- if (size >= mlist.digest_size_threshold * 1024.0 or
+ if (size >= mailing_list.digest_size_threshold * 1024.0 or
(force and size > 0)):
# Send the digest. Because we don't want to hold up this process
# with crafting the digest, we're going to move the digest file to
# a safe place, then craft a fake message for the DigestRunner as
# a trigger for it to build and send the digest.
mailbox_dest = os.path.join(
- mlist.data_path,
- 'digest.{0.volume}.{0.next_digest_number}.mmdf'.format(mlist))
- volume = mlist.volume
- digest_number = mlist.next_digest_number
- bump_digest_number_and_volume(mlist)
+ mailing_list.data_path,
+ 'digest.{0.volume}.{0.next_digest_number}.mmdf'.format(
+ mailing_list))
+ volume = mailing_list.volume
+ digest_number = mailing_list.next_digest_number
+ bump_digest_number_and_volume(mailing_list)
os.rename(mailbox_path, mailbox_dest)
config.switchboards['digest'].enqueue(
Message(),
- listid=mlist.list_id,
+ listid=mailing_list.list_id,
digest_path=mailbox_dest,
volume=volume,
digest_number=digest_number)