salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.53k stars 2.1k forks source link

Problem reading mail connected by oauth2 MSO365 #9921

Open ibanvaqe opened 1 year ago

ibanvaqe commented 1 year ago

Issue

During these days I have managed to set up the OAuth2 structure to connect at IMAP level against office365.

All the connection tests, tokens, etc. are correct. The problem occurs when I want to see the mail from SUITECRM. The from and subject fields are empty and I can’t figure out why.

Expected Behavior

You should see the fields of each section correctly when picking up the INBOX.

Actual Behavior

https://community.suitecrm.com/uploads/default/original/2X/1/1458af11985eca7d8281f282dedbc7863aa5cc65.png

Possible Fix

Steps to Reproduce

1.Configure all the OAuth2 section . 2.I receive the token , I can see my mail folders in the inbox settings .

  1. I configure the profile and add the desired INBOX to it.
  2. It picks up the body of the mail but not the from and subject fields.

Context

This is happening to me in a lab environment with several MS365 mails.

Your Environment

johnM2401 commented 1 year ago

Hey!

Hmmmm, I'm unfortunately unable to replicate at the moment

I've set up an Oauth2 authenticated 365 Account: image


But it appears as though the From/Subject values are pulling in as expected: image


I have some questions and things to try, if you have a chance?:

If you try to import one of these Emails into the CRM (via the Record's import action) Do the Subject/From values then display as expected?

Additionally, do you know if your Email Listview has perhaps been customized at all? (ie: Fields Removed/Added/Changed on Listview)

Lastly, have you given this a try in the default English Language Pack that the CRM installs in? This would be worth confirming if the Langauge Pack affects this view

Thanks for getting in touch!

ibanvaqe commented 1 year ago

Hey!

Hmmmm, I'm unfortunately unable to replicate at the moment

I've set up an Oauth2 authenticated 365 Account: image

But it appears as though the From/Subject values are pulling in as expected: image

I have some questions and things to try, if you have a chance?:

If you try to import one of these Emails into the CRM (via the Record's import action) Do the Subject/From values then display as expected?

Additionally, do you know if your Email Listview has perhaps been customized at all? (ie: Fields Removed/Added/Changed on Listview)

Lastly, have you given this a try in the default English Language Pack that the CRM installs in? This would be worth confirming if the Langauge Pack affects this view

Thanks for getting in touch!

Hi,

I have tried all types.

I have tested with several emails and they all appear the same.

If I import it in SUITECRM, it looks like this

https://ibb.co/mhJzR6J

I have used the English language and I get the same

I don't know what else to do. I have tried to search if any user has had this problem but I can't find anything related to this.

ibanvaqe commented 1 year ago

Hey!

Hmmmm, I'm unfortunately unable to replicate at the moment

I've set up an Oauth2 authenticated 365 Account: image

But it appears as though the From/Subject values are pulling in as expected: image

I have some questions and things to try, if you have a chance?:

If you try to import one of these Emails into the CRM (via the Record's import action) Do the Subject/From values then display as expected?

Additionally, do you know if your Email Listview has perhaps been customized at all? (ie: Fields Removed/Added/Changed on Listview)

Lastly, have you given this a try in the default English Language Pack that the CRM installs in? This would be worth confirming if the Langauge Pack affects this view

Thanks for getting in touch!

Hi again,

Can you tell me what version of PHP you are using?

I have also set up a Suitecrm 7.13 from scratch totally empty for testing and it keeps crashing. In the suitecrm log I don't see any failure.

johnM2401 commented 1 year ago

Hi @ibanvaqe

I've given this a try in both php 7.4 and php 8.0, but I'm still unable to replicate, I'm afraid

Have you given this a try with any other mail services?

Or, do you have any other CRM users that do not experience this issue? (if so, are there any differences in mail setup?)

Also, do you know if your Email Listview has perhaps been customized at all? (ie: Fields Removed/Added/Changed on Listview/Detailview)

Thank you for your patience, Hopefully we can narrow this down.

ibanvaqe commented 1 year ago

I have configured the SCRM against another mail365 service but I am still failing those two fields.

As I said, on the same server I have a lab server and another one set up from scratch SCRM 7.13 generated by the wizard.

Both fail me when displaying those fields.

They are configured with PHP 7.4. If I try to configure it with php 8.0 the SCRM is blank and does not work.

Question:

In your tests are you using all three scopes¿?

offline_access

https://outlook.office.com/IMAP.AccessAsUser.All

User.Read

The only thing left for me is to set up a new system and reinstall all the services and SCRM 7.13 with PHP 8.0 and see if it works.

johnM2401 commented 1 year ago

Hey

Thanks for your patience and getting back in touch

When testing, I've been using the scope:

offline_access https://outlook.office.com/IMAP.AccessAsUser.All SMTP.Send User.Read

image

(However, even if I try without SMTP.Send, I am unable to replicate)


Regarding:

If I try to configure it with php 8.0 the SCRM is blank and does not work.

Was this when saving records in the Email Modules? I believe the PHP8.0 Whitescreen issues have been resolved as of 7.13.1, so please try using this version.

Please let us know how you get on.

Thanks again!

ibanvaqe commented 1 year ago

Hey

Thanks for your patience and getting back in touch

When testing, I've been using the scope:

offline_access https://outlook.office.com/IMAP.AccessAsUser.All SMTP.Send User.Read

image

(However, even if I try without SMTP.Send, I am unable to replicate)

Regarding:

If I try to configure it with php 8.0 the SCRM is blank and does not work.

Was this when saving records in the Email Modules? I believe the PHP8.0 Whitescreen issues have been resolved as of 7.13.1, so please try using this version.

Please let us know how you get on.

Thanks again!

Hi @johnM2401

Thanks for continuing to help me in this thread.

I have new news about the section. I have managed to get it working and the fields appear. To make it work I had to do:

The only thing I have problems now is to be able to monitor the sent mail folder.

I can only see the INBOX folder. I have configured individually to see the sent folder but I still only see the INBOX.

I have tried several ways but it does not want to monitor other folders in the SCRM that I have configured in the email.

aurelien1980 commented 1 year ago

Hi. I have the exact same issue. SuiteCRM 7.13.3 on PHP 8.0 All fields are empty, only body and attachments are showing in SuiteCRM.

Screenshot 2023-06-07 134708

I am on production, how to solve ? @ibanvaqe what did you change in your php.ini ?

In logs, i can see those lines, if it helps: [FATAL] ImapHandler trying to use a non valid resource stream.

ibanvaqe commented 1 year ago

Hi. I have the exact same issue. SuiteCRM 7.13.3 on PHP 8.0 All fields are empty, only body and attachments are showing in SuiteCRM.

Screenshot 2023-06-07 134708

I am on production, how to solve ? @ibanvaqe what did you change in your php.ini ?

In logs, i can see those lines, if it helps: [FATAL] ImapHandler trying to use a non valid resource stream.

Hello @aurelien1980

In the thread I have explained the steps I did in my case to make the mail service work in SuiteCRM 7.13.1 (Now, I work 7.13.3)

With this I got my SuiteCRM to work when collecting mails from the inbox.

I don't know if you have the same structure as mine but maybe it helps you

DBRenny commented 1 year ago

I))) am having the same issue as the OP I am on suiteCRM 8.4, fresh bitnami installation.

I can successfully authenticate with OATH, and see a bunch of sent/ inbox emails. It even marks the emails as read in my outlook.

I traced the problem in the error log to potentially be in how the IMAP header is decoded in the InboundEmail.php file.

sudo nano /bitnami/suitecrm/public/legacy/modules/InboundEmail/InboundEmail.php

Line 4854:

 * takes the output from imap_mime_hader_decode() and handles multiple types of encoding
 * @param string subject Raw subject string from email
 * @return string ret properly formatted UTF-8 string
 */
public function handleMimeHeaderDecode($subject)
{
    $subjectDecoded = $this->getImap()->MimeHeaderDecode($subject);

    $ret = '';
    foreach ($subjectDecoded as $object) {
        if ($object->charset != 'default') {

Issue No - 9921apache logs example (o365 IMAP header decode).txt

            $ret .= $this->handleCharsetTranslation($object->text, $object->charset);
        } else {
            $ret .= $object->text;
        }
    }

    return $ret;
}

PHP Version:

PHP 8.1.24 (cli) (built: Sep 29 2023 13:20:42) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.24, Copyright (c) Zend Technologies with Zend OPcache v8.1.24, Copyright (c), by Zend Technologies

chris001 commented 1 year ago

From your log, the error is: the code passed a string to the foreach loop, it needs an array:

Got error 'PHP message: PHP Warning:  foreach() argument must be of type array|object, string given in /bitnami/suitecrm/public/legacy/modules/InboundEmail/InboundEmail.php on line 4863', referer: https://agent.mysuitecrmurl.com/legacy/index.php?module=Emails