~mailman-coders/mailman/2.1

« back to all changes in this revision

Viewing changes to Mailman/Bouncers/SimpleWarning.py

  • Committer: Mark Sapiro
  • Date: 2020-01-17 00:03:34 UTC
  • Revision ID: mark@msapiro.net-20200117000334-8s3tx7yimpxt5oqj
Fixed SimpleMatch to only return valid addresses.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Recognizes simple heuristically delimited warnings."""
19
19
 
 
20
import email
 
21
 
20
22
from Mailman.Bouncers.BouncerAPI import Stop
21
23
from Mailman.Bouncers.SimpleMatch import _c
22
 
from Mailman.Bouncers.SimpleMatch import process as _process
23
24
 
24
25
 
25
26
 
67
68
 
68
69
 
69
70
def process(msg):
70
 
    if _process(msg, patterns):
71
 
        # It's a recognized warning so stop now
72
 
        return Stop
73
 
    else:
74
 
        return []
 
71
    # We used to just import process from SimpleMatch, but with the change in
 
72
    # SimpleMatch to return only vaild addresses, that doesn't work any more.
 
73
    # So, we copy most of the process from SimpleMatch here.
 
74
    addrs = {}
 
75
    for scre, ecre, acre in patterns:
 
76
        state = 0
 
77
        for line in email.Iterators.body_line_iterator(msg, decode=True):
 
78
            if state == 0:
 
79
                if scre.search(line):
 
80
                    state = 1
 
81
            if state == 1:
 
82
                mo = acre.search(line)
 
83
                if mo:
 
84
                    addr = mo.group('addr')
 
85
                    if addr:
 
86
                        addrs[addr.strip('<>')] = 1
 
87
                elif ecre.search(line):
 
88
                    break
 
89
        if addrs:
 
90
            # It's a recognized warning so stop now
 
91
            return Stop
 
92
    return []