summaryrefslogtreecommitdiff
path: root/src/mailman/commands
diff options
context:
space:
mode:
authorBarry Warsaw2015-12-22 14:54:46 -0500
committerBarry Warsaw2015-12-22 14:54:46 -0500
commitc9464cb64f434749fee21e5ebbb15ce3f2fc1691 (patch)
tree9b93f9abe3e253210ba0249f284db85c0ee6b914 /src/mailman/commands
parent8e24476848de89302d9b0a8ea91116288201a95d (diff)
downloadmailman-c9464cb64f434749fee21e5ebbb15ce3f2fc1691.tar.gz
mailman-c9464cb64f434749fee21e5ebbb15ce3f2fc1691.tar.zst
mailman-c9464cb64f434749fee21e5ebbb15ce3f2fc1691.zip
Diffstat (limited to 'src/mailman/commands')
-rw-r--r--src/mailman/commands/cli_digests.py91
-rw-r--r--src/mailman/commands/cli_send_digests.py69
-rw-r--r--src/mailman/commands/tests/test_digests.py (renamed from src/mailman/commands/tests/test_send_digests.py)22
3 files changed, 107 insertions, 75 deletions
diff --git a/src/mailman/commands/cli_digests.py b/src/mailman/commands/cli_digests.py
new file mode 100644
index 000000000..9af91f1c3
--- /dev/null
+++ b/src/mailman/commands/cli_digests.py
@@ -0,0 +1,91 @@
+# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
+
+"""The `send_digests` subcommand."""
+
+__all__ = [
+ 'Digests',
+ ]
+
+
+import sys
+
+from mailman.app.digests import maybe_send_digest_now
+from mailman.core.i18n import _
+from mailman.interfaces.command import ICLISubCommand
+from mailman.interfaces.listmanager import IListManager
+from zope.component import getUtility
+from zope.interface import implementer
+
+
+
+@implementer(ICLISubCommand)
+class Digests:
+ """Operate on digests."""
+
+ name = 'digests'
+
+ def add(self, parser, command_parser):
+ """See `ICLISubCommand`."""
+
+ command_parser.add_argument(
+ '-l', '--list',
+ default=[], dest='lists', metavar='list', action='append',
+ help=_("""Operate on this mailing list. Multiple --list
+ options can be given. The argument can either be a List-ID
+ or a fully qualified list name. Without this option,
+ operate on the digests for all mailing lists."""))
+ command_parser.add_argument(
+ '-s', '--send',
+ default=False, action='store_true',
+ help=_("""Send any collected digests right now, even if the size
+ threshold has not yet been met."""))
+ command_parser.add_argument(
+ '-b', '--bump',
+ default=False, action='store_true',
+ help=_("""Increment the digest volume number and reset the digest
+ number to one. If given with --send, the volume number is
+ incremented after any current digests are sent."""))
+
+ def process(self, args):
+ """See `ICLISubCommand`."""
+ list_manager = getUtility(IListManager)
+ if args.send:
+ if not args.lists:
+ # Send the digests for every list.
+ for mlist in list_manager.mailing_lists:
+ maybe_send_digest_now(mlist, force=True)
+ return
+ for list_spec in args.lists:
+ # We'll accept list-ids or fqdn list names.
+ if '@' in list_spec:
+ mlist = list_manager.get(list_spec)
+ else:
+ mlist = list_manager.get_by_list_id(list_spec)
+ if mlist is None:
+ print(_('No such list found: $list_spec'), file=sys.stderr)
+ continue
+ maybe_send_digest_now(mlist, force=True)
+ if args.bump:
+ if not args.lists:
+ mlists = list(list_manager.mailing_lists)
+ else:
+ # We'll accept list-ids or fqdn list names.
+ if '@' in list_spec:
+ mlist = list_manager.get(list_spec)
+ else:
+ mlist = list_manager.get_by_list_id(list_spec)
diff --git a/src/mailman/commands/cli_send_digests.py b/src/mailman/commands/cli_send_digests.py
deleted file mode 100644
index 842054982..000000000
--- a/src/mailman/commands/cli_send_digests.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
-
-"""The `send_digests` subcommand."""
-
-__all__ = [
- 'Send',
- ]
-
-
-import sys
-
-from mailman.core.i18n import _
-from mailman.handlers.to_digest import maybe_send_digest_now
-from mailman.interfaces.command import ICLISubCommand
-from mailman.interfaces.listmanager import IListManager
-from zope.component import getUtility
-from zope.interface import implementer
-
-
-
-@implementer(ICLISubCommand)
-class Send:
- """Send some mailing list digests right now."""
-
- name = 'send-digests'
-
- def add(self, parser, command_parser):
- """See `ICLISubCommand`."""
-
- command_parser.add_argument(
- '-l', '--list',
- default=[], dest='lists', metavar='list', action='append',
- help=_("""Send the digests for this mailing list. Multiple --list
- options can be given. The argument can either be a List-ID
- or a fully qualified list name. Without this option, the
- digests for all mailing lists will be sent if possible."""))
-
- def process(self, args):
- """See `ICLISubCommand`."""
- if not args.lists:
- # Send the digests for every list.
- maybe_send_digest_now(force=True)
- return
- list_manager = getUtility(IListManager)
- for list_spec in args.lists:
- # We'll accept list-ids or fqdn list names.
- if '@' in list_spec:
- mlist = list_manager.get(list_spec)
- else:
- mlist = list_manager.get_by_list_id(list_spec)
- if mlist is None:
- print(_('No such list found: $list_spec'), file=sys.stderr)
- continue
- maybe_send_digest_now(mlist, force=True)
diff --git a/src/mailman/commands/tests/test_send_digests.py b/src/mailman/commands/tests/test_digests.py
index d0218ea12..2640580af 100644
--- a/src/mailman/commands/tests/test_send_digests.py
+++ b/src/mailman/commands/tests/test_digests.py
@@ -27,7 +27,7 @@ import unittest
from io import StringIO
from mailman.app.lifecycle import create_list
-from mailman.commands.cli_send_digests import Send
+from mailman.commands.cli_digests import Digests
from mailman.config import config
from mailman.interfaces.member import DeliveryMode
from mailman.runners.digest import DigestRunner
@@ -42,6 +42,8 @@ from unittest.mock import patch
class FakeArgs:
def __init__(self):
self.lists = []
+ self.send = False
+ self.bump = False
@@ -55,7 +57,7 @@ class TestSendDigests(unittest.TestCase):
self._mlist.digests_enabled = True
self._mlist.digest_size_threshold = 100000
self._mlist.send_welcome_message = False
- self._command = Send()
+ self._command = Digests()
self._handler = config.handlers['to-digest']
self._runner = make_testable_runner(DigestRunner, 'digest')
# The mailing list needs at least one digest recipient.
@@ -80,6 +82,7 @@ Subject: message 1
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
+ args.send = True
args.lists.append('ant.example.com')
self._command.process(args)
self._runner.run()
@@ -110,6 +113,7 @@ Subject: message 1
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
+ args.send = True
args.lists.append('ant@example.com')
self._command.process(args)
self._runner.run()
@@ -140,9 +144,10 @@ Subject: message 1
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
+ args.send = True
args.lists.append('bee.example.com')
stderr = StringIO()
- with patch('mailman.commands.cli_send_digests.sys.stderr', stderr):
+ with patch('mailman.commands.cli_digests.sys.stderr', stderr):
self._command.process(args)
self._runner.run()
# The warning was printed to stderr.
@@ -171,9 +176,10 @@ Subject: message 1
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
+ args.send = True
args.lists.append('bee@example.com')
stderr = StringIO()
- with patch('mailman.commands.cli_send_digests.sys.stderr', stderr):
+ with patch('mailman.commands.cli_digests.sys.stderr', stderr):
self._command.process(args)
self._runner.run()
# The warning was printed to stderr.
@@ -202,9 +208,10 @@ Subject: message 1
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
+ args.send = True
args.lists.extend(('ant.example.com', 'bee.example.com'))
stderr = StringIO()
- with patch('mailman.commands.cli_send_digests.sys.stderr', stderr):
+ with patch('mailman.commands.cli_digests.sys.stderr', stderr):
self._command.process(args)
self._runner.run()
# The warning was printed to stderr.
@@ -260,6 +267,7 @@ Subject: message 3
self.assertEqual(len(items), 0)
# Process both list's digests.
args = FakeArgs()
+ args.send = True
args.lists.extend(('ant.example.com', 'bee@example.com'))
self._command.process(args)
self._runner.run()
@@ -327,7 +335,9 @@ Subject: message 3
items = get_queue_messages('digest')
self.assertEqual(len(items), 0)
# Process all mailing list digests by not setting any arguments.
- self._command.process(FakeArgs())
+ args = FakeArgs()
+ args.send = True
+ self._command.process(args)
self._runner.run()
# Now, neither list has a digest mbox and but there are plaintext
# digest in the outgoing queue for both.