[pmwiki-devel] ZAP news/maillist recipe

The Editor editor at fast.st
Mon Oct 30 05:23:04 CST 2006


I pulled together a quick first draft of the maillist recipe I'm
working on.  It should be able to work with other recipes, but ZAP
will be modified to have built in hooks, and handle all the
subscribes, unsubscribes, etc.

Lists will be stored in simple wiki pages in a protected directory (by
default MailLists).  Throttling is done via sleep( ).  No cron is
needed.

In ZAP, a form field called emaillist will kick off the mail list
function, then return right to the browser, so the sender can keep
moving along.  At least, hope this will work... Though it may be
designed to run in a page--not be called by a function.  Anyone know?

Let me know if anyone has any further suggestions.  I just threw this
together and haven't tested it yet.  But thought I'd open it to input
before I get too set into one way of doing it.

Cheers,
Caveman

<?php

## This function is sent all needed email parameters from a zap form
containing: emaillist, emailfrom, emailsubject, emailbody.  When
called from emailer function, ZAP does all error checking, including
checks to see if $ZAPnews is set, if list exists, etc.  Can get opt.
alerts every x emails (that things are moving along) and can
throttling (by sleeping y seconds between emails)--both configurable
in a zapform.

SDV($ZAPnews, "true"); // used in ZAP emailer to check if zap news available
SDV($ZAPlistgroup, "MailList"); // default group for all pmwiki MailLists

function ZAPnews($list, $from, $subject, $message, $alerts=0, $throttle=20) {
     global $ZAPlistgroup, $ZAPadmin;

     ob_implicit_flush(TRUE);
     @ignore_user_abort(true);
     sendGIF();
     ob_implicit_flush(FALSE);
     ob_start();

     $c = 0;
     if(PageExists("$ZAPlistgroup.$list")) {
          $page = ReadPage($xx);
          $contents = substr($page['text'], 3, -3);
          $r = explode("\n", $contents);
          foreach ($r as $recipient) {
               $c = $c + 1;
               if ($c == 1) $begin = substr($r, 0, strpos($r, "@")) . "@*****";
               $mergedbody = str_replace("{email}", $to, $body);
               mail($r, $subject, $mergedbody, "From: $from");
               if (($c == $alerts) && (isset($ZAPadmin[$list]))) {
                    $end = substr($r, 0, strpos($r, "@")) . "@*****";
                    $alertsubject = "ZAPnews alert";
                    $alerttime = strftime(%c, time());
                    $alertbody = "$subject sent, from $begin to $end
by $alerttime";
                    mail($ZAPadmin[$list], $alertsubject, $mergedbody,
"From: $from");
                    $c = 0;
                    }
               sleep($throttle);
               }

     ob_end_clean()
     }

function sendGIF() {
    $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
    header('Content-Type: image/gif');
    header('Content-Length: '.strlen($img));
    header('Connection: Close');
    print $img;
}



More information about the pmwiki-devel mailing list