Re: Extended Expiration?

Mark Horn <[email protected]>
Newsgroups gmane.mail.spam.tmda.devel
Message-ID <[email protected]>
On 2006-10-27, Mark Horn <[email protected]> wrote:
> This is my first crack at this (see below).  I'm a very
> inexperienced python programmer.  So I'd really appreciate some
> feedback from the TMDA pythoners as to whether or not this is the
> right way to do this.

Right...so, I got impatient.  I'm still interested in feedback,
but I've got it working.  Here's the patch:



Index: TMDA/ChangeLog
===================================================================
--- TMDA/ChangeLog	(revision 2114)
+++ 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 2114)
+++ 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 2114)
+++ 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 2114)
+++ 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,33 @@
             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 = []
+
+    for k,v in Defaults.ACTION_EXPIRED_DATED.iteritems():
+        if k != 'default':
+	    templist.append((Util.seconds(k),v,k))
+        else:
+	    templist.append((0,v,k))
+    templist.sort()
+    templist.reverse()
+
+    overdue = int('%d' % time.time()) - int(cookie_date)
+
+    i = 0
+    while i < len(templist):
+        if overdue > templist[i][0]:
+	    logmsg = "action_expired_dated %s (%s)" % \
+		(templist[i][2].lower(),
+		Util.make_date(int(cookie_date)))
+	    do_default_action(templist[i][1].lower(), logmsg, 
+			'bounce_expired_dated.txt')
+        i = i + 1
+
+
 def verify_dated_cookie(dated_cookie):
     """Verify a dated cookie."""
     # Save some time if the cookie is bogus.
@@ -602,10 +629,18 @@
         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:
+		sys.stdout.write('tmda-filter: ACTION_EXPIRED_DATED is \
+			wrong format')
+		sys.exit(75)
+	    else:
+		dispose_expired_dated(cookie_date)
 
 
+
 def verify_sender_cookie(sender_address,sender_cookie):
     """Verify a sender cookie."""
     try:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.