Skip to content

Instantly share code, notes, and snippets.

@martinmev
Last active December 10, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinmev/4360636 to your computer and use it in GitHub Desktop.
Save martinmev/4360636 to your computer and use it in GitHub Desktop.
Script gets delivery errors from mbox file.
#!/usr/bin/env python
import sys
def writeErrors(mbox,filename):
isMessage=lambda c: mbox[c].strip()=='The mail system'
getMessage = lambda c,s: s if mbox[c].strip()=='' else s+' '+getMessage(c+1,mbox[c].strip())
counter=0
f=open(filename,'w')
while counter<len(mbox):
if isMessage(counter):
counter+=2
f.write((getMessage(counter,'')).strip())
f.write('\n')
counter+=1
f.close()
if len(sys.argv)!=3:
print('usage: get_delivery_errors mbox_file error_file')
exit(1)
f=file(sys.argv[1],'r')
mbox=f.readlines()
f.close()
writeErrors(mbox,sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment