CVS: tmda/bin ChangeLog,1.288,1.289 tmda-inject,1.93,1.94

"Jason R. Mastaler" <[email protected]> Thu, 05 Feb 2004 13:03:52 -0800
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29896/bin

Modified Files:
	ChangeLog tmda-inject 
Log Message:
New feature.  

Inspired by qmail-inject's QMAILMFTFILE feature, MAIL_FOLLOWUP_TO
automatically adds (via tmda-inject) a Mail-Followup-To field for
messages sent to mailing lists.

MAIL_FOLLOWUP_TO can either be a list of mailing list addresses, or a
string pointing to a file containing mailing list addresses, one per
line.  If To or Cc in the message includes one of those addresses
(without regard to case), tmda-inject adds a Mail-Followup-To field
with all the To+Cc addresses.  tmda-inject does not add
Mail-Followup-To to a message that already has one, or if the address
file does not exist.


Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/ChangeLog,v
retrieving revision 1.288
retrieving revision 1.289
diff -u -r1.288 -r1.289
--- ChangeLog	11 Jan 2004 07:36:53 -0000	1.288
+++ ChangeLog	5 Feb 2004 21:03:49 -0000	1.289
@@ -1,3 +1,7 @@
+2004-02-05  Jason R. Mastaler  <[email protected]>
+
+	* tmda-inject (inject_message): Support Defaults.MAIL_FOLLOWUP_TO.
+	
 2004-01-11  Jason R. Mastaler  <[email protected]>
 
 	* tmda-rfilter (verify_dated_cookie): Use Util.Make_date().

Index: tmda-inject
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-inject,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- tmda-inject	1 Jan 2004 23:22:19 -0000	1.93
+++ tmda-inject	5 Feb 2004 21:03:49 -0000	1.94
@@ -246,8 +246,28 @@
         del msg['From']
 	msg['From'] = message_format(magic_from, full_name,
                                      Defaults.MESSAGE_FROM_STYLE)
-    # If the MUA has added a `Mail-Followup-To' header that contains
-    # the untagged address, we need to tag that as well.
+    # Add a Mail-Followup-To field if one doesn't exist
+    if Defaults.MAIL_FOLLOWUP_TO and not msg.has_key('mail-followup-to'):
+        if isinstance(Defaults.MAIL_FOLLOWUP_TO, str):
+            if os.path.isfile(Defaults.MAIL_FOLLOWUP_TO):
+                mft_addrs = file(Defaults.MAIL_FOLLOWUP_TO, 'r').readlines()
+            else:
+                mft_addrs = None
+        else:
+            # assume a list
+            mft_addrs = Defaults.MAIL_FOLLOWUP_TO
+        if mft_addrs:
+            mft_addrs_lower = [a.lower().strip() for a in mft_addrs]
+            toccs = getaddresses(msg.get_all('to', [])
+                                 + msg.get_all('cc', []))
+            tocc_addrs = [a[1].strip() for a in toccs]
+            tocc_addrs_lower = [a.lower() for a in tocc_addrs]
+            for a in tocc_addrs_lower:
+                if a in mft_addrs_lower:
+                    msg['Mail-Followup-To'] = ', '.join(tocc_addrs)
+                    break
+    # If the Mail-Followup-To header contains an untagged address, we
+    # need to tag that as well.
     if msg.has_key('mail-followup-to'):
 	mft_list = getaddresses(msg.get_all('mail-followup-to'))
 	new_mft_list = []
@@ -258,7 +278,7 @@
 	    else:
 		new_mft_list.append(emaddy)
         del msg['Mail-Followup-To']
-	msg['Mail-Followup-To'] = string.join(new_mft_list, ',\n\t')
+	msg['Mail-Followup-To'] = ', '.join(new_mft_list)
     # Possibly add a `Date' field.
     if 'd' in Defaults.TMDAINJECT or not msg.has_key('date'):
         del msg['Date']