1 Date: Fri, 5 Nov 1999 02:30:38 +0200 (SAST)
2 From: Paul Sheer <psheer@icon.co.za>
4 there is an FAQ question on this, but no examples.
6 works with python 1.5.1
16 # exim-filter-mime.py <mime-type> ...
19 # exim-filter-mime.py audio image/jpg video
21 # This script reads from stdin and writes to stdout.
22 # It strips all the mime attachments from a mail message
23 # that are one of the mime types listed on the command line
25 # Exim can use it in its configuration file, for example, as follows:
32 # transport_filter = /etc/exim-filter-mime.py audio video image
35 # The attachment is replaced with the following:
36 def cheeky_response (part):
37 print "[File `%s' of type `%s' is meant to go here]" % (part.getheader('Content-Description'), part.gettype ())
39 print "This host is restricted from transmitting %s files and" % (part.getmaintype (),)
40 print "hence this attachment was stripped from the mail message."
46 message = mimetools.Message (sys.stdin, 0)
48 # Print out the header:
49 for l in message.headers:
53 # Not a multipart message, so just dump the whole thing:
54 if message.getmaintype () != "multipart":
57 l = message.fp.readline ()
62 boundary = "--" + message.getparam ("boundary") + "\n"
63 lastboundary = "--" + message.getparam ("boundary") + "--\n"
66 while l and l != boundary and l != lastboundary:
67 l = message.fp.readline ()
70 while l and l != lastboundary:
71 part = mimetools.Message (message.fp, 0)
72 if part.getmaintype () in sys.argv[1:] or part.gettype () in sys.argv[1:]:
73 # If it is of a type on the command-line, do not write the header or body,
74 # just skip over till the next boundary...
76 while l and l != boundary and l != lastboundary:
77 l = part.fp.readline ()
78 # ... and then give a cheeky replacement:
79 print "Content-Type: TEXT/plain; charset=us-ascii"
81 cheeky_response (part)
85 # if it is anything else (like text/plain, application/octet-stream etc.
86 # then write the header...
88 for p in part.headers:
91 # ... and then write the body
93 while l and l != boundary and l != lastboundary:
94 l = part.fp.readline ()
99 l = message.fp.readline ()