summaryrefslogtreecommitdiff
path: root/src/mailman/chains/hold.py
diff options
context:
space:
mode:
authorBarry Warsaw2009-02-19 00:26:22 -0500
committerBarry Warsaw2009-02-19 00:26:22 -0500
commitcf68d5d364a4453c3ab4a22ca04046d7a0d4cc1d (patch)
tree432a04b4712159961146c7249c2577b0f553fe78 /src/mailman/chains/hold.py
parentd0cb397ef31598e4fb6b7c70553ee9e9f23226ab (diff)
downloadmailman-cf68d5d364a4453c3ab4a22ca04046d7a0d4cc1d.tar.gz
mailman-cf68d5d364a4453c3ab4a22ca04046d7a0d4cc1d.tar.zst
mailman-cf68d5d364a4453c3ab4a22ca04046d7a0d4cc1d.zip
Diffstat (limited to 'src/mailman/chains/hold.py')
-rw-r--r--src/mailman/chains/hold.py66
1 files changed, 63 insertions, 3 deletions
diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py
index 8774028bd..5f98bceea 100644
--- a/src/mailman/chains/hold.py
+++ b/src/mailman/chains/hold.py
@@ -35,11 +35,11 @@ from zope.interface import implements
from mailman import i18n
from mailman.Utils import maketext, oneline, wrap
from mailman.app.moderator import hold_message
-from mailman.app.replybot import autorespond_to_sender, can_acknowledge
+from mailman.app.replybot import can_acknowledge
from mailman.chains.base import TerminalChainBase
from mailman.config import config
from mailman.email.message import UserNotification
-from mailman.interfaces.autorespond import Response
+from mailman.interfaces.autorespond import IAutoResponseSet, Response
from mailman.interfaces.pending import IPendable
@@ -55,6 +55,66 @@ class HeldMessagePendable(dict):
+def autorespond_to_sender(mlist, sender, lang=None):
+ """Should Mailman automatically respond to this sender?
+
+ :param mlist: The mailing list.
+ :type mlist: `IMailingList`.
+ :param sender: The sender's email address.
+ :type sender: string
+ :param lang: Optional language.
+ :type lang: `ILanguage` or None
+ :return: True if an automatic response should be sent, otherwise False.
+ If an automatic response is not sent, a message is sent indicating
+ that, er no more will be sent today.
+ :rtype: bool
+ """
+ if lang is None:
+ lang = mlist.preferred_language
+ max_autoresponses_per_day = int(config.mta.max_autoresponses_per_day)
+ if max_autoresponses_per_day == 0:
+ # Unlimited.
+ return True
+ # Get an IAddress from an email address.
+ address = config.db.user_manager.get_address(sender)
+ if address is None:
+ address = config.db.user_manager.create_address(sender)
+ response_set = IAutoResponseSet(mlist)
+ todays_count = response_set.todays_count(address, Response.hold)
+ if todays_count < max_autoresponses_per_day:
+ # This person has not reached their automatic response limit, so it's
+ # okay to send a response.
+ response_set.response_sent(address, Response.hold)
+ return True
+ elif todays_count == max_autoresponses_per_day:
+ # The last one we sent was the last one we should send today. Instead
+ # of sending an automatic response, send them the "no more today"
+ # message.
+ log.info('hold autoresponse limit hit: %s', sender)
+ response_set.response_sent(address, Response.hold)
+ # Send this notification message instead.
+ text = Utils.maketext(
+ 'nomoretoday.txt',
+ {'sender' : sender,
+ 'listname': mlist.fqdn_listname,
+ 'num' : count,
+ 'owneremail': mlist.owner_address,
+ },
+ lang=lang)
+ with i18n.using_language(lang.code):
+ msg = Message.UserNotification(
+ sender, mlist.owner_address,
+ _('Last autoresponse notification for today'),
+ text, lang=lang)
+ msg.send(mlist)
+ return False
+ else:
+ # We've sent them everything we're going to send them today.
+ log.info('Automatic response limit discard: %s', sender)
+ return False
+
+
+
class HoldChain(TerminalChainBase):
"""Hold a message."""
@@ -118,7 +178,7 @@ class HoldChain(TerminalChainBase):
if (not msgdata.get('fromusenet') and
can_acknowledge(msg) and
mlist.respond_to_post_requests and
- autorespond_to_sender(mlist, msg.sender, Response.hold, language)):
+ autorespond_to_sender(mlist, msg.sender, language)):
# We can respond to the sender with a message indicating their
# posting was held.
subject = _(