CVS: tmda/bin ChangeLog,1.289,1.290 tmda-inject,1.95,1.96
"Jason R. Mastaler" <[email protected]> Wed, 11 Feb 2004 16:39:20 -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-serv11901/bin Modified Files: ChangeLog tmda-inject Log Message: Bugfix. Add Received, Date, Message-ID, X-Delivery-Agent and Mail-Followup-To outside of inject_message() so that they are added only once per message, not once per recipient of that message. Index: ChangeLog =================================================================== RCS file: /cvsroot/tmda/tmda/bin/ChangeLog,v retrieving revision 1.289 retrieving revision 1.290 diff -u -r1.289 -r1.290 --- ChangeLog 5 Feb 2004 21:03:49 -0000 1.289 +++ ChangeLog 12 Feb 2004 00:39:18 -0000 1.290 @@ -1,3 +1,10 @@ +2004-02-11 Jason R. Mastaler <[email protected]> + + * tmda-inject (main): Add Received, Date, Message-ID, + X-Delivery-Agent and Mail-Followup-To outside of inject_message() + so that they are added only once per message, not once per + recipient of that message. + 2004-02-05 Jason R. Mastaler <[email protected]> * tmda-inject (inject_message): Support Defaults.MAIL_FOLLOWUP_TO. Index: tmda-inject =================================================================== RCS file: /cvsroot/tmda/tmda/bin/tmda-inject,v retrieving revision 1.95 retrieving revision 1.96 diff -u -r1.95 -r1.96 --- tmda-inject 5 Feb 2004 21:11:51 -0000 1.95 +++ tmda-inject 12 Feb 2004 00:39:18 -0000 1.96 @@ -78,7 +78,6 @@ filter_match = None -injections = 0 qfilter = None program = sys.argv[0] @@ -220,8 +219,6 @@ actions, log_msg): """Hand the message off to sendmail.""" - global injections - # Default, if no From: is specified, is bare. (cookie_type, cookie_option) = actions.get('from', ('bare', None)) magic_from = make_field(cookie_type, cookie_option, @@ -246,26 +243,6 @@ del msg['From'] msg['From'] = message_format(magic_from, full_name, Defaults.MESSAGE_FROM_STYLE) - # 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'): @@ -279,19 +256,6 @@ new_mft_list.append(emaddy) del msg['Mail-Followup-To'] msg['Mail-Followup-To'] = ', '.join(new_mft_list) - # Possibly add a `Date' field. - if ((Defaults.TMDAINJECT and 'd' in list(Defaults.TMDAINJECT)) - or not msg.has_key('date')): - del msg['Date'] - msg['Date'] = Util.make_date() - # Possibly add a `Message-ID' field. - if ((Defaults.TMDAINJECT and 'i' in list(Defaults.TMDAINJECT)) - or not msg.has_key('message-id')): - del msg['Message-ID'] - msg['Message-ID'] = Util.make_msgid() - # Add `X-Delivery-Agent' header. - del msg['X-Delivery-Agent'] - msg['X-Delivery-Agent'] = 'TMDA/%s (%s)' % (Version.TMDA, Version.CODENAME) # Optionally, add an `X-TMDA-Fingerprint' header. if Defaults.FINGERPRINT: hdrlist = [] @@ -322,19 +286,6 @@ nice_header = string.capwords(header.replace('-', ' ')).replace(' ', '-') nice_headers[nice_header] = field Util.add_headers(msg, nice_headers) - # Prepend a Received header. - if injections == 0: - if os.environ.has_key('TMDA_OFMIPD_RECEIVED'): - # tmda-ofmipd - msg._headers.insert(0, ('Received', - (os.environ.get('TMDA_OFMIPD_RECEIVED')))) - else: - # tmda-sendmail/inject - msg._headers.insert(0, ('Received', - 'by %s (tmda-sendmail, from uid %s); %s' \ - % (socket.getfqdn(), os.getuid(), - Util.make_date()))) - # Optionally, log this transmission. if Defaults.LOGFILE_OUTGOING: from TMDA import MessageLogger @@ -347,7 +298,6 @@ logger.write() # Inject the message. Util.sendmail(Util.msg_as_string(msg, 78), to_address, envelope_sender) - injections += 1 # Remove any custom headers we added for this recipient from the # message object, else all subsequent recipients will receive them # unconditionally. @@ -435,6 +385,54 @@ else: msgout['Subject'] = '' + # Transformations that should happen a total of once for the + # message, not once per recipient of the message. + + # Prepend a Received header. + if os.environ.has_key('TMDA_OFMIPD_RECEIVED'): + # tmda-ofmipd + msgout._headers.insert(0, ('Received', + (os.environ.get('TMDA_OFMIPD_RECEIVED')))) + else: + # tmda-sendmail/inject + msgout._headers.insert(0, ('Received', + 'by %s (tmda-sendmail, from uid %s); %s' \ + % (socket.getfqdn(), os.getuid(), + Util.make_date()))) + # Possibly add a `Date' field. + if ((Defaults.TMDAINJECT and 'd' in list(Defaults.TMDAINJECT)) + or not msgout.has_key('date')): + del msgout['Date'] + msgout['Date'] = Util.make_date() + # Possibly add a `Message-ID' field. + if ((Defaults.TMDAINJECT and 'i' in list(Defaults.TMDAINJECT)) + or not msgout.has_key('message-id')): + del msgout['Message-ID'] + msgout['Message-ID'] = Util.make_msgid() + # Add an `X-Delivery-Agent' header. + del msgout['X-Delivery-Agent'] + msgout['X-Delivery-Agent'] = 'TMDA/%s (%s)' % (Version.TMDA, Version.CODENAME) + # Possibly add a Mail-Followup-To field if one doesn't exist. + if Defaults.MAIL_FOLLOWUP_TO and not msgout.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(msgout.get_all('to', []) + + msgout.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: + msgout['Mail-Followup-To'] = ', '.join(tocc_addrs) + break + # If the address matches a line in the filter file, it is tagged # accordingly, otherwise it is tagged with the default cookie # type.