summaryrefslogtreecommitdiff
path: root/src/mailman/handlers/to_digest.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/handlers/to_digest.py')
-rw-r--r--src/mailman/handlers/to_digest.py78
1 files changed, 55 insertions, 23 deletions
diff --git a/src/mailman/handlers/to_digest.py b/src/mailman/handlers/to_digest.py
index 89e1acaea..d9c707e12 100644
--- a/src/mailman/handlers/to_digest.py
+++ b/src/mailman/handlers/to_digest.py
@@ -19,6 +19,8 @@
__all__ = [
'ToDigest',
+ 'bump_digest_number_and_volume',
+ 'maybe_send_digest_now',
]
@@ -29,8 +31,10 @@ from mailman.core.i18n import _
from mailman.email.message import Message
from mailman.interfaces.digests import DigestFrequency
from mailman.interfaces.handler import IHandler
+from mailman.interfaces.listmanager import IListManager
from mailman.utilities.datetime import now as right_now
from mailman.utilities.mailbox import Mailbox
+from zope.component import getUtility
from zope.interface import implementer
@@ -53,29 +57,7 @@ class ToDigest:
# Lock the mailbox and append the message.
with Mailbox(mailbox_path, create=True) as mbox:
mbox.add(msg)
- # Calculate the current size of the mailbox file. This will not tell
- # us exactly how big the resulting MIME and rfc1153 digest will
- # 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:
- # The digest is ready to send. 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)
- os.rename(mailbox_path, mailbox_dest)
- config.switchboards['digest'].enqueue(
- Message(),
- listid=mlist.list_id,
- digest_path=mailbox_dest,
- volume=volume,
- digest_number=digest_number)
+ maybe_send_digest_now(mlist)
@@ -117,3 +99,53 @@ def bump_digest_number_and_volume(mlist):
# Just bump the digest number.
mlist.next_digest_number += 1
mlist.digest_last_sent_at = now
+
+
+
+def maybe_send_digest_now(mlist=None, force=False):
+ """Send this mailing list's digest now.
+
+ If there are any messages in this mailing list's digest, the
+ digest is sent immediately, regardless of whether the size
+ threshold has been met. When called through the subcommand
+ `mailman send_digest` the value of .digest_send_periodic is
+ consulted.
+
+ :param mlist: The mailing list whose digest should be sent. If this is
+ None, all mailing lists with non-zero sized digests will have theirs
+ sent immediately.
+ :type mlist: IMailingList or None
+ :param force: Should the digest be sent even if the size threshold hasn't
+ been met?
+ :type force: boolean
+ """
+ if mlist is None:
+ digestable_lists = getUtility(IListManager).mailing_lists
+ else:
+ digestable_lists = [mlist]
+ for mailing_list in digestable_lists:
+ mailbox_path = os.path.join(mailing_list.data_path, 'digest.mmdf')
+ # Calculate the current size of the mailbox file. This will not tell
+ # us exactly how big the resulting MIME and rfc1153 digest will
+ # 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
+ (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)
+ os.rename(mailbox_path, mailbox_dest)
+ config.switchboards['digest'].enqueue(
+ Message(),
+ listid=mlist.list_id,
+ digest_path=mailbox_dest,
+ volume=volume,
+ digest_number=digest_number)