~xav0989/ubuntu/vivid/mailman/ubuntu-logo

« back to all changes in this revision

Viewing changes to Mailman/Handlers/CalcRecips.py

  • Committer: Bazaar Package Importer
  • Author(s): Thijs Kinkhorst
  • Date: 2008-04-24 19:30:49 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080424193049-jy5fa9tus40tjbmn
Tags: 1:2.1.10-2
Apply upstream patch to fix regression in cmd_subscribe
so that email subscribe to the -subscribe or -join address or the
-request address with a bare 'subscribe' command results in the message
being shunted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
 
1
# Copyright (C) 1998-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
12
12
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software 
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 
16
# USA.
16
17
 
17
18
"""Calculate the regular (i.e. non-digest) recipients of the message.
18
19
 
22
23
SendmailDeliver and BulkDeliver modules.
23
24
"""
24
25
 
 
26
import email.Utils
25
27
from Mailman import mm_cfg
26
28
from Mailman import Utils
27
29
from Mailman import Message
28
30
from Mailman import Errors
29
31
from Mailman.MemberAdaptor import ENABLED
 
32
from Mailman.MailList import MailList
30
33
from Mailman.i18n import _
31
34
from Mailman.Logging.Syslog import syslog
 
35
from Mailman.Errors import MMUnknownListError
 
36
 
 
37
# Use set for sibling list recipient calculation
 
38
try:
 
39
    set
 
40
except NameError: # Python2.3
 
41
    from sets import Set as set
32
42
 
33
43
 
34
44
 
85
95
            pass
86
96
    # Handle topic classifications
87
97
    do_topic_filters(mlist, msg, msgdata, recips)
 
98
    # Regular delivery exclude/include (if in/not_in To: or Cc:) lists
 
99
    recips = do_exclude(mlist, msg, msgdata, recips)
 
100
    recips = do_include(mlist, msg, msgdata, recips)
88
101
    # Bookkeeping
89
102
    msgdata['recips'] = recips
90
103
 
91
104
 
92
105
 
93
106
def do_topic_filters(mlist, msg, msgdata, recips):
 
107
    if not mlist.topics_enabled:
 
108
        # MAS: if topics are currently disabled for the list, send to all
 
109
        # regardless of ReceiveNonmatchingTopics
 
110
        return
94
111
    hits = msgdata.get('topichits')
95
112
    zaprecips = []
96
113
    if hits:
130
147
    # Prune out the non-receiving users
131
148
    for user in zaprecips:
132
149
        recips.remove(user)
133
 
    
 
150
 
 
151
 
 
152
def do_exclude(mlist, msg, msgdata, recips):
 
153
    # regular_exclude_lists are the other mailing lists on this mailman
 
154
    # installation whose members are excluded from the regular (non-digest)
 
155
    # delivery of this list if those list addresses appear in To: or Cc:
 
156
    # headers.
 
157
    if not mlist.regular_exclude_lists:
 
158
        return recips
 
159
    recips = set(recips)
 
160
    destinations = email.Utils.getaddresses(msg.get_all('to', []) +
 
161
                                            msg.get_all('cc', []))
 
162
    destinations = [y.lower() for x,y in destinations]
 
163
    for listname in mlist.regular_exclude_lists:
 
164
        listname = listname.lower()
 
165
        if listname not in destinations:
 
166
            continue
 
167
        listlhs, hostname = listname.split('@')
 
168
        if listlhs == mlist.internal_name():
 
169
            syslog('error', 'Exclude list %s is a self reference.',
 
170
                    listname)
 
171
            continue
 
172
        try:
 
173
            slist = MailList(listlhs, lock=False)
 
174
        except MMUnknownListError:
 
175
            syslog('error', 'Exclude list %s not found.', listname)
 
176
            continue
 
177
        if not mm_cfg.ALLOW_CROSS_DOMAIN_SIBLING \
 
178
           and slist.host_name != hostname:
 
179
            syslog('error', 'Exclude list %s is not in the same domain.',
 
180
                    listname)
 
181
            continue
 
182
        srecips = set([slist.getMemberCPAddress(m)
 
183
                   for m in slist.getRegularMemberKeys()
 
184
                   if slist.getDeliveryStatus(m) == ENABLED])
 
185
        recips -= srecips
 
186
    return list(recips)
 
187
 
 
188
 
 
189
def do_include(mlist, msg, msgdata, recips):
 
190
    # regular_include_lists are the other mailing lists on this mailman
 
191
    # installation whose members are included in the regular (non-digest)
 
192
    # delivery if those list addresses don't appear in To: or Cc: headers.
 
193
    if not mlist.regular_include_lists:
 
194
        return recips
 
195
    recips = set(recips)
 
196
    destinations = email.Utils.getaddresses(msg.get_all('to', []) +
 
197
                                            msg.get_all('cc', []))
 
198
    destinations = [y.lower() for x,y in destinations]
 
199
    for listname in mlist.regular_include_lists:
 
200
        listname = listname.lower()
 
201
        if listname in destinations:
 
202
            continue
 
203
        listlhs, hostname = listname.split('@')
 
204
        if listlhs == mlist.internal_name():
 
205
            syslog('error', 'Include list %s is a self reference.',
 
206
                    listname)
 
207
            continue
 
208
        try:
 
209
            slist = MailList(listlhs, lock=False)
 
210
        except MMUnknownListError:
 
211
            syslog('error', 'Include list %s not found.', listname)
 
212
            continue
 
213
        if not mm_cfg.ALLOW_CROSS_DOMAIN_SIBLING \
 
214
           and slist.host_name != hostname:
 
215
            syslog('error', 'Include list %s is not in the same domain.',
 
216
                    listname)
 
217
            continue
 
218
        srecips = set([slist.getMemberCPAddress(m)
 
219
                   for m in slist.getRegularMemberKeys()
 
220
                   if slist.getDeliveryStatus(m) == ENABLED])
 
221
        recips |= srecips
 
222
    return list(recips)