Back to index

python3.2  3.2.2
Classes | Functions | Variables
mailerdaemon Namespace Reference

Classes

class  Unparseable
class  ErrorMessage

Functions

def emparse_list
def sort_numeric
def parsedir
def main

Variables

list emparse_list_list
list x = emparse_list_list[i]
list xl = []
list emparse_list_reason
tuple emparse_list_from = re.compile('^From:', re.IGNORECASE|re.MULTILINE)
list EMPARSERS = [emparse_list]
tuple errors = m.get_errors()
 os.unlink(fn)
int nbad = 1
string date = '%s %02d'
int nok = 1
list list = []
 os.unlink(fn)

Function Documentation

def mailerdaemon.emparse_list (   fp,
  sub 
)

Definition at line 97 of file mailerdaemon.py.

00097 
00098 def emparse_list(fp, sub):
00099     data = fp.read()
00100     res = emparse_list_from.search(data)
00101     if res is None:
00102         from_index = len(data)
00103     else:
00104         from_index = res.start(0)
00105     errors = []
00106     emails = []
00107     reason = None
00108     for regexp in emparse_list_list:
00109         if type(regexp) is type(()):
00110             res = regexp[0].search(data, 0, from_index)
00111             if res is not None:
00112                 try:
00113                     reason = res.group('reason')
00114                 except IndexError:
00115                     pass
00116                 while 1:
00117                     res = regexp[1].match(data, res.end(0), from_index)
00118                     if res is None:
00119                         break
00120                     emails.append(res.group('email'))
00121                 break
00122         else:
00123             res = regexp.search(data, 0, from_index)
00124             if res is not None:
00125                 emails.append(res.group('email'))
00126                 try:
00127                     reason = res.group('reason')
00128                 except IndexError:
00129                     pass
00130                 break
00131     if not emails:
00132         raise Unparseable
00133     if not reason:
00134         reason = sub
00135         if reason[:15] == 'returned mail: ':
00136             reason = reason[15:]
00137         for regexp in emparse_list_reason:
00138             if type(regexp) is type(''):
00139                 for i in range(len(emails)-1,-1,-1):
00140                     email = emails[i]
00141                     exp = re.compile(re.escape(email).join(regexp.split('<>')), re.MULTILINE)
00142                     res = exp.search(data)
00143                     if res is not None:
00144                         errors.append(' '.join((email.strip()+': '+res.group('reason')).split()))
00145                         del emails[i]
00146                 continue
00147             res = regexp.search(data)
00148             if res is not None:
00149                 reason = res.group('reason')
00150                 break
00151     for email in emails:
00152         errors.append(' '.join((email.strip()+': '+reason).split()))
00153     return errors

Here is the call graph for this function:

Definition at line 234 of file mailerdaemon.py.

00234 
00235 def main():
00236     modify = 0
00237     if len(sys.argv) > 1 and sys.argv[1] == '-d':
00238         modify = 1
00239         del sys.argv[1]
00240     if len(sys.argv) > 1:
00241         for folder in sys.argv[1:]:
00242             parsedir(folder, modify)
00243     else:
00244         parsedir('/ufs/jack/Mail/errorsinbox', modify)

Here is the call graph for this function:

def mailerdaemon.parsedir (   dir,
  modify 
)

Definition at line 166 of file mailerdaemon.py.

00166 
00167 def parsedir(dir, modify):
00168     os.chdir(dir)
00169     pat = re.compile('^[0-9]*$')
00170     errordict = {}
00171     errorfirst = {}
00172     errorlast = {}
00173     nok = nwarn = nbad = 0
00174 
00175     # find all numeric file names and sort them
00176     files = list(filter(lambda fn, pat=pat: pat.match(fn) is not None, os.listdir('.')))
00177     files.sort(sort_numeric)
00178 
00179     for fn in files:
00180         # Lets try to parse the file.
00181         fp = open(fn)
00182         m = email.message_from_file(fp, _class=ErrorMessage)
00183         sender = m.getaddr('From')
00184         print('%s\t%-40s\t'%(fn, sender[1]), end=' ')
00185 
00186         if m.is_warning():
00187             fp.close()
00188             print('warning only')
00189             nwarn = nwarn + 1
00190             if modify:
                os.rename(fn, ','+fn)

Here is the call graph for this function:

Here is the caller graph for this function:

def mailerdaemon.sort_numeric (   a,
  b 
)

Definition at line 156 of file mailerdaemon.py.

00156 
00157 def sort_numeric(a, b):
00158     a = int(a)
00159     b = int(b)
00160     if a < b:
00161         return -1
00162     elif a > b:
00163         return 1
00164     else:
00165         return 0


Variable Documentation

Definition at line 207 of file mailerdaemon.py.

tuple mailerdaemon.emparse_list_from = re.compile('^From:', re.IGNORECASE|re.MULTILINE)

Definition at line 96 of file mailerdaemon.py.

Initial value:
00001 [
00002     'error: (?P<reason>unresolvable): (?P<email>.+)',
00003     ('----- The following addresses had permanent fatal errors -----\n',
00004      '(?P<email>[^ \n].*)\n( .*\n)?'),
00005     'remote execution.*\n.*rmail (?P<email>.+)',
00006     ('The following recipients did not receive your message:\n\n',
00007      ' +(?P<email>.*)\n(The following recipients did not receive your message:\n\n)?'),
00008     '------- Failure Reasons  --------\n\n(?P<reason>.*)\n(?P<email>.*)',
00009     '^<(?P<email>.*)>:\n(?P<reason>.*)',
00010     '^(?P<reason>User mailbox exceeds allowed size): (?P<email>.+)',
00011     '^5\\d{2} <(?P<email>[^\n>]+)>\\.\\.\\. (?P<reason>.+)',
00012     '^Original-Recipient: rfc822;(?P<email>.*)',
00013     '^did not reach the following recipient\\(s\\):\n\n(?P<email>.*) on .*\n +(?P<reason>.*)',
00014     '^ <(?P<email>[^\n>]+)> \\.\\.\\. (?P<reason>.*)',
00015     '^Report on your message to: (?P<email>.*)\nReason: (?P<reason>.*)',
00016     '^Your message was not delivered to +(?P<email>.*)\n +for the following reason:\n +(?P<reason>.*)',
00017     '^ was not +(?P<email>[^ \n].*?) *\n.*\n.*\n.*\n because:.*\n +(?P<reason>[^ \n].*?) *\n',
00018     ]

Definition at line 52 of file mailerdaemon.py.

Initial value:
00001 [
00002     r'^5\d{2} <>\.\.\. (?P<reason>.*)',
00003     '<>\.\.\. (?P<reason>.*)',
00004     re.compile(r'^<<< 5\d{2} (?P<reason>.*)', re.MULTILINE),
00005     re.compile('===== stderr was =====\nrmail: (?P<reason>.*)'),
00006     re.compile('^Diagnostic-Code: (?P<reason>.*)', re.MULTILINE),
00007     ]

Definition at line 89 of file mailerdaemon.py.

Definition at line 154 of file mailerdaemon.py.

tuple mailerdaemon.errors = m.get_errors()

os.unlink(fn)

Definition at line 195 of file mailerdaemon.py.

os.unlink(fn)

Definition at line 227 of file mailerdaemon.py.

Definition at line 198 of file mailerdaemon.py.

Definition at line 218 of file mailerdaemon.py.

Definition at line 72 of file mailerdaemon.py.

Definition at line 76 of file mailerdaemon.py.