From b88ba1855317605599c79554a6f49381d51868d5 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 27 Apr 2009 12:41:00 -0400 Subject: [PATCH] Update error mailing code to use SwiftMailer. Signed-off-by: Edward Z. Yang --- XHTMLCompiler.php | 4 ++-- common.php | 3 +++ config.default.php | 12 +++++++++++- functions.php | 29 ++++++++++++++++++++++++----- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/XHTMLCompiler.php b/XHTMLCompiler.php index 66db126..6631cfe 100644 --- a/XHTMLCompiler.php +++ b/XHTMLCompiler.php @@ -57,8 +57,8 @@ class XHTMLCompiler protected $configKeys = array('allowed_dirs', 'directory_index', 'indexed_dirs', 'web_path', 'web_domain', 'viewvc_url', - 'svn_headurl_munge', 'debug', 'error_xsl', 'admin_email', - 'error_log', 'error_mute', 'configdoc'); + 'svn_headurl_munge', 'debug', 'error_xsl', 'admin_email', 'from_email', + 'error_log', 'error_mute', 'configdoc', 'smtp_transport'); protected $config = array(); protected $filterManager; diff --git a/common.php b/common.php index 05dd94f..a742a86 100644 --- a/common.php +++ b/common.php @@ -33,6 +33,9 @@ require_once 'XHTMLCompiler/TextFilter.php'; require_once 'XHTMLCompiler/DOMFilter.php'; require_once 'XHTMLCompiler/DOMFilter/NewsBase.php'; +// load external libraries that we *need* +require_once 'external/swiftmailer/lib/swift_required.php'; + set_exception_handler('xhtmlcompiler_exception_handler'); $xc = XHTMLCompiler::getInstance(); // invoke the super-object check_errors(); diff --git a/config.default.php b/config.default.php index 57b42e1..05f250d 100644 --- a/config.default.php +++ b/config.default.php @@ -81,7 +81,11 @@ $error_xsl = 'xhtml-compiler/error.xsl'; // ** Administrator email // Miscellaneous email notices will be mailed to this address in the event of // errors. This will NOT be published -$admin_email = 'admin@' . $web_domain; +$admin_email = 'admin@localhost'; + +// ** From email +// Name that your emails will come from +$from_email = 'daemon@localhost'; // ** Error log // Errors will be logged here. @@ -98,3 +102,9 @@ $error_mute = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mute.txt'; // It is the URL URLs are transformed to. $configdoc = 'http://htmlpurifier.org/live/configdoc/plain.html#%s'; +// ** SwiftMailer smtp transport +// Check out http://swiftmailer.org/docs/sending-quickref for information +// on how to configure this. On properly configured Unix systems, the +// default should "just work". +$smtp_transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t'); + diff --git a/functions.php b/functions.php index b56e03a..0ac01d5 100644 --- a/functions.php +++ b/functions.php @@ -196,11 +196,30 @@ function check_errors() { if (file_exists($error_log) && filesize($error_log) > 0) { if (file_exists($error_mute) && filesize($error_mute) == 0) { $error_text = wordwrap(file_get_contents($error_log), 70, "\r\n"); - mail($xc->getConf('admin_email'), 'Errors in XHTML Compiler', - "Some errors occurred in the log. No further messages\r\n". - "will be sent until the mute file [1] is deleted. The\r\n". - "error log file [2] will be blanked after resolving any\r\n". - "issues.\r\n\r\n[1] $error_mute\r\n[2] $error_log\r\n\r\n$error_text\r\n"); + try { + $message = Swift_Message::newInstance() + ->setSubject('Errors in XHTML Compiler') + ->setTo($xc->getConf('admin_email')) + ->setFrom($xc->getConf('from_email')) + ->setBody(<<getConf('smtp_transport')->send($message); + } catch (Exception $e) { + // uh oh, mail failed, not much we can do about that. + if ($xc->getConf('debug')) { + echo $e . "\n"; + } + } file_put_contents($error_mute, '1'); } elseif (!file_exists($error_mute) && file_exists($error_log)) { $tentative_new_name = "$error_log." . date('Ymd'); -- 2.11.4.GIT