From: Olivier Date: Fri, 3 Jul 2015 14:05:41 +0000 (-0400) Subject: CRM-16584 - Improve bounce management with Mandrilla SMTP X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=08523e941113b71cff700e51e7823005c27cb5dc;p=civicrm-core.git CRM-16584 - Improve bounce management with Mandrilla SMTP --- diff --git a/CRM/Utils/Mail/EmailProcessor.php b/CRM/Utils/Mail/EmailProcessor.php index 3d469222b4..663da9f796 100644 --- a/CRM/Utils/Mail/EmailProcessor.php +++ b/CRM/Utils/Mail/EmailProcessor.php @@ -171,7 +171,8 @@ class CRM_Utils_Mail_EmailProcessor { $rpRegex = '/Return-Path: ' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/'; // a regex for finding bound info X-Header - $rpXheaderRegex = '/X-CiviMail-Bounce: ' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/'; + $rpXheaderRegex = '/X-CiviMail-Bounce: ' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/i'; + // CiviMail in regex and Civimail in header !!! // retrieve the emails try { @@ -220,6 +221,23 @@ class CRM_Utils_Mail_EmailProcessor { if (!$matches and preg_match($rpXheaderRegex, $mail->generateBody(), $matches)) { list($match, $action, $job, $queue, $hash) = $matches; } + // With Mandrilla, the X-CiviMail-Bounce header is produced by generateBody + // is base64 encoded + // Check all parts + if (!$matches) { + $all_parts=$mail->fetchParts(); + foreach ($all_parts as $k_part => $v_part) { + if ($v_part instanceof ezcMailFile) { + $p_file = $v_part->__get('fileName'); + $c_file=file_get_contents($p_file); + if (preg_match($rpXheaderRegex, $c_file, $matches)) { + self::_log("file match rpXheaderRegex", $matches); + list($match, $action, $job, $queue, $hash) = $matches; + } + } + } + } + // if all else fails, check Delivered-To for possible pattern if (!$matches and preg_match($regex, $mail->getHeader('Delivered-To'), $matches)) {