Skip to content

Commit

Permalink
Merge pull request civicrm#29908 from eileenmcnaughton/reply
Browse files Browse the repository at this point in the history
Fix auto-respond to use token processor.
  • Loading branch information
eileenmcnaughton authored Jun 6, 2024
2 parents bb01648 + 4ba79ff commit d98c1e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
8 changes: 4 additions & 4 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,17 +892,17 @@ 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
* Hash component of the generated message ID.
*
* @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();
Expand Down
43 changes: 20 additions & 23 deletions CRM/Mailing/Event/BAO/MailingEventReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Civi\Token\TokenProcessor;

require_once 'Mail/mime.php';

/**
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Mailing/MailingSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 :-(
Expand Down

0 comments on commit d98c1e4

Please sign in to comment.