PHP access to Mailman?

software development

#1

Hi All,

Have anyone done any PHP integration to Mailman (Discussion lists) on DH sites?

I would like to auto add/remove members when they are added/removed from associated groups in a CMS (Xoops) site.


#2

Hi marook.

I have the same situation. How did you solve this problem?


#3

As far as I can tell, there’s no way to do this without privileged access to run the mailman/bin commands except to “screen scrape” the web interface. [On other systems, where you can run a cron job as a privileged user, it’s straightforward to put together a shell or python script to manipulate the subscriber database.]

There’s a discussion of doing this with wget in the thread starting at
http://mail.python.org/pipermail/mailman-users/2004-December/041213.html

I’ve settled on using cURL.

$file = pathname (on the server) of a file containing the addresses (or name/addresses) to subscribe/unsubscribe
$pass = admin’s password for the list
$host = hostname, i.e. the part after “lists.” in the admin url
$listname = name of the list

[code] $postData[ ‘subscribees_upload’ ] = “@”.$file;
$postData[ ‘adminpw’ ] = $pass;
$postData [ ‘subscribe_or_invite’] = 0;
$postData [ ‘send_welcome_msg_to_this_batch’ ] = 0;
$postData [ ‘send_notifications_to_list_owner’ ] = 0;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,“http://lists.”.$host."/admin.cgi/".$listname."-".$host."/members/add");
curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);

curl_exec ($curl);
curl_close ($curl);
[/code]If the script generates the address(es) instead of reading them from a file, use subscribees instead of subscribees_upload.

$postData[ 'subscribees' ] = "test@example.com (First Last)"; or $postData [ 'subscribees' ] = "one@example.com (Just One)\ntwo@example.com (Just Two)"; Unsubscribe works the same way.

[code] $postData[ ‘unsubscribees_upload’ ] = “@”.$file;
$postData[ ‘adminpw’ ] = $pass;
$postData[ ‘send_unsub_ack_to_this_batch’ ] = 0;
$postData[ ‘send_unsub_notifications_to_list_owner’ ] = 0;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,“http://lists.”.$host."/admin.cgi/".$listname."-".$host."/members/remove");
curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);

curl_exec ($curl);
curl_close ($curl);
[/code]and to simulate the text box instead of the file upload:

$postData [ 'unsubscribees' ] = "one@example.com\ntwo@example.com"; Usual warnings: Screenscraping is subject to change in the admin interface. Be careful about how the admin password variable is set/protected.