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,
17
18
"""Calculate the regular (i.e. non-digest) recipients of the message.
22
23
SendmailDeliver and BulkDeliver modules.
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
37
# Use set for sibling list recipient calculation
40
except NameError: # Python2.3
41
from sets import Set as set
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)
89
102
msgdata['recips'] = recips
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
94
111
hits = msgdata.get('topichits')
130
147
# Prune out the non-receiving users
131
148
for user in zaprecips:
132
149
recips.remove(user)
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:
157
if not mlist.regular_exclude_lists:
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:
167
listlhs, hostname = listname.split('@')
168
if listlhs == mlist.internal_name():
169
syslog('error', 'Exclude list %s is a self reference.',
173
slist = MailList(listlhs, lock=False)
174
except MMUnknownListError:
175
syslog('error', 'Exclude list %s not found.', listname)
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.',
182
srecips = set([slist.getMemberCPAddress(m)
183
for m in slist.getRegularMemberKeys()
184
if slist.getDeliveryStatus(m) == ENABLED])
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:
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:
203
listlhs, hostname = listname.split('@')
204
if listlhs == mlist.internal_name():
205
syslog('error', 'Include list %s is a self reference.',
209
slist = MailList(listlhs, lock=False)
210
except MMUnknownListError:
211
syslog('error', 'Include list %s not found.', listname)
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.',
218
srecips = set([slist.getMemberCPAddress(m)
219
for m in slist.getRegularMemberKeys()
220
if slist.getDeliveryStatus(m) == ENABLED])