~barry/mailman/py26

« back to all changes in this revision

Viewing changes to Mailman/Handlers/AvoidDuplicates.py

  • Committer: Barry Warsaw
  • Date: 2008-11-29 23:46:03 UTC
  • mfrom: (1132.1.2 2.1)
  • Revision ID: barry@python.org-20081129234603-5mk8ef9clyz4sp25
trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2002-2003 by the Free Software Foundation, Inc.
 
1
# Copyright (C) 2002-2008 by the Free Software Foundation, Inc.
2
2
#
3
3
# This program is free software; you can redistribute it and/or
4
4
# modify it under the terms of the GNU General Public License
40
40
    # Short circuit
41
41
    if not recips:
42
42
        return
 
43
    # There is an issue with addresses in To: or Cc: that differ in
 
44
    # case from the MemberCPAddresses in recips.  We can't just
 
45
    # lower-case everything because we still want CP addresses in
 
46
    # the final recips list, so we lower case the keys.
43
47
    # Seed this set with addresses we don't care about dup avoiding
44
48
    explicit_recips = {}
45
49
    listaddrs = [mlist.GetListEmail(), mlist.GetBouncesEmail(),
46
50
                 mlist.GetOwnerEmail(), mlist.GetRequestEmail()]
47
51
    for addr in listaddrs:
48
 
        explicit_recips[addr] = True
 
52
        explicit_recips[addr.lower()] = True
49
53
    # Figure out the set of explicit recipients
50
54
    ccaddrs = {}
51
55
    for header in ('to', 'cc', 'resent-to', 'resent-cc'):
52
56
        addrs = getaddresses(msg.get_all(header, []))
53
57
        if header == 'cc':
54
58
            for name, addr in addrs:
55
 
                ccaddrs[addr] = name, addr
 
59
                ccaddrs[addr.lower()] = name, addr
56
60
        for name, addr in addrs:
57
61
            if not addr:
58
62
                continue
59
63
            # Ignore the list addresses for purposes of dup avoidance
60
 
            explicit_recips[addr] = True
 
64
            explicit_recips[addr.lower()] = True
61
65
    # Now strip out the list addresses
62
66
    for addr in listaddrs:
63
 
        del explicit_recips[addr]
 
67
        del explicit_recips[addr.lower()]
64
68
    if not explicit_recips:
65
69
        # No one was explicitly addressed, so we can't do any dup collapsing
66
70
        return
67
71
    newrecips = []
68
72
    for r in recips:
69
73
        # If this recipient is explicitly addressed...
70
 
        if explicit_recips.has_key(r):
 
74
        if explicit_recips.has_key(r.lower()):
71
75
            send_duplicate = True
72
76
            # If the member wants to receive duplicates, or if the recipient
73
77
            # is not a member at all, just flag the X-Mailman-Duplicate: yes
81
85
            if send_duplicate:
82
86
                msgdata.setdefault('add-dup-header', {})[r] = True
83
87
                newrecips.append(r)
84
 
            elif ccaddrs.has_key(r):
85
 
                del ccaddrs[r]
 
88
            elif ccaddrs.has_key(r.lower()):
 
89
                del ccaddrs[r.lower()]
86
90
        else:
87
91
            # Otherwise, this is the first time they've been in the recips
88
92
            # list.  Add them to the newrecips list and flag them as having