Thank you for replying Mark.
Mark Sapiro wrote:
C Nulk wrote:
I have recently implemented the LDAPMembership adapter. It provides some good functionality in creating the list membership. However, the concept is there to provide access to one or more lists of email addresses (list membership is essentially a list of email addresses). I would like to use the LDAP functionality in other areas which require or use a list of email addresses (e.g. accept_these_nonmembers, hold_these_nonmembers, etc).
I have looked at the F.A.Q. on custom handlers and read the MailList.py file (under __init__) to see the 'extend.py' file being loaded.
Can someone better explain how loading the 'extend.py' file incorporates the files code and how the 'def extend' function is called? If I can understand how it works, perhaps, a solution to adding multiple LDAP search queries can be added to the extend.py file and used in other places in Mailman.
Chris,
The extend.py mechanism as you use it basically just replaces the default mamber adaptor OLDStyleMembertships.py with LDAPMemberships.py for any list that has the extend.py file in it's lists/LISTNAME/ directory. In addition, it defines a few attributes which may or may not be list-specific which allow LDAPMemberships.py to get to the appropriate LDAP database.
If you've read the __init__ method in MailList.py, you've seen everything there is to see about extend.py. It gets called there and there only when the list is instantiated and sets the lists ._memberadaptor attribute to LDAPMemberships.
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.
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.
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.
The key would be the changes to extend.py so everything works.
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. :)
Thanks, Chris