From a718097461522485ece488b56859b26142010b0f Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Sat, 5 Jan 2019 15:46:25 -0500 Subject: [PATCH] core#644 - extract function to return correct mailbox header --- CRM/Contact/Form/Task/EmailCommon.php | 8 +------- CRM/Member/Form/MembershipRenewal.php | 2 +- CRM/Utils/Mail.php | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index 1b0e7f4b47..1dd47fcc5c 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -400,13 +400,7 @@ class CRM_Contact_Form_Task_EmailCommon { // dev/core#357 User Emails are keyed by their id so that the Signature is able to be added // If we have had a contact email used here the value returned from the line above will be the // numerical key where as $from for use in the sendEmail in Activity needs to be of format of "To Name" - if (is_numeric($from)) { - $result = civicrm_api3('Email', 'get', [ - 'id' => $from, - 'return' => ['contact_id.display_name', 'email'], - ]); - $from = '"' . $result['values'][$from]['contact_id.display_name'] . '" <' . $result['values'][$from]['email'] . '>'; - } + $from = CRM_Utils_Mail::mailboxHeader($from); $subject = $formValues['subject']; // CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 138576eb2f..5ea6a46e9d 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -661,7 +661,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { if (!empty($this->_params['send_receipt'])) { - $receiptFrom = $this->_params['from_email_address']; + $receiptFrom = CRM_Utils_Mail::mailboxHeader($this->_params['from_email_address']); if (!empty($this->_params['payment_instrument_id'])) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php index eebb06319e..f3c0189880 100644 --- a/CRM/Utils/Mail.php +++ b/CRM/Utils/Mail.php @@ -577,4 +577,25 @@ class CRM_Utils_Mail { return $formattedEmail; } + /** + * When passed a value, returns the value if it's non-numeric. + * If it's numeric, look up the display name and email of the corresponding + * contact ID in RFC822 format. + * + * @param string $header + * @return string + * The RFC822-formatted email header (display name + address) + */ + public static function mailboxHeader($header) { + if (is_numeric($header)) { + $result = civicrm_api3('Email', 'get', [ + 'id' => $header, + 'return' => ['contact_id.display_name', 'email'], + 'sequential' => 1, + ])['values'][0]; + $header = '"' . $result['contact_id.display_name'] . '" <' . $result['email'] . '>'; + } + return $header; + } + } -- 2.25.1