OSDN Git Service

Added pkwk_mail_notify(): Send a mail to the administrator
authorhenoheno <henoheno>
Tue, 7 Jun 2005 14:37:47 +0000 (23:37 +0900)
committerhenoheno <henoheno>
Tue, 7 Jun 2005 14:37:47 +0000 (23:37 +0900)
lib/file.php
lib/mail.php
pukiwiki.ini.php

index 3519d2c..146131f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: file.php,v 1.25 2005/04/30 05:21:00 henoheno Exp $
+// $Id: file.php,v 1.26 2005/06/07 14:37:46 henoheno Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -90,9 +90,7 @@ function make_str_rules($str)
 // Output to a file
 function file_write($dir, $page, $str, $notimestamp = FALSE)
 {
-       global $update_exec, $_msg_invalidiwn;
-       global $notify, $notify_diff_only, $notify_to, $notify_subject, $notify_header;
-       global $smtp_server, $smtp_auth;
+       global $update_exec, $_msg_invalidiwn, $notify, $notify_diff_only, $notify_subject;
        global $whatsdeleted, $maxshow_deleted;
 
        if (PKWK_READONLY) return; // Do nothing
@@ -144,17 +142,15 @@ function file_write($dir, $page, $str, $notimestamp = FALSE)
 
        if ($notify && $dir == DIFF_DIR) {
                if ($notify_diff_only) $str = preg_replace('/^[^-+].*\n/m', '', $str);
-               $str .= "\n" .
-                       str_repeat('-', 30) . "\n" .
-                       'URI: ' . get_script_uri() . '?' . rawurlencode($page) . "\n" .
-                       'REMOTE_ADDR: ' . $_SERVER['REMOTE_ADDR'] . "\n";
 
-               $subject = str_replace('$page', $page, $notify_subject);
-               ini_set('SMTP', $smtp_server);
-               mb_language(LANG);
+               $footer['ACTION'] = 'Page update';
+               $footer['PAGE'] = $page;
+               $footer['URI']  = get_script_uri() . '?' . rawurlencode($page);
+               $footer['REMOTE_ADDR'] = TRUE;
+               $footer['USER_AGENT']  = TRUE;
 
-               if ($smtp_auth) pop_before_smtp();
-               mb_send_mail($notify_to, $subject, $str, $notify_header);
+               pkwk_mail_notify($notify_subject, $str, $footer) or
+                       die('pkwk_mail_notify(): Failed');
        }
 }
 
index f970f4a..6f3589b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: mail.php,v 1.4 2005/05/22 03:20:52 henoheno Exp $
+// $Id: mail.php,v 1.5 2005/06/07 14:37:46 henoheno Exp $
 // Copyright (C)
 //   2003-2005 PukiWiki Developers Team
 //   2003      Originally written by upk
@@ -8,6 +8,68 @@
 //
 // E-mail related functions
 
+// Send a mail to the administrator
+function pkwk_mail_notify($subject, $message, $footer = array())
+{
+       global $smtp_server, $smtp_auth, $notify_to, $notify_from, $notify_header;
+       static $_to, $_headers, $_after_pop;
+
+       // Init and lock
+       if (! isset($_to)) {
+               if (! PKWK_OPTIMISE) {
+                       $mail_regex   = '/[^@]+@[^@]{1,}\.[^@]{2,}/';
+                       $header_regex = "/\A(?:\r\n|\r|\n)|\r\n\r\n/";
+                       if (! preg_match($mail_regex, $notify_to))
+                               die('pkwk_mail_notify(): Invalid $notify_to');
+                       if (! preg_match($mail_regex, $notify_from))
+                               die('pkwk_mail_notify(): Invalid $notify_from');
+                       if ($notify_header != '' && preg_match($header_regex, $notify_header))
+                               die('pkwk_mail_notify(): Invalid $notify_header');
+               }
+
+               $_to      = $notify_to;
+               $_headers =
+                       'X-Mailer: PukiWiki/' . S_VERSION .
+                       ' PHP/' . phpversion() . "\r\n" .
+                       'From: ' . $notify_from;
+                       
+               // Additional header(s) by admin
+               if ($notify_header != '') $_headers .= "\r\n" . $notify_header;
+
+               $_after_pop = $smtp_auth;
+       }
+
+       if ($subject == '' || ($message == '' && empty($footer))) return FALSE;
+
+       // Subject:
+       if (isset($footer['PAGE'])) $subject = str_replace('$page', $footer['PAGE'], $subject);
+
+       // Footer
+       if (isset($footer['REMOTE_ADDR'])) $footer['REMOTE_ADDR'] = & $_SERVER['REMOTE_ADDR'];
+       if (isset($footer['USER_AGENT']))
+               $footer['USER_AGENT']  = '(' . UA_PROFILE . ') ' . UA_NAME . '/' . UA_VERS;
+       if (! empty($footer)) {
+               if ($message != '') $_footer = "\n" . str_repeat('-', 30) . "\n";
+               foreach($footer as $key => $value)
+                       $_footer .= $key . ': ' . $value . "\n";
+               $message .= $_footer;
+       }
+
+       // Wait POP/APOP auth completion
+       if ($_after_pop) {
+               $result = pop_before_smtp();
+               if ($result !== TRUE) die($result);
+       }
+
+       ini_set('SMTP', $smtp_server);
+       mb_language(LANG);
+       if ($_headers == '') {
+               return mb_send_mail($_to, $subject, $message);
+       } else {
+               return mb_send_mail($_to, $subject, $message, $_headers);
+       }
+}
+
 // APOP/POP Before SMTP
 function pop_before_smtp($pop_userid = '', $pop_passwd = '',
        $pop_server = 'localhost', $pop_port = 110)
index 1377f9e..c94286c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: pukiwiki.ini.php,v 1.125 2005/06/03 13:56:25 henoheno Exp $
+// $Id: pukiwiki.ini.php,v 1.126 2005/06/07 14:37:47 henoheno Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -347,8 +347,8 @@ $notify_from = 'from@example.com';  // From:
 $notify_subject = '[PukiWiki] $page';
 
 // Mail header
-$notify_header = "From: $notify_from\r\n" .
-       'X-Mailer: PukiWiki/' .  S_VERSION . ' PHP/' . phpversion();
+// NOTE: Multiple items must be divided by "\r\n", not "\n".
+$notify_header = '';
 
 /////////////////////////////////////////////////
 // Mail: POP / APOP Before SMTP