From bf309c74382b3004ef215be03f62a8ada542b06f Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 25 Dec 2015 20:46:46 +0000 Subject: [PATCH] CRM-17754 Include resent headers to ensure that SPF and probably DMARC checking works as Mail Clients will know we are forwarding on the reply --- CRM/Mailing/BAO/Mailing.php | 28 ++++++++++++++++++---------- CRM/Mailing/Event/BAO/Reply.php | 10 ++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 227307c133..36ee5a3ffa 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1014,17 +1014,25 @@ ORDER BY civicrm_email.is_bulkmail DESC $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId(); - - if ($includeMessageId && (!array_key_exists('Message-ID', $headers))) { - $headers['Message-ID'] = '<' . implode($config->verpSeparator, - array( - $localpart . $prefix, - $job_id, - $event_queue_id, - $hash, - ) - ) . "@{$emailDomain}>"; + $fields = array(); + $fields[] = 'Message-ID'; + // CRM-17754 check if Resent-Message-id is set also if not add it in when re-laying reply email + if ($prefix == 'r') { + $fields[] = 'Resent-Message-ID'; + } + foreach ($fields as $field) { + if ($includeMessageId && (!array_key_exists($field, $headers))) { + $headers['Message-ID'] = '<' . implode($config->verpSeparator, + array( + $localpart . $prefix, + $job_id, + $event_queue_id, + $hash, + ) + ) . "@{$emailDomain}>"; + } } + } /** diff --git a/CRM/Mailing/Event/BAO/Reply.php b/CRM/Mailing/Event/BAO/Reply.php index 4d6e874b52..c1ad732743 100644 --- a/CRM/Mailing/Event/BAO/Reply.php +++ b/CRM/Mailing/Event/BAO/Reply.php @@ -117,6 +117,8 @@ class CRM_Mailing_Event_BAO_Reply extends CRM_Mailing_Event_DAO_Reply { $emails = CRM_Core_BAO_Email::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); $contacts = CRM_Contact_BAO_Contact::getTableName(); + $domain_id = CRM_Core_Config::domainID(); + $domainValues = civicrm_api3('Domain', 'get', array('sequential' => 1, 'id' => $domain_id)); $eq = new CRM_Core_DAO(); $eq->query("SELECT $contacts.display_name as display_name, @@ -143,6 +145,11 @@ class CRM_Mailing_Event_BAO_Reply extends CRM_Mailing_Event_DAO_Reply { // to the forward goes to the sender of the reply $parsed->setHeader('Reply-To', $replyto instanceof ezcMailAddress ? $replyto : $parsed->from->__toString()); + // CRM-17754 Include re-sent headers to indicate that we have forwarded on the email + $domainEmail = $domainValues['values'][0]['from_email']; + $parsed->setHeader('Resent-From', $domainEmail); + $parsed->setHeader('Resent-Date', date('r')); + // $h must be an array, so we can't use generateHeaders()'s result, // but we have to regenerate the headers because we changed To $parsed->generateHeaders(); @@ -183,6 +190,9 @@ class CRM_Mailing_Event_BAO_Reply extends CRM_Mailing_Event_DAO_Reply { 'From' => $from, 'Reply-To' => empty($replyto) ? $eq->email : $replyto, 'Return-Path' => "do-not-reply@{$emailDomain}", + // CRM-17754 Include re-sent headers to indicate that we have forwarded on the email + 'Resent-From' => $domainValues['values'][0]['from_email'], + 'Resent-Date' => date('r'), ); $message->setTxtBody($bodyTxt); -- 2.25.1