Further tweeks following testing
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 18 Sep 2015 04:34:20 +0000 (04:34 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 18 Sep 2015 22:14:39 +0000 (22:14 +0000)
CRM/Utils/Mail/EmailProcessor.php

index 3418185e64f703168b8bf3ce5152db5eb87b8c0c..394aa52e7cb2d608c8652b7970c0fa1a30d0e13b 100644 (file)
@@ -288,7 +288,7 @@ class CRM_Utils_Mail_EmailProcessor {
                 $text = $mail->body->text;
               }
               elseif ($mail->body instanceof ezcMailMultipart) {
-                if ($mail->body instanceof ezcMailMultipartReport) {
+               if ($mail->body instanceof ezcMailMultipartReport) {
                   $part = $mail->body->getMachinePart();
                   if ($part instanceof ezcMailDeliveryStatus) {
                     foreach ($part->recipients as $rec) {
@@ -296,12 +296,25 @@ class CRM_Utils_Mail_EmailProcessor {
                         $text = $rec["Diagnostic-Code"];
                         break;
                       }
-                    }
-                    if (empty($text)) {
-                      $text = $part->text;
+                      elseif (isset($rec["Description"])) {
+                        $text = $rec["Description"];
+                        break;
+                      }
+                      // no diagnostic info present - try getting the human readable part
+                      elseif (isset($rec["Status"])) {
+                        $text = $rec["Status"];
+                        $textpart = $mail->body->getReadablePart();
+                        if ($textpart != NULL and isset($textpart->text)) {
+                          $text .= " " . $textpart->text;
+                        }
+                        else {
+                          $text .= " Delivery failed but no diagnostic code or description.";
+                        }
+                        break;
+                      }
                     }
                   }
-                  elseif ($part != NULL) {
+                  elseif ($part != NULL and isset($part->text)) {
                     $text = $part->text;
                   }
                   elseif (($part = $mail->body->getReadablePart()) != NULL) {
@@ -339,7 +352,7 @@ class CRM_Utils_Mail_EmailProcessor {
                           $text = $rec["Description"];
                         }
                         else {
-                          $text = "Delivery to the following recipients failed";
+                          $text = $rec["Status"] . " Delivery to the following recipients failed";
                         }
                         break;
                       }