[Mailman-Developers] Change to acceptable_aliases
Barry A. Warsaw
bwarsaw@cnri.reston.va.us
Fri, 14 Apr 2000 13:53:48 -0400 (EDT)
>>>>> "BAW" == Barry A Warsaw <bwarsaw@cnri.reston.va.us> writes:
BAW> +1 on Harald's approach, with a provision to remove #1 in
BAW> some future version.
And here's the patch.
-Barry
Index: MailList.py
===================================================================
RCS file: /projects/cvsroot/mailman/Mailman/MailList.py,v
retrieving revision 1.161
diff -c -r1.161 MailList.py
*** MailList.py 2000/04/13 23:25:16 1.161
--- MailList.py 2000/04/14 17:34:09
***************
*** 1215,1250 ****
# this is the list's full address
listfullname = '%s@%s' % (self.internal_name(), self.host_name)
recips = []
! # check all recipient addresses against the list's full address...
for fullname, addr in msg.getaddrlist('to') + msg.getaddrlist('cc'):
! localpart = string.lower(string.split(addr, '@')[0])
! laddr = string.lower(addr)
if (# TBD: backwards compatibility: deprecated
localpart == self.internal_name() or
! # new behavior
! laddr == listfullname):
return 1
! recips.append((laddr, localpart))
! # ... and only then try the regexp acceptable aliases.
! for laddr, localpart in recips:
for alias in string.split(self.acceptable_aliases, '\n'):
stripped = string.strip(alias)
! if '@' in stripped:
! # new behavior: match the entire recipient string
! recip = laddr
! else:
! # TBD: backwards compatibility: deprecated
! recip = localpart
! try:
! # The list alias in `stripped` is a user supplied regexp,
! # which could be malformed.
! if stripped and re.match(stripped, recip):
! return 1
! except re.error:
! # `stripped' is a malformed regexp -- try matching
! # safely, with all non-alphanumerics backslashed:
! if stripped and re.match(re.escape(stripped), recip):
! return 1
return 0
def parse_matching_header_opt(self):
--- 1215,1261 ----
# this is the list's full address
listfullname = '%s@%s' % (self.internal_name(), self.host_name)
recips = []
! # check all recipient addresses against the list's explicit address.
for fullname, addr in msg.getaddrlist('to') + msg.getaddrlist('cc'):
! addr = string.lower(addr)
! localpart = string.split(addr, '@')[0]
if (# TBD: backwards compatibility: deprecated
localpart == self.internal_name() or
! # exact match against the complete list address
! addr == listfullname):
return 1
! recips.append((addr, localpart))
! #
! # helper function used to match a pattern against an address. Do it
! def domatch(pattern, addr):
! try:
! if re.match(pattern, addr):
! return 1
! except re.error:
! # The pattern is a malformed regexp -- try matching safely,
! # with all non-alphanumerics backslashed:
! if re.match(re.escape(pattern), addr):
! return 1
! #
! # Here's the current algorithm for matching acceptable_aliases:
! #
! # 1. If the pattern does not have an `@' in it, we first try matching
! # it against just the localpart. This was the behavior prior to
! # 2.0beta3, and is kept for backwards compatibility.
! # (deprecated).
! #
! # 2. If that match fails, or the pattern does have an `@' in it, we
! # try matching against the entire recip address.
! for addr, localpart in recips:
for alias in string.split(self.acceptable_aliases, '\n'):
stripped = string.strip(alias)
! if not stripped:
! # ignore blank or empty lines
! continue
! if '@' not in stripped and domatch(stripped, localpart):
! return 1
! if domatch(stripped, addr):
! return 1
return 0
def parse_matching_header_opt(self):