diff options
| author | Barry Warsaw | 2009-02-17 22:23:12 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2009-02-17 22:23:12 -0500 |
| commit | 165f53b5d38850589aa75122ab08c73c7ddcb127 (patch) | |
| tree | d6c48fb84a7a92f3e82628bb45b96fe2b438c028 /src | |
| parent | 1f4c4e107f24cbb36110e8cb88908b34bac74b01 (diff) | |
| download | mailman-165f53b5d38850589aa75122ab08c73c7ddcb127.tar.gz mailman-165f53b5d38850589aa75122ab08c73c7ddcb127.tar.zst mailman-165f53b5d38850589aa75122ab08c73c7ddcb127.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/replybot.py | 60 | ||||
| -rw-r--r-- | src/mailman/chains/hold.py | 3 | ||||
| -rw-r--r-- | src/mailman/database/mailinglist.py | 5 | ||||
| -rw-r--r-- | src/mailman/database/mailman.sql | 1 | ||||
| -rw-r--r-- | src/mailman/styles/default.py | 1 |
5 files changed, 40 insertions, 30 deletions
diff --git a/src/mailman/app/replybot.py b/src/mailman/app/replybot.py index b558e96aa..fa423973b 100644 --- a/src/mailman/app/replybot.py +++ b/src/mailman/app/replybot.py @@ -35,6 +35,8 @@ import datetime from mailman import Utils from mailman import i18n from mailman.config import config +from mailman.utilities.datetime import today +from mailman.interfaces.autorespond import IAutoResponseSet, Response log = logging.getLogger('mailman.vette') @@ -42,12 +44,21 @@ _ = i18n._ -def autorespond_to_sender(mlist, sender, lang=None): - """Return True if Mailman should auto-respond to this sender. +def autorespond_to_sender(mlist, sender, response_type, lang=None): + """Should Mailman automatically respond to this sender? - This is only consulted for messages sent to the -request address, or - for posting hold notifications, and serves only as a safety value for - mail loops with email 'bots. + :param mlist: The mailing list. + :type mlist: `IMailingList`. + :param sender: The sender's email address. + :type sender: string + :param response_type: The type of response that might be sent. + :type response_type: `Response` enum + :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 @@ -55,22 +66,24 @@ def autorespond_to_sender(mlist, sender, lang=None): if max_autoresponses_per_day == 0: # Unlimited. return True - today = datetime.date.today() - info = mlist.hold_and_cmd_autoresponses.get(sender) - if info is None or info[0] <> today: - # This is the first time we've seen a -request/post-hold for this - # sender today. - mlist.hold_and_cmd_autoresponses[sender] = (today, 1) + # 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_type) + 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_type) return True - date, count = info - if count < 0: - # They've already hit the limit for today, and we've already notified - # them of this fact, so there's nothing more to do. - log.info('-request/hold autoresponse discarded for: %s', sender) - return False - if count >= max_autoresponses_per_day: - log.info('-request/hold autoresponse limit hit for: %s', sender) - mlist.hold_and_cmd_autoresponses[sender] = (today, -1) + 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('-request/hold autoresponse limit hit (%s): %s', + response_type, sender) + response_set.response_sent(address, response_type) # Send this notification message instead. text = Utils.maketext( 'nomoretoday.txt', @@ -87,8 +100,11 @@ def autorespond_to_sender(mlist, sender, lang=None): text, lang=lang) msg.send(mlist) return False - mlist.hold_and_cmd_autoresponses[sender] = (today, count + 1) - return True + else: + # We've sent them everything we're going to send them today. + log.info('Automatic response limit discard (%s): %s', + response_type, sender) + return False diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index dd5b69db0..8774028bd 100644 --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -39,6 +39,7 @@ from mailman.app.replybot import autorespond_to_sender, 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.pending import IPendable @@ -117,7 +118,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, language)): + autorespond_to_sender(mlist, msg.sender, Response.hold, language)): # We can respond to the sender with a message indicating their # posting was held. subject = _( diff --git a/src/mailman/database/mailinglist.py b/src/mailman/database/mailinglist.py index 605c51cd6..02100eeb8 100644 --- a/src/mailman/database/mailinglist.py +++ b/src/mailman/database/mailinglist.py @@ -57,7 +57,6 @@ class MailingList(Model): # Attributes not directly modifiable via the web u/i created_at = DateTime() admin_member_chunksize = Int() - hold_and_cmd_autoresponses = Pickle() # Attributes which are directly modifiable via the web u/i. The more # complicated attributes are currently stored as pickles, though that # will change as the schema and implementation is developed. @@ -181,10 +180,6 @@ class MailingList(Model): # For the pending database self.next_request_id = 1 self._restore() - # Max autoresponses per day. A mapping between addresses and a - # 2-tuple of the date of the last autoresponse and the number of - # autoresponses sent on that date. - self.hold_and_cmd_autoresponses = {} self.personalization = Personalization.none self.real_name = string.capwords( SPACE.join(listname.split(UNDERSCORE))) diff --git a/src/mailman/database/mailman.sql b/src/mailman/database/mailman.sql index e2a239f1a..3ce9ea515 100644 --- a/src/mailman/database/mailman.sql +++ b/src/mailman/database/mailman.sql @@ -51,7 +51,6 @@ CREATE TABLE mailinglist ( host_name TEXT, created_at TIMESTAMP, admin_member_chunksize INTEGER, - hold_and_cmd_autoresponses BLOB, next_request_id INTEGER, next_digest_number INTEGER, admin_responses BLOB, diff --git a/src/mailman/styles/default.py b/src/mailman/styles/default.py index ea4e1a342..3ae7b35f3 100644 --- a/src/mailman/styles/default.py +++ b/src/mailman/styles/default.py @@ -147,7 +147,6 @@ ${listinfo_page} # Max autoresponses per day. A mapping between addresses and a # 2-tuple of the date of the last autoresponse and the number of # autoresponses sent on that date. - mlist.hold_and_cmd_autoresponses = {} mlist.subject_prefix = _('[$mlist.real_name] ') mlist.msg_header = '' mlist.msg_footer = """\ |
