[Python-Dev] The first trustworthy <wink> GBayes results

Anthony Baxter Anthony Baxter <anthony@interlink.com.au>
Thu, 29 Aug 2002 17:04:32 +1000


This is a multipart MIME message.

--==_Exmh_20690933280
Content-Type: text/plain; charset=us-ascii


For what it's worth, the attached (simple) script will 'de-spamassassin'
an email message. I use it on my 'spam' folder to get test messages of 
various ugly MIME things that spam and viruses let through...

It's not pretty, but it does the job (for me, anyway)

-- 
Anthony Baxter     <anthony@interlink.com.au>   
It's never too late to have a happy childhood.


--==_Exmh_20690933280
Content-Type: text/plain ; name="deSA.py"; charset=us-ascii
Content-Description: deSA.py
Content-Disposition: attachment; filename="deSA.py"



def deSA(fp):
    import email, re
    m = email.message_from_string(fp.read())
    if m['X-Spam-Status']:
	if m['X-Spam-Status'].startswith('No'):
	    del m['X-Spam-Status']
	    del m['X-Spam-Level']
	else:
	    del m['X-Spam-Status']
	    del m['X-Spam-Level']
	    del m['X-Spam-Flag']
	    del m['X-Spam-Checker-Version']

	    pct = m['X-Spam-Prev-Content-Type']
	    if pct:
		del m['X-Spam-Prev-Content-Type']
		m['Content-Type'] = pct

	    pcte = m['X-Spam-Prev-Content-Transfer-Encoding']
	    if pcte:
		del m['Content-Transfer-Encoding']
		m['Content-Transfer-Encoding'] = pcte
		del m['X-Spam-Prev-Content-Transfer-Encoding']

	    body = m.get_payload()

	    subj = m['Subject']
	    del m['Subject']
	    m['Subject'] = re.sub(r'\*\*\*\*\*SPAM\*\*\*\*\* ', '', subj)

	    newbody = []
	    at_start = 1
	    for line in body.splitlines():
		if at_start and line.startswith('SPAM: '):
		    continue
		elif at_start:
		    at_start = 0
		else:
		    newbody.append(line)
	    m.set_payload("\n".join(newbody))


    return m

if __name__ == "__main__":
    import sys
    print deSA(open(sys.argv[1]))

--==_Exmh_20690933280--