salesagility / SuiteCRM-Core

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

Can not send email because of failing mb_encode_mimeheader #567

Open blummarci24 opened 1 week ago

blummarci24 commented 1 week ago

Issue

There is a failing code in the legacy Localization.php in translateCharsetMIME function causing error on email sending.

The failing code is here:

$result = mb_encode_mimeheader($string, $toCharset, $encoding);

Digging deeper it is a change in polyfill-mbstring dependency:

```public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
{
    trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
}```

Possible Fix

As suggested, use iconv_mime_encode. I have a working local solution for this which fix this issue.

    public function translateCharsetMIME($string, $fromCharset, $toCharset = 'UTF-8', $encoding = "Q")
    {
        $preferences = array(
            'input-charset' => $fromCharset,
            'output-charset' => $toCharset,
            'line-length' => 76,
            'scheme' => $encoding,
            'line-break-chars' => "\n"
        );
        $result = iconv_mime_encode('', $string, $preferences);
        return substr($result, 2);
    }
I will create a PR for this.

Steps to Reproduce the Issue

1. Set up an new suitecrm environment (tested on 8.7 and php 8.2)
2. Login and go to admin page
3. Configure email and try to send a test email
...

Context

I tried the email functionality. I have not found any other topic to this certain issue, so I took a look at the code.

Version

8.7.0

What browser are you currently using?

Chrome

Browser Version

No response

Environment Information

PHP 8.2

Operating System and Version

Ubuntu 20.04.6 LTS

blummarci24 commented 5 days ago

Fix in:

https://github.com/salesagility/SuiteCRM-Core/pull/568