Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.