Last active
December 10, 2015 01:38
-
-
Save martinmev/4360636 to your computer and use it in GitHub Desktop.
Script gets delivery errors from mbox file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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