Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoDaddy Email Sync Breaks on MIME Header Decoding in SuiteCRM 8.4 #363

Open
DBRenny opened this issue Oct 16, 2023 · 1 comment
Open

GoDaddy Email Sync Breaks on MIME Header Decoding in SuiteCRM 8.4 #363

DBRenny opened this issue Oct 16, 2023 · 1 comment
Labels
Area: Emails Issues & PRs related to all things regarding emails & email module Priority:Important Issues & PRs that are important; broken functions; errors; there are workarounds Severity: Major Significant impact/severe disruption Type: Bug Something isn't working

Comments

@DBRenny
Copy link

DBRenny commented Oct 16, 2023

Issue

We are experiencing an issue with the email synchronization functionality in SuiteCRM. Specifically, the system encounters a fatal error during the process of handling MIME header decoding for email subject, to list, from, and other headers. The error message indicates a problem with the foreach() function, suggesting that the variable being iterated upon is not an array or object as expected.

Expected Behavior

The CRM should seamlessly decode MIME headers and handle email headers, regardless of their encoding, without encountering fatal errors. The process should iterate over the decoded headers and correctly process the email details into a readable format.

Actual Behavior

Instead of successful processing, the system throws a fatal error, particularly pointing to the foreach() line in the handleMimeHeaderDecode method. The error message is: "Invalid argument supplied for foreach()". This issue disrupts the normal flow of email synchronization, preventing emails from being properly imported and read in the CRM.

Relevant logs indicate the error originates from the handleMimeHeaderDecode method, but there's no additional information about the state or format of the data being passed to foreach().

SuiteCRM_10236 sample log.txt

Possible Fix

A potential fix could involve adding robust checks before the foreach() statement to ensure the variable is indeed iterable. If the variable is a JSON string, it might require decoding with json_decode().

Here's a proposed code snippet (GPT helped): It referenced subject, but all header information except time information is not syncing.


php
Copy code
// Check if $subjectDecoded is JSON, and decode it if necessary
if (is_string($subjectDecoded)) {
    $decodedJson = json_decode($subjectDecoded);
    if (json_last_error() === JSON_ERROR_NONE) {
        $subjectDecoded = $decodedJson;
    } else {
        // Handle error
    }
}

// Check if $subjectDecoded is iterable
if (is_iterable($subjectDecoded)) {
    // existing foreach loop
} else {
    // Handle error
}

Steps to Reproduce

  1. Set up email synchronization in SuiteCRM.
  2. Receive an email with a subject that requires MIME header decoding.
  3. Observe the SuiteCRM log or UI for errors during the email import process.
  4. Notice the "Invalid argument supplied for foreach()" error pointing to the handleMimeHeaderDecode method.

Context

This is our pilot system, but we need to use as many integrated features as possible. I want to get through these roadblocks to start expanding the scope of users.

Outbound email automation still works, and in the meantime my users can use outlook. but this is a major adoptability issue.
Inbound email box view:
image
Email detail level view:
image

Your Environment

  • SuiteCRM Version used: 8.4
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)):
  • Environment name and version: PHP 8.1.24, MariaDB 11.0.3, Godaddy Office 365 (outlook.office365.com) - utilizing an OATH connection
  • Debian GNU/Linux 11 (bullseye)

This is somewhat similar to this issue: SuiteCRM#9921, but I opened a new one so it could be replicated with my environment.

@DBRenny
Copy link
Author

DBRenny commented Oct 17, 2023

I have a fix, but should I leave this open so you can create a branch? Do you want me to do it? I haven't done one of those before on here. I would be happy to learn.

Replacing the function with this resolved my issue:

public function handleMimeHeaderDecode($subject)
{
    $GLOBALS['log']->debug('handleMimeHeaderDecode: Starting MIME header decoding for subject: ' . $subject);

    $subjectDecoded = $this->getImap()->MimeHeaderDecode($subject);

    // If $subjectDecoded is a string, log its content to understand why
    if (is_string($subjectDecoded)) {
        $GLOBALS['log']->error('handleMimeHeaderDecode: $subjectDecoded is a string. Content: ' . $subjectDecoded);
        // Instead of returning an error message, we might want to return the original subject
        // or handle this case appropriately based on the actual content of $subjectDecoded.
        return $subject; // returning the original subject for now
    }

    $ret = '';
    if (is_array($subjectDecoded)) { // Checking if it's an array as expected
        $GLOBALS['log']->debug('handleMimeHeaderDecode: $subjectDecoded is an array, proceeding with decoding');
        foreach ($subjectDecoded as $object) {
            if (isset($object->charset) && $object->charset != 'default' && isset($object->text)) {
                $ret .= $this->handleCharsetTranslation($object->text, $object->charset);
            } elseif (isset($object->text)) {
                $ret .= $object->text;
            }
        }
    } else {
        $GLOBALS['log']->error('handleMimeHeaderDecode: $subjectDecoded is not an array');
        // Similar to above, decide how you want to handle this error.
        return $subject; // returning the original subject for now
    }

    $GLOBALS['log']->debug('handleMimeHeaderDecode: Decoding completed, result: ' . $ret);
    return $ret;
}

DBRenny added a commit to DBRenny/SuiteCRM-Core that referenced this issue Oct 19, 2023
DBRenny added a commit to DBRenny/SuiteCRM-Core that referenced this issue Oct 19, 2023
DBRenny added a commit to DBRenny/SuiteCRM-Core that referenced this issue Oct 19, 2023
DBRenny added a commit to DBRenny/SuiteCRM-Core that referenced this issue Oct 19, 2023
@johnM2401 johnM2401 added Type: Bug Something isn't working Priority:Important Issues & PRs that are important; broken functions; errors; there are workarounds Area: Emails Issues & PRs related to all things regarding emails & email module Severity: Major Significant impact/severe disruption labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Emails Issues & PRs related to all things regarding emails & email module Priority:Important Issues & PRs that are important; broken functions; errors; there are workarounds Severity: Major Significant impact/severe disruption Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants