--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * The logging-mailer is a utility to wrap an existing PEAR Mail class
+ * and apply extra logging functionality.
+ *
+ * It replaces a set of patches which had been previously applied directly
+ * to a few specific PEAR Mail classes.
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+class CRM_Utils_Mail_LoggingMailer extends Mail {
+
+ /**
+ * @var Mail
+ */
+ protected $delegate;
+
+ /**
+ * @param Mail $delegate
+ */
+ public function __construct($delegate) {
+ $this->delegate = $delegate;
+ }
+
+ public function send($recipients, $headers, $body) {
+ if (defined('CIVICRM_MAIL_LOG')) {
+ CRM_Utils_Mail::logger($recipients, $headers, $body);
+ if (!defined('CIVICRM_MAIL_LOG_AND_SEND') && !defined('CIVICRM_MAIL_LOG_AND SEND')) {
+ return TRUE;
+ }
+ }
+
+ if (!is_array($headers)) {
+ return PEAR::raiseError('$headers must be an array');
+ }
+
+ return $this->delegate->send($recipients, $headers, $body);
+ }
+
+ public function &__get($name) {
+ return $this->delegate->{$name};
+ }
+
+ public function __set($name, $value) {
+ return $this->delegate->{$name} = $value;
+ }
+
+ public function __isset($name) {
+ return isset($this->delegate->{$name});
+ }
+
+ public function __unset($name) {
+ unset($this->delegate->{$name});
+ }
+
+}
index ee1ecef..ae6e2e8 100644
--- a/Mail/mail.php
+++ b/Mail/mail.php
-@@ -114,6 +114,14 @@ class Mail_mail extends Mail {
- */
- public function send($recipients, $headers, $body)
- {
-+ if (defined('CIVICRM_MAIL_LOG')) {
-+ CRM_Utils_Mail::logger($recipients, $headers, $body);
-+ // Note: "CIVICRM_MAIL_LOG_AND SEND" (space not underscore) was a typo that existed for some years, so kept here for compatibility, but it should not be used.
-+ if (!defined('CIVICRM_MAIL_LOG_AND_SEND') && !defined('CIVICRM_MAIL_LOG_AND SEND')) {
-+ return true;
-+ }
-+ }
-+
- if (!is_array($headers)) {
- return PEAR::raiseError('$headers must be an array');
- }
@@ -145,7 +153,12 @@ class Mail_mail extends Mail {
if (is_a($headerElements, 'PEAR_Error')) {
return $headerElements;
// We only use mail()'s optional fifth parameter if the additional
// parameters have been provided and we're not running in safe mode.
-diff --git a/Mail/sendmail.php b/Mail/sendmail.php
-index 7e8f804..e0300a0 100644
---- a/Mail/sendmail.php
-+++ b/Mail/sendmail.php
-@@ -132,6 +132,14 @@ class Mail_sendmail extends Mail {
- */
- public function send($recipients, $headers, $body)
- {
-+ if (defined('CIVICRM_MAIL_LOG')) {
-+ CRM_Utils_Mail::logger($recipients, $headers, $body);
-+ // Note: "CIVICRM_MAIL_LOG_AND SEND" (space not underscore) was a typo that existed for some years, so kept here for compatibility, but it should not be used.
-+ if (!defined('CIVICRM_MAIL_LOG_AND_SEND') && !defined('CIVICRM_MAIL_LOG_AND SEND')) {
-+ return true;
-+ }
-+ }
-+
- if (!is_array($headers)) {
- return PEAR::raiseError('$headers must be an array');
- }
-diff --git a/Mail/smtp.php b/Mail/smtp.php
-index 5e698fe..5f057e2 100644
---- a/Mail/smtp.php
-+++ b/Mail/smtp.php
-@@ -255,6 +255,14 @@ class Mail_smtp extends Mail {
- */
- public function send($recipients, $headers, $body)
- {
-+ if (defined('CIVICRM_MAIL_LOG')) {
-+ CRM_Utils_Mail::logger($recipients, $headers, $body);
-+ // Note: "CIVICRM_MAIL_LOG_AND SEND" (space not underscore) was a typo that existed for some years, so kept here for compatibility, but it should not be used.
-+ if (!defined('CIVICRM_MAIL_LOG_AND_SEND') && !defined('CIVICRM_MAIL_LOG_AND SEND')) {
-+ return true;
-+ }
-+ }
-+
- $result = $this->send_or_fail($recipients, $headers, $body);
-
- /* If persistent connections are disabled, destroy our SMTP object. */