1"""Recognizes simple heuristically delimited warnings."""
2
3from flufl.bounce._detectors.simplematch import SimpleMatch, _c
4from flufl.bounce.interfaces import NoPermanentFailures
5from public import public
6
7
8# This is a list of tuples of the form
9#
10#     (start cre, end cre, address cre)
11#
12# where 'cre' means compiled regular expression, start is the line just before
13# the bouncing address block, end is the line just after the bouncing address
14# block, and address cre is the regexp that will recognize the addresses.  It
15# must have a group called 'addr' which will contain exactly and only the
16# address that bounced.
17PATTERNS = [
18    # pop3.pta.lia.net
19    (_c('The address to which the message has not yet been delivered is'),
20     _c('No action is required on your part'),
21     _c(r'\s*(?P<addr>\S+@\S+)\s*')),
22    # MessageSwitch
23    (_c('Your message to:'),
24     _c('This is just a warning, you do not need to take any action'),
25     _c(r'\s*(?P<addr>\S+@\S+)\s*')),
26    # Symantec_AntiVirus_for_SMTP_Gateways
27    (_c('Your message with Subject:'),
28     _c('Delivery attempts will continue to be made'),
29     _c(r'\s*(?P<addr>\S+@\S+)\s*')),
30    # googlemail.com warning
31    (_c('Delivery to the following recipient has been delayed'),
32     _c('Message will be retried'),
33     _c(r'\s*(?P<addr>\S+@\S+)\s*')),
34    # Exchange warning message.
35    (_c('This is an advisory-only email'),
36     _c('has been postponed'),
37     _c('"(?P<addr>[^"]+)"')),
38    # kundenserver.de
39    (_c('not yet been delivered'),
40     _c('No action is required on your part'),
41     _c(r'\s*<?(?P<addr>\S+@[^>\s]+)>?\s*')),
42    # Next one goes here...
43    ]
44
45
46@public
47class SimpleWarning(SimpleMatch):
48    """Recognizes simple heuristically delimited warnings."""
49
50    PATTERNS = PATTERNS
51
52    def process(self, msg):
53        """See `SimpleMatch`."""
54        # Since these are warnings, they're classified as temporary failures.
55        # There are no permanent failures.
56        (temporary,
57         permanent_really_temporary) = super(SimpleWarning, self).process(msg)
58        return permanent_really_temporary, NoPermanentFailures
59