[Mailman-Developers] Sub-address patch

Sean Reifschneider jafo@tummy.com
Sun, 12 Sep 1999 01:38:26 -0600


I haven't done any testing of this code yet (I'm not comfortable enough
with things to shove this into production, and don't have a test mailman
setup I can run this on).  The goal of this patch is to add sub-address
matching to the SMART_ADDRESS_MATCH code.

I've added a new option "SMART_ADDRESS_MATCH_SUBADDR" to make it easy to
disable (perhaps it should even be allowed on a per-list basis?).  It's
goal is to match "user-mailman-devel@example.com" with "user@example.com".
I frequently subscribe to a list as "jafo-listname@", but submit from
"jafo@" and sometimes get tripped up in the closed-list restrictions.

It handles both qmail-style sub-addresses (as above) and sendmail-style
("jafo+mailman+devel").

I believe this was one of the things that I asked to be added to the
TODO list, but I don't see it on there (nor did I see any discussion of
it).

Sean
===============

Index: Defaults.py.in
===================================================================
RCS file: /projects/cvsroot/mailman/Mailman/Defaults.py.in,v
retrieving revision 1.83
diff -c -r1.83 Defaults.py.in
*** Defaults.py.in	1999/09/07 18:32:44	1.83
--- Defaults.py.in	1999/09/12 07:13:49
***************
*** 120,131 ****
  # spoofed messages may get through.
  USE_ENVELOPE_SENDER = 0
  
! # When true, mailman will consider user@host.domain to be the same address
! # as user@domain.  If set to 0, mailman will consider user@host.domain to 
! # be the same address as user@Host.DoMain, but different than user@domain.
! # Usernames will be case preserved, and host parts of addresses will all be
! # lowercased.
  SMART_ADDRESS_MATCH = 1
  # When set, the listinfo web page overview of lists on the machine will be
  # confined to only those lists whose web_page_url configuration option host
  # is included within the URL by which the page is visited - only those "on
--- 120,139 ----
  # spoofed messages may get through.
  USE_ENVELOPE_SENDER = 0
  
! # When SMART_ADDRESS_MATCH is true, mailman will consider user@host.domain
! # to be the same address as user@domain.  If set to 0, mailman will
! # consider user@host.domain to be the same address as user@Host.DoMain,
! # but different than user@domain.  Usernames will be case preserved,
! # and host parts of addresses will all be lowercased.
  SMART_ADDRESS_MATCH = 1
+ # When SMART_ADDRESS_MATCH_SUBADDR is true (as well as SMART_ADDRESS_MATCH), 
+ # user names with '+' or '-' in them are tried with this part stripped.
+ # For example, "user-mailman-devel@example.com" will match
+ # (in addition to the full address) "user-mailman@example.com" and
+ # "user@example.com".  Similarly with the '+' symbol (- is qmail, + is
+ # sendmail).
+ SMART_ADDRESS_MATCH_SUBADDR = 1
+ 
  # When set, the listinfo web page overview of lists on the machine will be
  # confined to only those lists whose web_page_url configuration option host
  # is included within the URL by which the page is visited - only those "on
Index: Utils.py
===================================================================
RCS file: /projects/cvsroot/mailman/Mailman/Utils.py,v
retrieving revision 1.77
diff -c -r1.77 Utils.py
*** Utils.py	1999/09/03 05:55:51	1.77
--- Utils.py	1999/09/12 07:13:51
***************
*** 455,471 ****
      """returns a sorted list of addresses that could possibly match
      a given name.
  
!     For Example, given scott@pobox.com, return ['scott@pobox.com'],
!     given scott@blackbox.pobox.com return ['scott@blackbox.pobox.com',
                                             'scott@pobox.com']"""
  
      name = string.lower(name)
      user, domain = ParseEmail(name)
      res = [name]
      if domain:
          domain = domain[1:]
          while len(domain) >= 2:
!             res.append("%s@%s" % (user, string.join(domain, ".")))
              domain = domain[1:]
      return res
  
--- 455,486 ----
      """returns a sorted list of addresses that could possibly match
      a given name.
  
!     For Example, given scott@pobox.com, return ['scott-mailman@pobox.com'],
!     given scott@blackbox.pobox.com return ['scott-mailman@blackbox.pobox.com',
!                                            'scott@blackbox.pobox.com',
!                                            'scott-mailman@pobox.com',
                                             'scott@pobox.com']"""
  
      name = string.lower(name)
      user, domain = ParseEmail(name)
      res = [name]
+ 
+     #  Try stripping off sub-addresses
+     userList = [user]
+     if mm_cfg.SMART_ADDRESS_MATCH_SUBADDR:
+         userTmp = userList[0]
+         for split in ( '-', '+' ):
+             while 1:
+                 pos = string.rfind(userTmp, split)
+                 if pos <= 0: break   #  <= to not create empty user-names
+                 userTmp = userTmp[:pos]
+                 if pos: userList.append(userTmp)
+ 
      if domain:
          domain = domain[1:]
          while len(domain) >= 2:
!             for user in userList:
!                 res.append("%s@%s" % (user, string.join(domain, ".")))
              domain = domain[1:]
      return res

-- 
 Linux:  When you need to run like a greased weasel.
                 -- Sean Reifschneider, 1998
Sean Reifschneider, Inimitably Superfluous <jafo@tummy.com>
URL: <http://www.tummy.com/xvscan> HP-UX/Linux/FreeBSD/BSDOS scanning software.