"); } function sendGoodbyeMessage($address, $listPrefix, $listDescription, $listAddress, $adminAddress) { $body = "You have chosen to unsubscribe from the $listPrefix list. Sorry to see you leave.\r\n\r\n"; $body.= "If you decide to enter the list again, send a message with subject 'SUBSCRIBE' (without quotes) to $listAddress.\r\n"; $body.= "mailto:$listAddress?subject=SUBSCRIBE\r\n"; mail($address, "Subscription cancelled: $listPrefix mailing list", wordwrap($body), "From: $listPrefix administrator <$adminAddress>"); } function sendInvitationMessage($address, $listPrefix, $listDescription, $listAddress, $adminAddress) { $body = "You have sent an email to a private mailing list. Subscription is required to post messages on this list.\r\n\r\n"; $body.= "List description:\r\n"; $body.= "$listDescription\r\n\r\n"; $body.= "If you would like to enter the list, send a message with subject 'SUBSCRIBE' (without quotes) to $listAddress.\r\n"; $body.= "mailto:$listAddress?subject=SUBSCRIBE\r\n"; mail($address, "Want to join the $listPrefix mailing list?", wordwrap($body), "From: $listPrefix administrator <$adminAddress>"); } function sendApprovalMessages($address, $listPrefix, $listDescription, $listAddress, $adminAddress) { $body = "Your admission request for the $listPrefix has been sent to the list administrator ($adminAddress). You will be informed as soon as the administrator has decided over your request.\r\n\r\n"; mail($address, "Subscription request for $listPrefix", wordwrap($body), "From: $listPrefix administrator <$adminAddress>"); $body = "$address has asked for admission to the $listPrefix mailing list.\r\n\r\n"; $body.= "To grant the request, send a message with subject 'APPROVE $address' (without quotes) to $listAddress.\r\n"; $body.= "mailto:$listAddress?subject=APPROVE%20$address\r\n"; mail($adminAddress, "Subscription request for $listPrefix", wordwrap($body), "From: $listPrefix administrator <$adminAddress>"); } // do NOT change anything from here on (except if you know what you're doing) mysql_connect($dbServer, $dbUser, $dbPassword); mysql_select_db($dbName); $lists = mysql_query("SELECT * FROM lists"); while ($list = mysql_fetch_object($lists)) { echo "Processing list '$list->prefix'...
"; $user = $list->account; $password = $list->password; $apop = 0; $pop3_connection = new pop3_class; $pop3_connection->hostname = $list->server; if(($error = $pop3_connection->Open())=="") { if(($error = $pop3_connection->Login($user,$password,$apop))=="") { if(($error = $pop3_connection->Statistics(&$messages,&$size))=="") { $result = $pop3_connection->ListMessages("",0); if(getType($result)=="array") { for(Reset($result); $msgNumberRetrieveMessage(Key($result), &$header, &$body, -1))=="") { $messageBody = join($body,"\n"); $messageHeader = ""; for ($i=0; $i]*)>/", $messageFrom, $matches); $senderAllowed = mysql_query("SELECT COUNT(*) as allowed FROM subscribers WHERE address='".$matches[1]."' AND listID=$list->ID AND approved=1"); $sender = mysql_fetch_object($senderAllowed); $senderIsInList = $sender->allowed; if (strtoupper($messageSubject == "UNSUBSCRIBE")) { echo "  performing unsubscribe for ".$matches[1]; if ($senderIsInList) { @mysql_query("DELETE FROM subscribers WHERE address='".$matches[1]."' AND listID=".$list->ID); echo " - sending goodbye message"; sendGoodbyeMessage($matches[1], $list->prefix, $list->description, $list->address, $list->adminAddress); } else echo " - cancelled: not in list"; echo "
"; $pop3_connection->DeleteMessage(Key($result)); continue; } if (strtoupper($messageSubject == "SUBSCRIBE")) { echo "  performing subscribe for ".$matches[1]; if (!$senderIsInList) { if ($list->approveMembers == 0) { $senderApproved = 1; } else { $senderApproved = 0; } mysql_query("INSERT INTO subscribers SET address='".$matches[1]."', listID=".$list->ID.", approved=$senderApproved"); if ($senderApproved) { echo " - sending welcome message"; sendWelcomeMessage($matches[1], $list->prefix, $list->description, $list->address, $list->adminAddress); } else { echo " - sending approval messages"; sendApprovalMessages($matches[1], $list->prefix, $list->description, $list->address, $list->adminAddress); } } else echo " - cancelled: already in list"; echo "
"; $pop3_connection->DeleteMessage(Key($result)); continue; } if (strtoupper(substr($messageSubject,0,7)) == "APPROVE") { if ($matches[1]==$list->adminAddress) { $requester = substr($messageSubject,8); echo "  performing approval for ".$requester.; if (!$senderIsInList) { mysql_query("UPDATE subscribers SET approved=1 WHERE address='$requester'"); echo " - sending welcome message"; sendWelcomeMessage($requester, $list->prefix, $list->description, $list->address, $list->adminAddress); } else echo " - cancelled: already in list"; echo "
"; $pop3_connection->DeleteMessage(Key($result)); } continue; } $messageSubject = "[".$list->prefix."] ".$messageSubject; if ($list->membersOnly) { if (!$senderIsInList) { echo "  skipping '$messageSubject': Sender not in list ($matches[1])"; if ($list->inviteMembers) { echo " - sending invitation message"; sendInvitationMessage($matches[1], $list->prefix, $list->description, $list->address, $list->adminAddress); } echo "
"; $pop3_connection->DeleteMessage(Key($result)); continue; // next message } } if ($list->moderated) { } $subscribers = mysql_query("SELECT address FROM subscribers WHERE listID='".$list->ID."' AND approved=1"); echo "  sending '$messageSubject'...
"; while ($subscriber = mysql_fetch_object($subscribers)) { mail($subscriber->address, $messageSubject, $messageBody, $messageHeader); $pop3_connection->DeleteMessage(Key($result)); } } } } else $error=$result; } } $pop3_connection->Close(); } if($error!="") echo "

Error: ",HtmlSpecialChars($error),"

"; } ?>