Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/mailerdaemon.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | ac114a5fc8ff |
| children | 7a9afaba88d8 |
| rev | line source |
|---|---|
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 """mailerdaemon - classes to parse mailer-daemon messages""" |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3 import string |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 import rfc822 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
5 import calendar |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
6 import regex |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 import os |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
8 import sys |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
9 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
10 Unparseable = 'mailerdaemon.Unparseable' |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 class ErrorMessage(rfc822.Message): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
13 def __init__(self, fp): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 rfc822.Message.__init__(self, fp) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 def is_warning(self): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 sub = self.getheader('Subject') |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 if not sub: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 return 0 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 sub = string.lower(sub) |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
21 if sub[:12] == 'waiting mail': return 1 |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 if string.find(sub, 'warning') >= 0: return 1 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
23 self.sub = sub |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
24 return 0 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
25 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
26 def get_errors(self): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
27 for p in EMPARSERS: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
28 self.rewindbody() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 try: |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
30 return p(self.fp, self.sub) |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 except Unparseable: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
32 pass |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
35 sendmail_pattern = regex.compile('[0-9][0-9][0-9] ') |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
36 def emparse_sendmail(fp, sub): |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
37 while 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 line = fp.readline() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 line = line[:-1] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 # Check that we're not in the returned message yet |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 if string.lower(line)[:5] == 'from:': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
46 line = string.split(line) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 if len(line) > 3 and \ |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 ((line[0] == '-----' and line[1] == 'Transcript') or |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 (line[0] == '---' and line[1] == 'The' and |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 line[2] == 'transcript') or |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 (line[0] == 'While' and line[1] == 'talking' and line[2] == 'to')): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 # Yes, found it! |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
53 break |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 errors = [] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 found_a_line = 0 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 warnings = 0 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 while 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
59 line = fp.readline() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 break |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
62 line = line[:-1] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 continue |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 if sendmail_pattern.match(line) == 4: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
66 # Yes, an error/warning line. Ignore 4, remember 5, stop on rest |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 if line[0] == '5': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 errors.append(line) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
69 elif line[0] == '4': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
70 warnings = 1 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
71 else: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
73 line = string.split(line) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 if line and line[0][:3] == '---': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 break |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
76 found_a_line = 1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
77 # special case for CWI sendmail |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
78 if len(line) > 1 and line[1] == 'Undelivered': |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
79 while 1: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
80 line = fp.readline() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
81 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
82 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
83 line = string.strip(line) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
84 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
85 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
86 errors.append(line + ': ' + sub) |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 # Empty transcripts are ok, others without an error are not. |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
88 if found_a_line and not (errors or warnings): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
89 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
90 return errors |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
91 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
92 def emparse_cts(fp, sub): |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
93 while 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
94 line = fp.readline() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
95 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
97 line = line[:-1] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
98 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
99 # Check that we're not in the returned message yet |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
100 if string.lower(line)[:5] == 'from:': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
101 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
102 line = string.split(line) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
103 if len(line) > 3 and line[0][:2] == '|-' and line[1] == 'Failed' \ |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
104 and line[2] == 'addresses': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
105 # Yes, found it! |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
106 break |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
107 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 errors = [] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
109 while 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
110 line = fp.readline() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
111 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
112 break |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
113 line = line[:-1] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
114 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
115 continue |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 if line[:2] == '|-': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
117 break |
|
3251
1a39d407b4d3
Fixed bug in cts error message handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3239
diff
changeset
|
118 errors.append(line) |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
119 return errors |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
120 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
121 def emparse_aol(fp, sub): |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
122 while 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
123 line = fp.readline() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
124 if not line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
125 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
126 line = line[:-1] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
127 if line: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 break |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 exp = 'The mail you sent could not be delivered to:' |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 if line[:len(exp)] != exp: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
132 errors = [] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 while 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 line = fp.readline() |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 if sendmail_pattern.match(line) == 4: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
136 # Yes, an error/warning line. Ignore 4, remember 5, stop on rest |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 if line[0] == '5': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 errors.append(line) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
139 elif line[0] != '4': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
140 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
141 elif line == '\n': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
142 break |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
143 else: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
144 raise Unparseable |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
145 return errors |
|
3238
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
146 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
147 def emparse_compuserve(fp, sub): |
|
3238
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
148 while 1: |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
149 line = fp.readline() |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
150 if not line: |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
151 raise Unparseable |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
152 line = line[:-1] |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
153 if line: |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
154 break |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
155 exp = 'Your message could not be delivered for the following reason:' |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
156 if line[:len(exp)] != exp: |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
157 raise Unparseable |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
158 errors = [] |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
159 while 1: |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
160 line = fp.readline() |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
161 if not line: break |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
162 if line[:3] == '---': break |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
163 line = line[:-1] |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
164 if not line: continue |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
165 if line == 'Please resend your message at a later time.': |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
166 continue |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
167 line = 'Compuserve: ' + line |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
168 errors.append(line) |
|
d3510f1118b6
Added (limited) compuserve error parsing
Jack Jansen <jack.jansen@cwi.nl>
parents:
3222
diff
changeset
|
169 return errors |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
170 |
|
3239
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
171 prov_pattern = regex.compile('.* | \(.*\)') |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
172 def emparse_providence(fp, sub): |
|
3239
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
173 while 1: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
174 line = fp.readline() |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
175 if not line: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
176 raise Unparseable |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
177 line = line[:-1] |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
178 |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
179 # Check that we're not in the returned message yet |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
180 if string.lower(line)[:5] == 'from:': |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
181 raise Unparseable |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
182 exp = 'The following errors occurred' |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
183 if line[:len(exp)] == exp: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
184 break |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
185 |
|
3239
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
186 errors = [] |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
187 while 1: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
188 line = fp.readline() |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
189 if not line: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
190 break |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
191 line = line[:-1] |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
192 if not line: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
193 continue |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
194 if line[:4] == '----': |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
195 break |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
196 if prov_pattern.match(line) > 0: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
197 errors.append(prov_pattern.group(1)) |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
198 |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
199 if not errors: |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
200 raise Unparseable |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
201 return errors |
|
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
202 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
203 def emparse_x400(fp, sub): |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
204 exp = 'This report relates to your message:' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
205 while 1: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
206 line = fp.readline() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
207 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
208 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
209 line = line[:-1] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
210 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
211 # Check that we're not in the returned message yet |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
212 if string.lower(line)[:5] == 'from:': |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
213 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
214 if line[:len(exp)] == exp: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
215 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
216 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
217 errors = [] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
218 exp = 'Your message was not delivered to' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
219 while 1: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
220 line = fp.readline() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
221 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
222 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
223 line = line[:-1] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
224 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
225 continue |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
226 if line[:len(exp)] == exp: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
227 error = string.strip(line[len(exp):]) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
228 sep = ': ' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
229 while 1: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
230 line = fp.readline() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
231 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
232 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
233 line = line[:-1] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
234 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
235 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
236 if line[0] == ' ' and line[-1] != ':': |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
237 error = error + sep + string.strip(line) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
238 sep = '; ' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
239 errors.append(error) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
240 return errors |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
241 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
242 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
243 def emparse_passau(fp, sub): |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
244 exp = 'Unable to deliver message because' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
245 while 1: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
246 line = fp.readline() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
247 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
248 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
249 if string.lower(line)[:5] == 'from:': |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
250 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
251 if line[:len(exp)] == exp: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
252 break |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
253 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
254 errors = [] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
255 exp = 'Returned Text follows' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
256 while 1: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
257 line = fp.readline() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
258 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
259 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
260 line = line[:-1] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
261 # Check that we're not in the returned message yet |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
262 if string.lower(line)[:5] == 'from:': |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
263 raise Unparseable |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
264 if not line: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
265 continue |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
266 if line[:len(exp)] == exp: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
267 return errors |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
268 errors.append(string.strip(line)) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
269 |
|
3239
285dba4e0e51
Added providence mailer support
Jack Jansen <jack.jansen@cwi.nl>
parents:
3238
diff
changeset
|
270 EMPARSERS = [emparse_sendmail, emparse_aol, emparse_cts, emparse_compuserve, |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
271 emparse_providence, emparse_x400, emparse_passau] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
272 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
273 def sort_numeric(a, b): |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
274 a = string.atoi(a) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
275 b = string.atoi(b) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
276 if a < b: return -1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
277 elif a > b: return 1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
278 else: return 0 |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
279 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
280 def parsedir(dir, modify): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
281 os.chdir(dir) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
282 pat = regex.compile('^[0-9]*$') |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
283 errordict = {} |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
284 errorfirst = {} |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
285 errorlast = {} |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
286 nok = nwarn = nbad = 0 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
287 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
288 # find all numeric file names and sort them |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
289 files = filter(lambda fn, pat=pat: pat.match(fn) > 0, os.listdir('.')) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
290 files.sort(sort_numeric) |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
291 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
292 for fn in files: |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
293 # Lets try to parse the file. |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
294 fp = open(fn) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
295 m = ErrorMessage(fp) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
296 sender = m.getaddr('From') |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
297 print '%s\t%-40s\t'%(fn, sender[1]), |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
298 |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
299 if m.is_warning(): |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
300 print 'warning only' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
301 nwarn = nwarn + 1 |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
302 if modify: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
303 os.unlink(fn) |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
304 continue |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
305 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
306 try: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
307 errors = m.get_errors() |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
308 except Unparseable: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
309 print '** Not parseable' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
310 nbad = nbad + 1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
311 continue |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
312 print len(errors), 'errors' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
313 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
314 # Remember them |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
315 for e in errors: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
316 try: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
317 mm, dd = m.getdate('date')[1:1+2] |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
318 date = '%s %02d' % (calendar.month_abbr[mm], dd) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
319 except: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
320 date = '??????' |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
321 if not errordict.has_key(e): |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
322 errordict[e] = 1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
323 errorfirst[e] = '%s (%s)' % (fn, date) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
324 else: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
325 errordict[e] = errordict[e] + 1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
326 errorlast[e] = '%s (%s)' % (fn, date) |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
327 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
328 nok = nok + 1 |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
329 if modify: |
|
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
330 os.unlink(fn) |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
331 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
332 print '--------------' |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
333 print nok, 'files parsed,',nwarn,'files warning-only,', |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
334 print nbad,'files unparseable' |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
335 print '--------------' |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
336 for e in errordict.keys(): |
|
3780
ac114a5fc8ff
More changes by Sjoerd & Jack
Guido van Rossum <guido@python.org>
parents:
3251
diff
changeset
|
337 print errordict[e], errorfirst[e], '-', errorlast[e], '\t', e |
|
3222
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
338 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
339 def main(): |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
340 modify = 0 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
341 if len(sys.argv) > 1 and sys.argv[1] == '-d': |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
342 modify = 1 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
343 del sys.argv[1] |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
344 if len(sys.argv) > 1: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
345 for folder in sys.argv[1:]: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
346 parsedir(folder, modify) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
347 else: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
348 parsedir('/ufs/jack/Mail/errorsinbox', modify) |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
349 |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
350 if __name__ == '__main__' or sys.argv[0] == __name__: |
|
0f38cec56539
Script to read and parse error messages from mailer daemons.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
351 main() |
