Source

smtpErrorAnalysis / smtp-error-analysis / regexEmailTester.py

Full commit
import re, sys
import pprint
 
email_pattern = re.compile('([\w\-\.]+@(\w[\w\-]+\.)+[\w\-]+)')
#rawstr = re.compile(r"""^(?P<fullErrorMessage>[<](?P<emailAddress>.+)[>].*)""")
#compile_obj = re.compile(rawstr,  re.MULTILINE| re.DOTALL)
 
line = '''<associates.co.nz@diezel.dreamhost.com> (expanded from <associates.co.nz>):    unknown user: "associates.co.nz"'''

arrLines = []
arrLines.append('''1306107014.V811I65c91c6M159839.diezel,associates.co.nz@diezel.dreamhost.com> (expanded from <associates.co.nz,"<associates.co.nz@diezel.dreamhost.com> (expanded from <associates.co.nz>):    unknown user: ""associates.co.nz"""''')
arrLines.append('''1306107015.V811I65c91c7M469029.diezel,don.eadie@roadtrain.org.nz,<don.eadie@roadtrain.org.nz>: [roadtrain.org.nz]: Name or service not known''')
arrLines.append('''1306107016.V811I65cc3c8M33430.diezel,su@murulearncentre.org.nz,<su@murulearncentre.org.nz>: [murulearncentre.org.nz]: Name or service not    known''')
arrLines.append('''1306107016.V811I65cc3c9M208857.diezel,a.carrington@eplus-salvationarmy.co.nz,<a.carrington@eplus-salvationarmy.co.nz>: [eplus-salvationarmy.co.nz]: Name or    service not known''')
arrLines.append('''1306107016.V811I65cc3cbM585965.diezel,keithmcgregor1@hotmail.com,<keithmcgregor1@hotmail.com>: host mx3.hotmail.com[65.54.188.94] said: 550    Requested action not taken: mailbox unavailable (in reply to RCPT TO    command)''')
arrLines.append('''1306107016.V811I65cc3ccM591758.diezel,diane@sadlerand.dreamhost.com,<diane@sadlerand.dreamhost.com>: [sadlerand.dreamhost.com]: Name or service not    known''')
arrLines.append('''1306107016.V811I65cc3cdM624973.diezel,marina8088@hotmail.com,<marina8088@hotmail.com>: host mx3.hotmail.com[65.54.188.72] said: 550    Requested action not taken: mailbox unavailable (in reply to RCPT TO    command)''')
arrLines.append('''1306107017.V811I65cc3ceM10074.diezel,bramdev@ihug.co.nz,<bramdev@ihug.co.nz>: host zuul.ihug.co.nz[203.109.135.49] said: 550 #5.1.0    Address rejected bramdev@ihug.co.nz (in reply to RCPT TO command)''')
arrLines.append('''1306107017.V811I65cc3cfM50315.diezel,valeria@senz.org.nz,<valeria@senz.org.nz>: host equipperschurch.com.s9a1.psmtp.com[74.125.148.10]    said: 550 No such user - psmtp (in reply to RCPT TO command)''')
arrLines.append('''1306107017.V811I65cc3d0M54814.diezel,mccomish@actrix.gen.nz>: host mta.actrix.co.nz[203.96.16.183] said: 550 5.1.1    <mccomish@actrix.gen.nz,<mccomish@actrix.gen.nz>: host mta.actrix.co.nz[203.96.16.183] said: 550 5.1.1    <mccomish@actrix.gen.nz>: Recipient address rejected: User unknown in local    recipient table (in reply to RCPT TO command)''')
arrLines.append('''1306107017.V811I65cc3d1M68979.diezel,k.elliott@paradise.net.nz,<k.elliott@paradise.net.nz>: host mx.paradise.net.nz[203.97.33.212] said: 550    #5.1.0 Address rejected k.elliott@paradise.net.nz (in reply to RCPT TO    command)''')
arrLines.append('''1306107017.V811I65cc3d2M227320.diezel,mtctour@xtra.co.nz,<mtctour@xtra.co.nz>: host mx1.tnz.mail.yahoo.com[124.108.96.211] said: 554    delivery error: dd This user doesn't have a xtra.co.nz account    (mtctour@xtra.co.nz) [0] - mta1001.tnz.mail.aue.yahoo.com (in reply to end    of DATA command)''')
arrLines.append('''1306107017.V811I65cc3d3M508051.diezel,positive.people@ww.co.nz,"<positive.people@ww.co.nz>: host mail.ww.co.nz[124.198.191.58] said: 550    ""Unknown User"" (in reply to RCPT TO command)"''')


for line in arrLines:
    '''
    match_obj = compile_obj.search(line)
    try:
        fullErrorMessage = match_obj.group('fullErrorMessage')
    except AttributeError:
        print "Error 1" 
    except:
        print "Unexpected error:", sys.exc_info()[0]
        raise
    else:
        fullErrorMessage = stripLineFeeds(fullErrorMessage)
        blnGoodErrMsg = True 

    
    try:
        emailAddress = match_obj.group('emailAddress')
    except AttributeError:
        print "Error 2" 
    except:
        print "Unexpected error:", sys.exc_info()[0]
        raise
    else:
        emailAddress = stripFromVerboseMessage(emailAddress, compile_objVerboseMsg)
        emailAddress = stripLineFeeds(emailAddress)
        blnGoodEmail = True
    '''

    print "+" * 50
    print line
    print "!" * 50
    #emailAddress = match_obj.group('emailAddress')
    for match in email_pattern.findall(line):
            #print match[0]
            pprint.pprint(match)
    print "-" * 50