From 9b9a871331cfc9134fa4635479fc51b3094d6cb3 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 16 Sep 2015 23:36:45 +0000 Subject: [PATCH] CRM-17231 Allow for Multipart Report to be included in the Email Processor --- CRM/Utils/Mail/EmailProcessor.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/Mail/EmailProcessor.php b/CRM/Utils/Mail/EmailProcessor.php index f1c964db85..d01ad9c5a9 100644 --- a/CRM/Utils/Mail/EmailProcessor.php +++ b/CRM/Utils/Mail/EmailProcessor.php @@ -288,7 +288,27 @@ class CRM_Utils_Mail_EmailProcessor { $text = $mail->body->text; } elseif ($mail->body instanceof ezcMailMultipart) { - if ($mail->body instanceof ezcMailMultipartRelated) { + if ($mail->body instanceof ezcMailMultipartReport) { + $part = $mail->body->getMachinePart(); + if ($part instanceof ezcMailDeliveryStatus) { + foreach ($part->recipients as $rec) { + if (isset($rec["Diagnostic-Code"])) { + $text = $rec["Diagnostic-Code"]; + break; + } + } + if (empty($text)) { + $text = $part->text; + } + } + elseif ($part != null) { + $text = $part->text; + } + elseif (($part = $mail->body->getReadablePart()) != null) { + $text = $part->text; + } + } + elseif ($mail->body instanceof ezcMailMultipartRelated) { foreach ($mail->body->getRelatedParts() as $part) { if (isset($part->subType) and $part->subType == 'plain') { $text = $part->text; @@ -307,7 +327,7 @@ class CRM_Utils_Mail_EmailProcessor { } if ( - $text == NULL && + empty($text) && $mail->subject == "Delivery Status Notification (Failure)" ) { // Exchange error - CRM-9361 @@ -315,7 +335,12 @@ class CRM_Utils_Mail_EmailProcessor { if ($part instanceof ezcMailDeliveryStatus) { foreach ($part->recipients as $rec) { if ($rec["Status"] == "5.1.1") { - $text = "Delivery to the following recipients failed"; + if (isset($rec["Description"])) { + $text = $rec["Description"]; + } + else { + $text = "Delivery to the following recipients failed"; + } break; } } -- 2.25.1