123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php if (!defined('PmWiki')) exit();
- SDV($MailPostsDelay,0);
- SDV($MailPostsSquelch,7200);
- SDV($MailPostsFile,"$WorkDir/.mailposts");
- SDV($MailPostsMessage,"Recent wiki posts:\n"
- ." ($ScriptUrl/$SiteGroup/AllRecentChanges)\n\n\$MailPostsList\n");
- SDV($MailPostsSubject,"$WikiTitle recent wiki posts");
- SDV($MailPostsFunction,"mail");
- SDV($MailPostsTimeFmt,$TimeFmt);
- SDV($MailPostsItemFmt,' * $FullName . . . $PostTime by $Author');
- SDV($MailPostsHeaders,'');
- if (@$MailPostsFrom)
- $MailPostsHeaders = "From: $MailPostsFrom\r\n$MailPostsHeaders";
- array_push($EditFunctions,'MailPosts');
- function MailPosts($pagename, &$page, &$new) {
- global $IsPagePosted, $MailPostsFile, $MailPostsTimeFmt, $Now,
- $MailPostsItemFmt, $PostTime;
- if (!$IsPagePosted) return;
- $fp = @fopen($MailPostsFile, "a");
- if ($fp) {
- $PostTime = strftime($MailPostsTimeFmt, $Now);
- fputs($fp,
- urlencode(FmtPageName("$Now $MailPostsItemFmt", $pagename))."\n");
- fclose($fp);
- }
- }
- if (@$MailPostsTo == "") return;
- $fp = @fopen($MailPostsFile, "r");
- if (!$fp) return;
- $oldestpost = $Now+1; $mailpost=array();
- while (!feof($fp)) {
- $x = urldecode(rtrim(fgets($fp, 1024)));
- @(list($t,$p) = explode(' ', $x, 2));
- if (!$t) continue;
- if ($p=='#lastmailed') {
- if ($t > $Now-$MailPostsSquelch) { fclose($fp); return; }
- continue;
- }
- Lock(2);
- array_push($mailpost, $p."\n");
- if ($t<$oldestpost) $oldestpost=$t;
- }
- fclose($fp);
- if ($oldestpost > $Now-$MailPostsDelay) { Lock(0); return; }
- $MailPostsFunction($MailPostsTo,$MailPostsSubject,
- str_replace('$MailPostsList',join('',$mailpost),$MailPostsMessage),
- $MailPostsHeaders);
- $fp = @fopen($MailPostsFile,"w");
- if ($fp) { fputs($fp,"$Now #lastmailed\n"); fclose($fp); }
- Lock(0);
- function MailPostsSendmail($to,$subject,$msg,$headers) {
- if (preg_match('/From: .*?([-.\w]+@[-.\w]+)/',$headers,$match))
- $from="-f".$match[1];
- $mailer = popen("/usr/lib/sendmail -t -i $from","w");
- fwrite($mailer,"To: $to\nSubject: $subject\n$headers\n\n$msg");
- pclose($mailer);
- }
|