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

Dragon dragon at crimson-dragon.com
Mon Mar 13 07:49:29 CET 2006


Mark Sapiro sent the message below at 08:46 PM 3/12/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.

It's not so much a problem per se as it is just that I want 
processing to be much more immediate so that when a member 
subscription is approved or a member unsubscribes or is removed from 
the list, the password update and other setup activities don't have 
to wait around for the next cron interval. (Which is currently set to 
run hourly).

The list this is running with is fairly small and it will remain that 
way as it is an invite only forum that I run for some esoteric stuff. 
So running cron on it is a bit of overkill because the list 
membership is quite static for long periods and if I don't have to 
run the script if there is no reason to do so, I would prefer that. 
(Of course, I wrote the script because doing all this manually is a 
pain in the rear...)

>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.

Well as I said above, I am primarily interested in having the updates 
occur as soon as possible, particularly in the case of somebody 
leaving the list. I want to remove access to the web features I have 
set up and also remove their profiles as in my web system.

>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.

Nah, this does not look very useful to me because this list requires 
moderator approval to subscribe.

>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,

Nope, I am new to Python. I'm an old hack with Perl and C and PHP, 
but Python is something I have never fiddled with.

I'm certainly willing to give this a try though, I can usually wrap 
my head around a new programming language pretty quickly. Especially 
if I can get some good guidance over the thorny bits.

>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.

OK, this looks like the right path for what I want to do. It would be 
nice if I can pass the affected e-mail address to my script so I can 
take action on only that e-mail address. The only thing I see as 
problematic is the case where a user changes the subscribed e-mail address.

But as my boss likes to say "If it were simple, anyone could do it".

Thanks for the help so far, I am sure I will have other questions as 
I figure this out.

Dragon

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Venimus, Saltavimus, Bibimus (et naribus canium capti sumus)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




More information about the Mailman-Users mailing list