From: eileen Date: Tue, 26 May 2020 02:58:37 +0000 (+1200) Subject: [REF] Simplify subject code. Note sendEmail X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=541ad531ebfd9c12a4ed2faaf1e400c1b66bda73;p=civicrm-core.git [REF] Simplify subject code. Note sendEmail is only called from this, some tests, and a deprecated function (unused in core) so we can change it to not pass by reference safely --- diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 97b4347027..027f767fcc 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -397,7 +397,6 @@ trait CRM_Contact_Form_Task_EmailTrait { // 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" $from = CRM_Utils_Mail::formatFromAddress($from); - $subject = $formValues['subject']; $ccArray = $formValues['cc_id'] ? explode(',', $formValues['cc_id']) : []; $cc = $this->getEmailString($ccArray); @@ -407,12 +406,6 @@ trait CRM_Contact_Form_Task_EmailTrait { $bcc = $this->getEmailString($bccArray); $additionalDetails .= empty($bccArray) ? '' : "\nbcc : " . $this->getEmailUrlString($bccArray); - // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects - if (isset($this->_caseId) && is_numeric($this->_caseId)) { - $hash = substr(sha1(CIVICRM_SITE_KEY . $this->_caseId), 0, 7); - $subject = "[case #$hash] $subject"; - } - // format contact details array to handle multiple emails from same contact $formattedContactDetails = []; foreach ($this->_contactIds as $key => $contactId) { @@ -438,7 +431,7 @@ trait CRM_Contact_Form_Task_EmailTrait { // send the mail list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail( $formattedContactDetails, - $subject, + $this->getSubject($formValues['subject']), $formValues['text_message'], $formValues['html_message'], NULL, @@ -643,4 +636,22 @@ trait CRM_Contact_Form_Task_EmailTrait { return $attachments; } + /** + * Get the subject for the message. + * + * The case handling should possibly be on the case form..... + * + * @param string $subject + * + * @return string + */ + protected function getSubject(string $subject):string { + // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects + if (isset($this->_caseId) && is_numeric($this->_caseId)) { + $hash = substr(sha1(CIVICRM_SITE_KEY . $this->_caseId), 0, 7); + $subject = "[case #$hash] $subject"; + } + return $subject; + } + }