CRM-17231 Allow for Multipart Report to be included in the Email Processor
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 16 Sep 2015 23:36:45 +0000 (23:36 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 18 Sep 2015 22:14:05 +0000 (22:14 +0000)
CRM/Utils/Mail/EmailProcessor.php

index f1c964db859ec3b53a2bfa96f55e42ecda19df08..d01ad9c5a96569e8cc1cb0c1aa5148ca8348c20b 100644 (file)
@@ -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;
                       }
                     }