[Mailman-Developers] Mailman and Extend.py

Mark Sapiro mark at msapiro.net
Tue Apr 14 01:05:56 CEST 2009


C Nulk wrote:
>
>While I waited, I did do some reading/researching on __init__ which lead
>me to reading about __getattr__ and getattr.  If I understand correctly,
>the LDAPMemberships uses them to get the isMember() and getMembers()
>methods among others.


Not exactly. Since the MemberAdaptor is replaceable, it can't simply be
a super class of the MailList class. Thus, it's methods are not in the
name space of the MailList object so we need an __getattr__ method to
access them from whatever class is assigned as the list's
_memberadaptor. So when you reference a method such as
mlist.isMember() that is not directly in the name space of the mlist
instance so mlist.__getattr__('isMember') is called (behind the
scenes) and it finds mlist._memberadaptor.isMember() and returns that.

This is true whether _memberadaptor is the default OldStyleMemberships
class or the LDAPMemberships class or something else. The only thing
that is specific to LDAPMemberships is the fact that the list's
extend.py module assigned LDAPMemberships to _memberadaptor.


>> From then on, whenever a member adaptor method is called for that list,
>> the method that is called is the one defined in LDAPMemberships.py.
>> 
>> So, for example, if your Mailman version is 2.1.10 or later so that it
>> supports the @LISTNAME entry in *_these_nonmembers, and you put say
>> @list2 in accept_these_nonmembers of list1, list1's processing of a
>> non-member post will call list2's isMember() method to see if the
>> poster is a member of list2, and if list2 already uses
>> LDAPMemberships, that's it - it's isMember() method will use its LDAP
>> database.
>
>Unfortunately, I am stuck at v2.1.9 for now.
>
>> 
>> See the matches_p function in Mailman/Handlers/Moderate.py for more
>> detail.
>
>I did look at Mailman/Handlers/Moderate.py, specifically the matches_p
>function.  What I envisioned doing was to modify the matches_p function
>to single out "ldap" entries similar to the regex entries.  Then for
>each "ldap" entry, call an LDAP2Dict function (to be written) which
>returns a dictionary of email addresses, then check if the sender was in
>the returned dictionary.


That would work, but if this dictionary could be equated to the
membership of some list, it seems to me that it would be easier to
just backport the @listname feature to 2.1.9. You can find the
original patch at
<http://sourceforge.net/tracker/?func=detail&aid=1220144&group_id=103&atid=300103>.
The 2.1.10 implementation is a bit more elaborate, but the SourceForge
patch should be sufficient for your purpose.

Note that there is nothing magic about the dictionary in

    plainaddrs = [addr for addr in nonmembers if not
                                   addr.startswith('^')]
    addrdict = Utils.List2Dict(plainaddrs, foldcase=1)
    if addrdict.has_key(sender):
        return 1

This could just as easily have been spelled

    plainaddrs = [addr.lower() for addr in nonmembers if not
                                   addr.startswith('^')]
    if sender in plainaddrs:
        return 1


>The changes made to LDAPMemberships.py would help since you explained to
>me that one of your changes was to make members a dictionary.  The
>getMembers() method would essentially return that dictionary.


No. getMembers() MUST return a list or everything breaks.


>The key would be the changes to extend.py so everything works.


If you are accessing some LDAP directly (not via the @list construct)
in the matches_p function, extend.py has nothing to do with it.


>> 
>> I hope this helps. If you still have questions, keep asking.
>> 
>
>It has helped.  I have made some changes to Mailman/Handlers/Moderate.py
>and Utils.py (to add the LDAP2Dict function).  Let me know if you would
>like to see what I came up with and I can send the diffs and
>explaination to you off-list.  You may have a better way to implement
>what I am doing.  Well, actually, you probably do have a better way. :)


See my remarks above.

-- 
Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan



More information about the Mailman-Developers mailing list