diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index d76a63516754..e209ffd6f554 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -892,9 +892,9 @@ private function getHeaderFooter() { * Array of message headers to update, in-out. * @param string $prefix * Prefix for the message ID, use same prefixes as verp. - * wherever possible - * @param string $job_id - * Job ID component of the generated message ID. + * wherever possible + * @param null $theVoid + * Stare into the abyss. * @param string $event_queue_id * Event Queue ID component of the generated message ID. * @param string $hash @@ -902,7 +902,7 @@ private function getHeaderFooter() { * * @return void */ - public static function addMessageIdHeader(&$headers, $prefix, $job_id, $event_queue_id, $hash) { + public static function addMessageIdHeader(&$headers, $prefix, $theVoid, $event_queue_id, $hash): void { $config = CRM_Core_Config::singleton(); $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); diff --git a/CRM/Mailing/Event/BAO/MailingEventReply.php b/CRM/Mailing/Event/BAO/MailingEventReply.php index a21165f725f9..4961cd30196e 100644 --- a/CRM/Mailing/Event/BAO/MailingEventReply.php +++ b/CRM/Mailing/Event/BAO/MailingEventReply.php @@ -15,6 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Token\TokenProcessor; + require_once 'Mail/mime.php'; /** @@ -194,11 +196,10 @@ public static function send($queue_id, &$mailing, &$bodyTxt, $replyto, &$bodyHTM * @param string $replyto * Optional reply-to from the reply. */ - private static function autoRespond(&$mailing, $queue_id, $replyto) { + private static function autoRespond($mailing, $queue_id, $replyto) { $eq = CRM_Core_DAO::executeQuery( 'SELECT email.email as email, - queue.job_id as job_id, queue.hash as hash FROM civicrm_contact contact INNER JOIN civicrm_mailing_event_queue queue ON queue.contact_id = contact.id @@ -213,8 +214,7 @@ private static function autoRespond(&$mailing, $queue_id, $replyto) { $component->id = $mailing->reply_id; $component->find(TRUE); - $domain = CRM_Core_BAO_Domain::getDomain(); - list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); + [$domainEmailName, $domainEmailAddress] = CRM_Core_BAO_Domain::getNameAndEmail(); $params = [ 'subject' => $component->subject, @@ -224,28 +224,25 @@ private static function autoRespond(&$mailing, $queue_id, $replyto) { 'returnPath' => CRM_Core_BAO_Domain::getNoReplyEmailAddress(), ]; - // TODO: do we need reply tokens? $html = $component->body_html; - if ($component->body_text) { - $text = $component->body_text; - } - else { - $text = CRM_Utils_String::htmlToText($component->body_html); + $text = $component->body_text ?: ''; + + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ + 'controller' => __CLASS__, + 'smarty' => FALSE, + 'schema' => ['mailingId'], + ]); + + $tokenProcessor->addMessage('body_html', $html, 'text/html'); + $tokenProcessor->addMessage('body_text', $text, 'text/plain'); + $tokenProcessor->addRow(['mailingId' => $mailing->id]); + $tokenProcessor->evaluate(); + $params['html'] = $tokenProcessor->getRow(0)->render('body_html'); + if ($text) { + $params['text'] = $tokenProcessor->getRow(0)->render('body_text'); } - $bao = new CRM_Mailing_BAO_Mailing(); - $bao->body_text = $text; - $bao->body_html = $html; - $tokens = $bao->getTokens(); - - $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); - $html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, NULL, $tokens['html']); - $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']); - $text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, NULL, $tokens['text']); - $params['html'] = $html; - $params['text'] = $text; - - CRM_Mailing_BAO_Mailing::addMessageIdHeader($params, 'a', $eq->job_id, $queue_id, $eq->hash); + CRM_Mailing_BAO_Mailing::addMessageIdHeader($params, 'a', NULL, $queue_id, $eq->hash); if (CRM_Core_BAO_MailSettings::includeMessageId()) { $params['messageId'] = $params['Message-ID']; } diff --git a/tests/phpunit/CRM/Mailing/MailingSystemTest.php b/tests/phpunit/CRM/Mailing/MailingSystemTest.php index 51f4c146d2ed..456c30f4f2b1 100644 --- a/tests/phpunit/CRM/Mailing/MailingSystemTest.php +++ b/tests/phpunit/CRM/Mailing/MailingSystemTest.php @@ -154,7 +154,7 @@ public function testMailingActivityCreate(): void { } /** - * @throws \CRM_Core_Exception + * Test the auto-respond email, including token presence. */ public function testMailingReplyAutoRespond(): void { // Because our parent class marks the _groupID as private, we can't use that :-(