~paulegan/flufl.bounce/caiwireless-bug-917720

« back to all changes in this revision

Viewing changes to flufl/bounce/_detectors/postfix.py

  • Committer: Barry Warsaw
  • Date: 2012-01-04 16:39:36 UTC
  • Revision ID: barry@python.org-20120104163936-qrrd7ipqrprpxwvp
 * Port to Python 3 is mostly complete, however the test suite current fails
   because of <https://bugs.launchpad.net/zope.interface/+bug/911851>.  Once
   that bug is fixed in `zope.interface`, `flufl.bounce` should be Python 3.2
   compatible without the need for `2to3`.
 * All returned addresses are bytes objects in Python 3 and 8-bit strings in
   Python 2 (no change there).

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
import re
36
36
 
37
 
from cStringIO import StringIO
38
37
from flufl.enum import Enum
 
38
from io import BytesIO
39
39
from zope.interface import implements
40
40
 
41
41
from flufl.bounce.interfaces import (
43
43
 
44
44
 
45
45
# Are these heuristics correct or guaranteed?
46
 
pcre = re.compile(r'[ \t]*the\s*(bns)?\s*(postfix|keftamail|smtp_gateway)',
47
 
                  re.IGNORECASE)
48
 
rcre = re.compile(r'failure reason:$', re.IGNORECASE)
49
 
acre = re.compile(r'<(?P<addr>[^>]*)>:')
 
46
pcre = re.compile(
 
47
    b'[ \\t]*the\\s*(bns)?\\s*(postfix|keftamail|smtp_gateway)',
 
48
    re.IGNORECASE)
 
49
rcre = re.compile(b'failure reason:$', re.IGNORECASE)
 
50
acre = re.compile(b'<(?P<addr>[^>]*)>:')
50
51
 
51
52
REPORT_TYPES = ('multipart/mixed', 'multipart/report')
52
53
 
69
70
 
70
71
def findaddr(msg):
71
72
    addresses = set()
72
 
    body = StringIO(msg.get_payload())
 
73
    body = BytesIO(msg.get_payload(decode=True))
73
74
    state = ParseState.start
74
75
    for line in body:
75
76
        # Preserve leading whitespace.