From 90c5b62f953e2edcf538645e6c57999a5aed434f Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 27 Jan 2022 11:59:56 +1300 Subject: [PATCH] dev/core#2866 Ignore preferred mail format when sending message --- CRM/Core/BAO/MessageTemplate.php | 15 ---------- .../CRM/Core/BAO/MessageTemplateTest.php | 30 ------------------- 2 files changed, 45 deletions(-) diff --git a/CRM/Core/BAO/MessageTemplate.php b/CRM/Core/BAO/MessageTemplate.php index ab0f8e7b6e..2eb23ddb1a 100644 --- a/CRM/Core/BAO/MessageTemplate.php +++ b/CRM/Core/BAO/MessageTemplate.php @@ -15,7 +15,6 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ -use Civi\Api4\Email; use Civi\Api4\MessageTemplate; use Civi\WorkflowMessage\WorkflowMessage; @@ -397,20 +396,6 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen // send the template, honouring the target user’s preferences (if any) $sent = FALSE; if (!empty($params['toEmail'])) { - // @todo - consider whether we really should be loading - // this based on 'the first email in the db that matches'. - // when we likely have the contact id. OTOH people probably barely - // use preferredMailFormat these days - the good fight against html - // emails was lost a decade ago... - $preferredMailFormatArray = Email::get(FALSE)->addWhere('email', '=', $params['toEmail'])->addSelect('contact_id.preferred_mail_format')->execute()->first(); - $preferredMailFormat = $preferredMailFormatArray['contact_id.preferred_mail_format'] ?? 'Both'; - - if ($preferredMailFormat === 'HTML') { - $params['text'] = NULL; - } - if ($preferredMailFormat === 'Text') { - $params['html'] = NULL; - } $config = CRM_Core_Config::singleton(); if ($isAttachPDF) { diff --git a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php index a6ffa82a0f..0f44b3a9aa 100644 --- a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php +++ b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php @@ -45,36 +45,6 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase { $this->assertStringContainsString('

Hello testRenderTemplate Abba Baab!

', $rendered['html']); } - /** - * Check detection of contact's preferred mail. - * - * - ie if text then no html output is sent. - * - * @throws \API_Exception - * @throws \CRM_Core_Exception - */ - public function testSendTemplateNoHtml(): void { - $contactId = $this->individualCreate([ - 'preferred_mail_format' => 'Text', - 'first_name' => 'Mary', - 'email' => 'mary_anderson@civicrm.org', - ]); - $mut = new CiviMailUtils($this, TRUE); - CRM_Core_BAO_MessageTemplate::sendTemplate( - [ - 'contactId' => $contactId, - 'from' => 'admin@example.com', - 'toEmail' => 'mary_anderson@civicrm.org', - 'messageTemplate' => [ - 'msg_subject' => 'My subject', - 'msg_text' => 'My text', - 'msg_html' => 'My html', - ], - ] - ); - $mut->checkMailLog(['My text', 'My subject'], ['My html']); - } - /** * @throws \API_Exception * @throws \CRM_Core_Exception -- 2.25.1