On 2006-10-29, Jason R. Mastaler <[EMAIL PROTECTED]> wrote:
> If you want to use 'True' instead of '1' and 'False' instead of '0'
> that'll be good, else I'll do it when I get around to checking this
> in.

Done.  Thanks.


Index: TMDA/ChangeLog
===================================================================
--- TMDA/ChangeLog      (revision 2116)
+++ TMDA/ChangeLog      (working copy)
@@ -1,3 +1,7 @@
+2006-10-07  Mark Horn  <[EMAIL PROTECTED]>
+
+       * Defaults.py: added additional descriptino to ACTION_EXPIRED_DATED
+
 2006-10-07  Jason R. Mastaler  <[EMAIL PROTECTED]>
 
        * pythonlib/email: Sync up with email 4.0.1.
Index: TMDA/Defaults.py
===================================================================
--- TMDA/Defaults.py    (revision 2116)
+++ TMDA/Defaults.py    (working copy)
@@ -681,7 +681,16 @@
 # "hold"
 #    silently hold message in pending queue
 #
-# Default is confirm
+# This can also be a Python Dictionary to specify multiple ways of handling
+# expiration types.  For example:
+#
+#   ACTION_EXPIRED_DATED = {
+#      'default':'confirm',    ## default is to confirm, unless
+#      '1w':     'bounce',     ## ...it expired more than 1w ago, then bounce
+#      '30d':    'hold',       ## ...it expired more than 30d ago, then hold
+#      '1Y':     'drop'}       ## ...it expired more than 1Y ago, then drop
+#
+# Default is "confirm"
 if not vars().has_key('ACTION_EXPIRED_DATED'):
     ACTION_EXPIRED_DATED = "confirm"
 
Index: bin/ChangeLog
===================================================================
--- bin/ChangeLog       (revision 2116)
+++ bin/ChangeLog       (working copy)
@@ -1,3 +1,7 @@
+2006-10-27  Mark Horn  <[EMAIL PROTECTED]>
+
+       * tmda-rfilter: added multiple expiration to ACTION_EXPIRED_DATED
+
 2006-10-13  Jason R. Mastaler  <[EMAIL PROTECTED]>
 
        * tmda-rfilter: Migrate from getopt to optparse.
Index: bin/tmda-rfilter
===================================================================
--- bin/tmda-rfilter    (revision 2116)
+++ bin/tmda-rfilter    (working copy)
@@ -469,6 +469,7 @@
         bouncegen('request')
 
 
+
 def release_pending(timestamp, pid, msg):
     """Release a confirmed message from the pending queue."""
     # Remove Return-Path: to avoid duplicates.
@@ -578,7 +579,48 @@
             del msgin['x-tmda-confirm-done']
             mta.deliver(msgin)
 
+def dispose_expired_dated(cookie_date):
+    """Dispoose of an expired dated address based on ACTION_EXPIRED_DATED 
dictionary settings"""
 
+    templist = []
+    havedefault = False
+
+
+    ## go through all of the times, and convert them into seconds
+    ## default becomes "0", saving the symbolic name logging
+    for k,v in Defaults.ACTION_EXPIRED_DATED.iteritems():
+        if k != 'default':
+           templist.append((Util.seconds(k),v,k))
+        else:
+           ## Default is False.  The number represents the number of
+           ## seconds that the address has been expired.  A negative
+           ## number would imply a non-expired address, so zero will
+           ## suffice as a default.
+           templist.append((0,v,k))
+           havedefault = True
+
+    ## If no default specfied, assume "confirm"
+    if havedefault == False:
+       templist.append((0,'confirm','default'))
+
+    ## Reverse sort the list.
+    templist.sort()
+    templist.reverse()
+
+    ## calculate how long ago the address expired
+    overdue = int('%d' % time.time()) - int(cookie_date)
+
+    ## Figure out which action should be used.  Since the list is reverse
+    ## sorted, the first time that overdue is > then the time in the list
+    ## means that we've found the action to use
+    for i in templist:
+       if overdue > i[0]:
+           logmsg = "action_expired_dated/%s (%s)" % \
+               (i[2], Util.make_date(int(cookie_date)))
+           do_default_action(i[1].lower(), logmsg, 'bounce_expired_dated.txt')
+           
+
+
 def verify_dated_cookie(dated_cookie):
     """Verify a dated cookie."""
     # Save some time if the cookie is bogus.
@@ -602,10 +644,19 @@
         else:
             logmsg = "action_expired_dated (%s)" % \
                      Util.make_date(int(cookie_date))
-            do_default_action(Defaults.ACTION_EXPIRED_DATED.lower(),
+           if type(Defaults.ACTION_EXPIRED_DATED) == str:
+                do_default_action(Defaults.ACTION_EXPIRED_DATED.lower(),
                               logmsg, 'bounce_expired_dated.txt')
+           elif type(Defaults.ACTION_EXPIRED_DATED) != dict:
+               errmsg = 'ACTION_EXPIRED_DATED is wrong type (%s). ' % \
+                       type(Defaults.ACTION_EXPIRED_DATED)
+               raise TypeError, errmsg + \
+                       'Must be string or dictionary'
+           else:
+               dispose_expired_dated(cookie_date)
 
 
+
 def verify_sender_cookie(sender_address,sender_cookie):
     """Verify a sender cookie."""
     try:

_________________________________________________
tmda-workers mailing list ([email protected])
http://tmda.net/lists/listinfo/tmda-workers

Reply via email to