[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mailman-cvs
Subject:    [Mailman-checkins] [Branch ~mailman-coders/mailman/3.0] Rev 6692:
From:       noreply () launchpad ! net
Date:       2009-02-18 3:26:08
Message-ID: 20090218032608.2837.70145.launchpad () loganberry ! canonical ! com
[Download RAW message or body]

------------------------------------------------------------
revno: 6692
committer: Barry Warsaw <barry@list.org>
branch nick: nopickles
timestamp: Tue 2009-02-17 22:23:12 -0500
message:
  Eradicate hold_and_cmd_autoresponses.
modified:
  src/mailman/app/replybot.py
  src/mailman/chains/hold.py
  src/mailman/database/mailinglist.py
  src/mailman/database/mailman.sql
  src/mailman/styles/default.py

=== modified file 'src/mailman/app/replybot.py'
--- src/mailman/app/replybot.py	2009-02-13 01:36:21 +0000
+++ src/mailman/app/replybot.py	2009-02-18 03:23:12 +0000
@@ -35,6 +35,8 @@
 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 @@
 
 
 
-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 @@
     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 @@
                 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
 
 
 

=== modified file 'src/mailman/chains/hold.py'
--- src/mailman/chains/hold.py	2009-02-13 01:36:21 +0000
+++ src/mailman/chains/hold.py	2009-02-18 03:23:12 +0000
@@ -39,6 +39,7 @@
 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 @@
         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 = _(

=== modified file 'src/mailman/database/mailinglist.py'
--- src/mailman/database/mailinglist.py	2009-02-13 01:36:21 +0000
+++ src/mailman/database/mailinglist.py	2009-02-18 03:23:12 +0000
@@ -57,7 +57,6 @@
     # 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 @@
         # 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)))

=== modified file 'src/mailman/database/mailman.sql'
--- src/mailman/database/mailman.sql	2009-02-17 04:57:30 +0000
+++ src/mailman/database/mailman.sql	2009-02-18 03:23:12 +0000
@@ -51,7 +51,6 @@
         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,

=== modified file 'src/mailman/styles/default.py'
--- src/mailman/styles/default.py	2009-02-13 01:36:21 +0000
+++ src/mailman/styles/default.py	2009-02-18 03:23:12 +0000
@@ -147,7 +147,6 @@
         # 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 = """\



--
Primary development focus
https://code.launchpad.net/~mailman-coders/mailman/3.0

Your team Mailman Checkins is subscribed to branch lp:mailman.
To unsubscribe from this branch go to \
https://code.launchpad.net/~mailman-coders/mailman/3.0/+edit-subscription. \
_______________________________________________ Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/mailman-cvs%40progressive-comp.com



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic