Improve error handling by using civicrm_api3 not civicrm_api
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 6 Sep 2023 05:42:44 +0000 (17:42 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 6 Sep 2023 05:46:29 +0000 (17:46 +1200)
CRM/Utils/Mail/EmailProcessor.php
CRM/Utils/Mail/Incoming.php

index 7713fce399524d531dc718525766cc53f94fa077..ff30b5b44a302ba802b23883239d3254f9321808 100644 (file)
@@ -188,24 +188,17 @@ class CRM_Utils_Mail_EmailProcessor {
           // if its the activities that needs to be processed ..
           try {
             $mailParams = CRM_Utils_Mail_Incoming::parseMailingObject($mail, $createContact, FALSE, $emailFields);
+            $params = self::deprecated_activity_buildmailparams($mailParams, $dao);
+            $result = civicrm_api3('Activity', 'create', $params);
           }
           catch (Exception $e) {
-            echo $e->getMessage();
+            echo "Failed Processing: {$mail->subject}. Reason: " . $e->getMessage() . "\n";
             $store->markIgnored($key);
             continue;
           }
-          $params = self::deprecated_activity_buildmailparams($mailParams, $dao);
-          $result = civicrm_api('activity', 'create', $params);
-
-          if ($result['is_error']) {
-            $matches = FALSE;
-            echo "Failed Processing: {$mail->subject}. Reason: {$result['error_message']}\n";
-          }
-          else {
-            $matches = TRUE;
-            CRM_Utils_Hook::emailProcessor('activity', $params, $mail, $result);
-            echo "Processed as Activity: {$mail->subject}\n";
-          }
+          $matches = TRUE;
+          CRM_Utils_Hook::emailProcessor('activity', $params, $mail, $result);
+          echo "Processed as Activity: {$mail->subject}\n";
         }
 
         // if $matches is empty, this email is not CiviMail-bound
@@ -478,7 +471,6 @@ class CRM_Utils_Mail_EmailProcessor {
    */
   protected static function deprecated_activity_buildmailparams($result, $dao) {
     $params = [];
-    $params['version'] = 3;
 
     // if we don't cast to int (the dao gives a string), then the Inbound Email Activity 1.0 extension won't work, will be fixed in next version to use a non-strict comparison
     $params['activity_type_id'] = (int) $dao->activity_type_id;
index 1a268c6fea1a0f0cf7e8b1e65f7d17a72e7ad73f..b6a446120d78dd1e8121577bb242516ffeb7061a 100644 (file)
@@ -296,12 +296,6 @@ class CRM_Utils_Mail_Incoming {
    */
   public static function parseMailingObject(&$mail, $createContact = TRUE, $requireContact = TRUE, $emailFields = ['from', 'to', 'cc', 'bcc']) {
 
-    $config = CRM_Core_Config::singleton();
-
-    // get ready for collecting data about this email
-    // and put it in a standardized format
-    $params = ['is_error' => 0];
-
     // Sometimes $mail->from is unset because ezcMail didn't handle format
     // of From header. CRM-19215.
     if (!isset($mail->from)) {