~nkarageuzian/mailman/usermanagement

« back to all changes in this revision

Viewing changes to src/mailman/bouncers/smtp32.py

  • Committer: Barry Warsaw
  • Date: 2011-07-15 22:55:19 UTC
  • mfrom: (7027.1.1 refactor)
  • Revision ID: barry@list.org-20110715225519-3q8qr1oyv9rqfcd1
Factor out bounce detection to `flufl.bounce`.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 1998-2011 by the Free Software Foundation, Inc.
2
 
#
3
 
# This file is part of GNU Mailman.
4
 
#
5
 
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
 
# the terms of the GNU General Public License as published by the Free
7
 
# Software Foundation, either version 3 of the License, or (at your option)
8
 
# any later version.
9
 
#
10
 
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 
# more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License along with
16
 
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
"""Something which claims
19
 
X-Mailer: <SMTP32 vXXXXXX>
20
 
 
21
 
What the heck is this thing?  Here's a recent host:
22
 
 
23
 
% telnet 207.51.255.218 smtp
24
 
Trying 207.51.255.218...
25
 
Connected to 207.51.255.218.
26
 
Escape character is '^]'.
27
 
220 X1 NT-ESMTP Server 208.24.118.205 (IMail 6.00 45595-15)
28
 
 
29
 
"""
30
 
 
31
 
from __future__ import absolute_import, unicode_literals
32
 
 
33
 
__metaclass__ = type
34
 
__all__ = [
35
 
    'SMTP32',
36
 
    ]
37
 
 
38
 
 
39
 
import re
40
 
 
41
 
from email.iterators import body_line_iterator
42
 
from zope.interface import implements
43
 
 
44
 
from mailman.interfaces.bounce import IBounceDetector
45
 
 
46
 
 
47
 
ecre = re.compile('original message follows', re.IGNORECASE)
48
 
acre = re.compile(r'''
49
 
    (                                             # several different prefixes
50
 
    user\ mailbox[^:]*:                           # have been spotted in the
51
 
    |delivery\ failed[^:]*:                       # wild...
52
 
    |unknown\ user[^:]*:
53
 
    |undeliverable\ +to
54
 
    |delivery\ userid[^:]*:
55
 
    )
56
 
    \s*                                           # space separator
57
 
    (?P<addr>[^\s]*)                              # and finally, the address
58
 
    ''', re.IGNORECASE | re.VERBOSE)
59
 
 
60
 
 
61
 
 
62
 
class SMTP32:
63
 
    """Something which claims
64
 
 
65
 
    X-Mailer: <SMTP32 vXXXXXX>
66
 
    """
67
 
 
68
 
    implements(IBounceDetector)
69
 
 
70
 
    def process(self, msg):
71
 
        mailer = msg.get('x-mailer', '')
72
 
        if not mailer.startswith('<SMTP32 v'):
73
 
            return set()
74
 
        addresses = set()
75
 
        for line in body_line_iterator(msg):
76
 
            if ecre.search(line):
77
 
                break
78
 
            mo = acre.search(line)
79
 
            if mo:
80
 
                addresses.add(mo.group('addr'))
81
 
        return addresses