[Mailman-Users] Running a script on subscribe/unsubscribe?

Mark Sapiro msapiro at value.net
Mon Mar 13 05:46:29 CET 2006


Dragon wrote:

>I have a list where I have provided a number of web features for 
>members. I have implemented a script to extract the email address and 
>password for each user and then update the password files for Apache 
>authentication for the list web directories. This script also does a 
>lot of additional set up for these features.
>
>I currently have this script set up as a cron job. I would prefer to 
>have it run only when a user actually subscribes or unsubscribes.
>
>I've looked through the FAQ and have not found anything that I 
>thought was applicable to doing this. Does anyone have an idea on how 
>this could be done?


I have a couple of ideas depending on what the problems are with your
current method. If you want to eliminate the cron altogether, you'll
have to hook into Mailman at a fairly low level to catch everything
including things like bounce processing unsubscribes, address changes,
password changes, admin mass subscribe and unsubscribe, etc.

If you are willing the run the script via cron at some interval to pick
up the exceptional cases, and you're not too concerned about email
subscribe and unsubscribe, you could hook into the subscribe.html and
options.html templates to catch events from those forms. The downside
of this approach is aside from not getting everything, these may
trigger the script to run while the request is still waiting for a
confirmation. See
<http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq04.048.htp>
for info on editing templates.

A better way to do this is to hook into the actual addNewMember(),
removeMember(), changeMemberAddress() and setMemberPassword() methods
in the member adaptor. Actually, if you use a modified
OldStyleMemberships.py as I suggest below, you only need to hook into
removeMember() and setMemberPassword() because changeMemberAddress()
calls removeMember() and addNewMember(), and addNewMember() calls
setMemberPassword().

To do this, assuming you are not already using a custom member adaptor,
first make a copy of Mailman/OldStyleMemberships.py at, for example,
Mailman/MyOldStyleMemberships.py. Then make a file named extend.py
containing the following from between the dashed lines.

--------------------------------------------------------
from Mailman import MyOldStyleMemberships

def extend(mlist):
    mlist._memberadaptor = \
        MyOldStyleMemberships.OldStyleMemberships(mlist)
--------------------------------------------------------

Then you can put the extend.py file in the lists/<listname>/ directory
for any list you want to use the MyOldStyleMemberships.py member
adaptor. Any list that has this extend.py in its lists/<listname>/
directory will use the MyOldStyleMemberships.py member adaptor which
you can then modify to add the necessary hooks without affecting other
lists and without your modifications subject to being overwritten if
Mailman is upgraded. The hooks will have to be written in Python, but
they can be as simple as spawning a process to run the existing script
or as complex as replacing the script entirely or something in between.

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




More information about the Mailman-Users mailing list