Jul
25
2010
Posted by ebal at
03:41:25
in planet_ellak, code
This is a better and improved version of one of my previous perl script:
#!/usr/bin/env python
# Created by Evaggelos Balaskas on Sun Jul 25 06:36:29 EEST 2010
# Remove mails from mbox by subject
import sys
import mailbox
import re
SUBJECTS = (
'automatically rejected mail',
'delivery failure',
'delivery notification',
'delivery status notification',
'failure notice',
'mail delivery failed',
'mail delivery failure',
'nondeliverable',
'returned mail',
'undeliverable',
'undelivered',
'warning: could not send message for past'
)
if len(sys.argv) == 2:
for message in mailbox.mbox( sys.argv[1] ) :
s = message['subject']
flag = 0
for i in SUBJECTS:
m = re.search ( i, str(s), re.I )
if m != None :
flag = 1
break
print message
else:
print "Usage should be: " + sys.argv[0] + " mbox > new.mbox"