As some of you are aware, I've been integrating Mailman with PHP to integrate it into Joomla!. I had a version that did it using command line options, but that didn't work for a lot of people, so I did some work to figure out how to do it via the file_get_contents function in PHP. I have pulled it off and my Joomla! component is just about ready to go out to the community, but I thought I'd send a non-Joomla! version to show how to use PHP to administer Mailman.
Attached is a demo script that will demonstrate how I did this. Hopefully you should be able to look at the script and its output and learn how to do what YOU need to do. To use the script, put it in the doc directory of your web server, calling it mailman.php. Then edit it and change the value of $domain to your domain, change $email to some valid email address, and change $adminpw to the admin password of your site. Leave diag at 1 to see the most information. Set it to 0 to turn off most of it, and set it to 2 for debugging. Then run yourdomain/mailman.php and watch the show. 1. List all the lists on your server 2. List all the lists that the email address you supplied is subscribe to, and how they're subscribed (digest or regular) 3. Do #2 again in a different way 4. Unsubscribe the email address you gave from all lists 5. Subscribe the email address you gave to all lists 6. Change the subscription to digest mode on all lists Here 'tis: -------cut and paste----- <? #List all lists $domain="domain.com"; $email="[EMAIL PROTECTED]"; $adminpw="password"; $diag=1; #Build an array of all lists and their descriptions print "<html><body>\n" ; #Build the command to list all lists $adminurl="http://" . $domain . "/mailman/admin"; if ( "$diag" == 1 ) {print "<br><b>adminurl=</b>$adminurl\n" ;} #Run the command $content=file_get_contents("$adminurl","FALSE"); #Split the output into an array that we can loop through $array = preg_split('/\n/',$content); #For each line in the output foreach ($array as $element) { #As soon as we see the first line of the list of lists, say so if ( preg_match("/a href=.*strong.*strong/", "$element") ) { $table="on";} if ( "$diag" == 2 ) {print "<br>$table:$element";} if ( "$table" == "on" ) { #We're inside the table if ( preg_match("/a href=.*strong.*strong/", "$element") ) { #If it's the line with the listname... if ( "$diag" == 2 ) {print "<br>list:$element\n";} $listname = preg_replace("/.*href=./","","$element") ; $listname = preg_replace("/.>.*/","","$listname") ; $listname = preg_replace("/.*\//","","$listname") ; if ( "$diag" == 2 ) {print "<br>listname:$listname\n";} } else { if ( "$diag" == 2 ) {print "<br>desc:$element\n";} if ( preg_match("/<td>.*<.td>/", "$element") ) { #If it's the line with the description $description = preg_replace("/.*<td>/","","$element") ; $description = preg_replace("/<.td>.*/","","$description") ; $description = preg_replace("/<\/*em>/","","$description") ; $lists["$listname"] = "$description"; if ( "$diag" == 2 ) {print "<br>description:$description\n";} } } #When the table ends, there's no more work to do if ( preg_match("/<.table>/", "$element") ) { $table="off";} } } if ( "$diag" == 1 ) {print "<table border=1>\n";} if ( "$diag" == 1 ) {print "<tr><td>Listname</td><td>Description</td></tr>\n";} #Loop through the associative array of lists and descriptions and print them out foreach ($lists as $listname => $desc) { if ( "$diag" == 1 ) {print "<tr>\n";} if ( "$diag" == 1 ) {print "<td>$listname</td>\n";} if ( "$diag" == 1 ) {print "<td>$desc</td>\n";} if ( "$diag" == 1 ) {print "</tr>\n";} } if ( "$diag" == 1 ) {print "</table>\n";} if ( "$diag" == 1 ) {print "<table border=1>\n";} if ( "$diag" == 1 ) {print "<tr><td>Listname</td><td>Regular/Digest</td></tr>\n" ;} #For each list foreach ($lists as $listname => $desc) { #Find email in list #Build a command to list if a member is in a given list $findemailurl="http://" . $domain . "/mailman/admin/" . $listname . "/members?findmember=" . $email . "&setmemberopts_btn&adminpw=" . "$adminpw"; if ( "$diag" == 1 ) {print "<tr><td colspan=\"2\"><b>FindMemberUrl=</b>$findemailurl</td></tr>\n" ;} #Run the command $content=file_get_contents("$findemailurl","FALSE"); #The line we're looking for looks like this: #<td><center><INPUT name="[EMAIL PROTECTED]" type="CHECKBOX" value="on" CHECKED ></center></td> $digestline="INPUT name=." . $email . "_digest."; $ondigestline="INPUT name=." . $email . "_digest. type=.CHECKBOX. value=.on."; if ( "$diag" == 2 ) {print "<tr><td colspan=\"2\">$digestline</td></tr>\n" ;} if ( "$diag" == 2 ) {print "<tr><td colspan=\"2\">$ondigestline</td></tr>\n" ;} #if we found the member, then they'll be a line that has this string in it. if ( preg_match("/$digestline/", "$content") ) { #He's subscribed. Is he subscribe in digest format? if ( preg_match("/$ondigestline/", "$content") ) { if ( "$diag" == 1 ) {print "<tr><td>$listname</td><td>Digest</td></tr>\n";} #Add the user listname and digest to the email_lists array $email_lists["$listname"] = "digest"; } else { if ( "$diag" == 1 ) {print "<tr><td>$listname</td><td>Regular</td></tr>\n";} #Add the user listname and regular to the email_lists array $email_lists["$listname"] = "regular"; } } } if ( "$diag" == 1 ) {print "</table>\n";} if ( "$diag" == 1 ) {print "<table border=1>\n";} if ( "$diag" == 1 ) {print "<tr><td colspan=\"2\"><b>Same info again just to show you how to use the array.</b></td></tr>\n" ;} #This just demonstrates how to use the array that we created above foreach ($email_lists as $listy => $digesty) { if ( "$diag" == 1 ) {print "<tr>\n";} if ( "$diag" == 1 ) {print "<td>$listy</td>\n";} if ( "$diag" == 1 ) {print "<td>$digesty</td>\n";} if ( "$diag" == 1 ) {print "</tr>\n";} } if ( "$diag" == 1 ) {print "</table>\n";} if ( "$diag" == 1 ) {print "<table border=1>\n";} #Unsub email from all lists foreach ($lists as $listname => $desc) { #Build the command $unsuburl = "http://" . $domain . "/mailman/admin/" . $listname . "/members/remove?send_unsub_ack_to_this_batch=0&send_unsub_notifications _to_list_owner=0&unsubscribees_upload=" . $email . "&adminpw=" . $adminpw; if ( "$diag" == 1 ) {print "<tr><td><b>UnsubscribeUrl:</b>$unsuburl</td></tr>\n";} #Run the command $content=file_get_contents("$unsuburl","FALSE"); } if ( "$diag" == 1 ) {print "</table>\n";} #Sub email to all lists if ( "$diag" == 1 ) {print "<table border=1>\n";} foreach ($lists as $listname => $desc) { #Build the command $subscribeurl="http://" . $domain . "/mailman/admin/" . $listname . "/members/add?subscribe_or_invite=0&send_welcome_msg_to_this_batch=0¬ ification_to_list_owner=0&subscribees_upload=" . $email . "&adminpw=" . $adminpw ; if ( "$diag" == 1 ) {print "<tr><td><b>SubscribeUrl</b>:$subscribeurl</td></tr>\n";} #Run the command $content=file_get_contents("$subscribeurl","FALSE"); } if ( "$diag" == 1 ) {print "</table>\n";} #Set digest mode on for all lists if ( "$diag" == 1 ) {print "<table border=1>\n";} foreach ($lists as $listname => $desc) { #Build the command $turnondigesturl="http://" . $domain . "/mailman/admin/" . $listname . "/members?user=" . $email . "&" . $email . "_digest=1&setmemberopts_btn&adminpw=" . "$adminpw"; if ( "$diag" == 1 ) {print "<tr><td><b>DigestOnUrl:</b>$turnondigesturl</td></tr>\n";} #Run the command $content=file_get_contents("$turnondigesturl","FALSE"); } if ( "$diag" == 1 ) {print "</table>\n";} ?> --- W. Curtis Preston Author of O'Reilly's Backup & Recovery and Using SANs and NAS VP Data Protection GlassHouse Technologies ------------------------------------------------------ Mailman-Users mailing list Mailman-Users@python.org http://mail.python.org/mailman/listinfo/mailman-users Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/ Unsubscribe: http://mail.python.org/mailman/options/mailman-users/archive%40jab.org Security Policy: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp