, Copyright 2006. License http://www.gnu.org/licenses/gpl.html GNU General Public License SDV($ZAPmodule[mail], " emailto emaillist emailnews "); SDV($ZAPlistgroup, "MailList"); function ZAPmail($field, $value) { global $WorkDir, $WikiDir, $pagename, $MessagesFmt, $m, $ZAPprofiles, $ZAPlistgroup, $lock; if($lock != "nolock") { if ($value != "") { if ((!isset($_POST[emailfrom])) || ($_POST[emailfrom] == "")) ZAPwarning("No return address entered. Email not sent."); if ((!isset($_POST[emailsubject])) || ($_POST[emailsubject] == "")) ZAPwarning("No email subject entered. Email not sent."); $_POST[email] = "{email}"; $emailbody = ZAPtemplate("email"); if ($emailbody == false) ZAPwarning("Email template not found. Email not sent."); if ($field == "emailnews") { if (!PageExists("$ZAPlistgroup.$value")) ZAPwarning("Mailing list $value not found. Mail not sent."); if (!isset($_POST[emailthrottle])) $_POST[emailthrottle] = "600"; if (!isset($_POST[emailbatch])) $_POST[emailbatch] = "25"; $id = time(); $maillist = ReadPage("$ZAPlistgroup.$value"); $maillist[text] .= "\n\n^$_POST[emailbatch]^$_POST[emailthrottle]^$id^$_POST[emailfrom]^$_POST[emailsubject]^\n\n$emailbody"; $t = bcadd(time(), $_POST[emailthrottle]); ZAPsavepage("Temp-$ZAPlistgroup.$t", $maillist[text], ""); $m .= "Message sent to queue. "; return; } if ($field == "emailto") $value = str_replace("self", $_POST[emailfrom], $value); $e = explode(",", $value); foreach($e as $to) { if ($field == "emaillist") $to = ZAPgetdata("Email","$ZAPprofiles.$to"); if (! ereg("^.+@.+\..+$", $to)) $m .= "Invalid email address: $to. "; else { $mergedbody = str_replace("{email}", $to, $emailbody); mail($to, $_POST[emailsubject], $mergedbody, "From: $_POST[emailfrom]"); $m .= "Mail successfully sent to $to. "; } } } } return; } Markup('zapnews', '>{$var}', '/\(:zapnews(.*?):\)/ei', "ZAPnews('$1')"); function ZAPnews($x) { global $WorkDir, $WikiDir, $ZAPlistgroup; if(is_dir("lock")) return; @ignore_user_abort(true); mkdir("lock"); $g = "Temp-$ZAPlistgroup"; $t = time(); foreach(ListPages("/^$g\\.\\d/") as $p) { $pn = substr($p, strpos($p, ".") + 1); if($pn < $t) { $oldqueue = ReadPage($p); $newqueue = $oldqueue; $n = explode("^", $oldqueue[text]); $list = substr($n[0], 3, -5); $to = explode("\n", $list); $batch = $n[1]; $throttle = $n[2]; $id = $n[3]; $from = $n[4]; $subject = $n[5]; $body = substr(str_replace("%0a", "\n", $n[6]), 2); $count = 0; $oldlog = ReadPage("$g.LOG-$id"); $newlog = $oldlog; if ($newlog[text] == "") $newlog[text] = "Subject: $subject\n\nSent: " . strftime("%c", $id) . "\n\n"; while($count < $batch) { if (! isset($to[$count])) break; $mergedbody = str_replace("{email}", "$to[$count]", $body); mail($to[$count], $subject, $mergedbody, "From: $from"); $newlog[text] .= "SENT " . substr($to[$count], 0, strpos($to[$count], "@")) . "@***** at " . strftime("%c", time()) . " \\\\\n"; $count = $count + 1; } if (count($to) > $batch) { $to = array_slice($to, $batch); $n[0] = "[@\n" . implode("\n", $to) . "\n@]\n\n"; $newqueue[text] = implode("^", $n); $pp = bcadd($pn, $throttle); UpdatePage("$g.$pp", $oldqueue, $newqueue); } else $newlog[text] .= "\n\nSending Complete!"; UpdatePage("$g.LOG-$id", $oldlog, $newlog); $WikiDir->delete("$p"); } } rmdir("lock"); return $m; }