Hi,

Use QMAILQUEUE patch and cascade your additionally programs correctly.
e.g. in qmail-scanner you can configure the next "qmail-queue" that needs
to be started.


Hope it helps.

You will have to :
1 - compile qmail-qfilter to point to your qmail-scanner queue
2 - point QMAILQUEUE to the qmail-qfilter script

Please report me any problem.
If you rewrite this code in C, please let me know (I do not have the time to do it right now myself).

Thomas
#!/usr/bin/python

# Copyright (C) 2004 Thomas Mangin
# Public Domain

import os
import sys
import re

# What to append
append_file = "footer.txt"
append_string  = "The footer which will annoy your customers\n"


boundary_search = '.*boundary="(.*)".*'
boundary_string = ''
boundary_compiled = None

boundary_line = False
append_raw = False
append_mime = False



file = os.fdopen(0)


for line in file:
        sys.stdout.write(line)

        if boundary_line:
                match =  boundary_compiled.match(line)
                if match:
                        boundary_string = '--' + match.group(1) 
                        append_mime = True
                elif len(line) > 1 and line[-2] == ';':
                        continue
                break

        
        if line and line.startswith('Content-Type:'):
                part = line.split(':')
                if len(part) < 2:
                        append_raw = False
                        append_mime = False
                        break
                
                if part[1].count('text/plain'):
                        if append_raw:
                                append_raw = False
                                break
                        else:
                                append_raw = True
                                
                elif part[1].count('multipart'):
                        if part[1].count('signed'):
                                break

                        if append_raw:
                                append_raw = False
                                break
                        
                        if len(line) > 1 and line[-2] == ';':
                                boundary_line = True
                        
                        boundary_compiled = re.compile(boundary_search)
                        match =  boundary_compiled.match(line)
                        if match:
                                boundary_string = '--' + match.group(1) 
                                append_mime = True
                                break
                        else:
                                boundary_line = True

                        
                else:
                        append_raw = False
                        append_mime = False
                        break

end_boundary_string = boundary_string + '--'

for line in file:
        if append_mime and line and line.count(end_boundary_string):
                print boundary_string
                print 'Content-Type: text/plain; charset=us-ascii; format=flowed; 
name="'+append_file+'".txt"'
                print 'Content-Transfer-Encoding: 7bit'
                print
                print
                print append_string
                print end_boundary_string
        else:
                sys.stdout.write(line)

if append_raw:
        print
        print append_string


#print 'Content-Type: text/plain; charset="iso-8859-1"'
#print 'Content-Transfer-Encoding: 8bit'

file.close()

sys.exit(0)
#!/bin/sh
exec /var/qmail/bin/qmail-qfilter /var/qmail/bin/qmail-qfilter-footer-mime

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to