From a659b3411733c9fc5017568684d24d97b19ebcc3 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 29 Dec 2014 15:44:30 +0100 Subject: [PATCH 1/2] Adds 'emailer_send_prepare' and 'emailer_send' hooks Adds relative documentation in doc/Plugins --- doc/Plugins.md | 18 ++++++++++++++++++ include/Emailer.php | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/doc/Plugins.md b/doc/Plugins.md index 2ae942eae..833c1d200 100644 --- a/doc/Plugins.md +++ b/doc/Plugins.md @@ -196,6 +196,24 @@ Current hooks: 'email' => email to look up the avatar for 'url' => the (string) generated URL of the avatar +**'emailer_send_prepare'** - called from Emailer::send() before building the mime message + $b is (array) , params to Emailer::send() + 'fromName' => name of the sender + 'fromEmail' => email fo the sender + 'replyTo' => replyTo address to direct responses + 'toEmail' => destination email address + 'messageSubject' => subject of the message + 'htmlVersion' => html version of the message + 'textVersion' => text only version of the message + 'additionalMailHeader' => additions to the smtp mail header + +**'emailer_send'** - called before calling PHP's mail() + $b is (array) , params to mail() + 'to' + 'subject' + 'body' + 'headers' + A complete list of all hook callbacks with file locations (generated 14-Feb-2012): Please see the source for details of any hooks not documented above. diff --git a/include/Emailer.php b/include/Emailer.php index 535a05428..f61636d95 100644 --- a/include/Emailer.php +++ b/include/Emailer.php @@ -17,6 +17,8 @@ class Emailer { */ static public function send($params) { + call_hooks('emailer_send_prepare', $params); + $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8'); $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8'); @@ -49,11 +51,18 @@ class Emailer { "--" . $mimeBoundary . "--\n"; // message ending // send the message + $hookdata = array( + 'to' => $params['toEmail'], + 'subject' => $messageSubject, + 'body' => $multipartMessageBody, + 'headers' => $messageHeader + ); + call_hooks("emailer_send", $hookdata); $res = mail( - $params['toEmail'], // send to address - $messageSubject, // subject - $multipartMessageBody, // message body - $messageHeader // message headers + $hookdata['to'], // send to address + $hookdata['subject'], // subject + $hookdata['body'], // message body + $hookdata['headers'], // message headers ); logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG); logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG); From 917ce5b411df5bf3f943b93214538c401a6f9e85 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Mon, 29 Dec 2014 16:04:51 +0100 Subject: [PATCH 2/2] Adds optional parameter 'uid' to Emailer::send() that is the user id of the recipient of the mail. Make enotify pass it to Emailer::send() --- include/Emailer.php | 1 + include/enotify.php | 1 + 2 files changed, 2 insertions(+) diff --git a/include/Emailer.php b/include/Emailer.php index f61636d95..3c0f4047c 100644 --- a/include/Emailer.php +++ b/include/Emailer.php @@ -14,6 +14,7 @@ class Emailer { * @param htmlVersion html version of the message * @param textVersion text only version of the message * @param additionalMailHeader additions to the smtp mail header + * @param optional uid user id of the destination user */ static public function send($params) { diff --git a/include/enotify.php b/include/enotify.php index 8b5002cb2..99bc0fd32 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -598,6 +598,7 @@ function notification($params) { // use the Emailer class to send the message return Emailer::send(array( + 'uid' => $params['uid'], 'fromName' => $sender_name, 'fromEmail' => $sender_email, 'replyTo' => $sender_email,