cakephp icon indicating copy to clipboard operation
cakephp copied to clipboard

5.x: deprecated mb_encode_mimeheader() usage

Open dereuromark opened this issue 9 months ago • 5 comments

Description

My logs are filling up with errors:

mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead
Trace:
Cake\Error\ErrorTrap->handleError() [internal], line ??
/var/www/app/vendor/symfony/polyfill-mbstring/Mbstring.php /var/www/app/vendor/symfony/polyfill-mbstring/Mbstring.php, line 152
Symfony\Polyfill\Mbstring\Mbstring::mb_encode_mimeheader() /var/www/app/vendor/symfony/polyfill-mbstring/bootstrap80.php, line 21
/var/www/app/vendor/cakephp/cakephp/src/Mailer/Message.php /var/www/app/vendor/cakephp/cakephp/src/Mailer/Message.php, line 1764
Cake\Mailer\Message->encodeForHeader() /var/www/app/vendor/cakephp/cakephp/src/Mailer/Message.php, line 815

Symfony polyfill seems to cause this with

    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);
    }

Message::encodeForHeader() is using it apparently:

        $restore = mb_internal_encoding();
        mb_internal_encoding($this->appCharset);
        $return = mb_encode_mimeheader($text, $this->getHeaderCharset(), 'B');
        mb_internal_encoding($restore);

CakePHP Version

5.2

PHP Version

8.3

dereuromark avatar Apr 30 '25 13:04 dereuromark

Wow, I found https://github.com/cakephp/cakephp/issues/8511 Apparently we didnt do much here yet.

dereuromark avatar Apr 30 '25 21:04 dereuromark

Apparently we didnt do much here yet.

do you have the mbstring extension installed? In the past that helped resolve this warning. Using iconv_mime_encode adds a new extension requirement (iconv), so it may not be a trivial fix.

markstory avatar May 03 '25 16:05 markstory

Afaik /etc/php/8.3/fpm/conf.d/20-mbstring.ini was definitly loaded.

Couldnt the extension be optional and in that case it still can fallback to the "old way"? But that way it would be able to use the new way if available.

dereuromark avatar May 05 '25 00:05 dereuromark

Also, we could detect if the method is available, .e.g. also via https://symfony.com/doc/2.x/components/polyfill_iconv.html and prefer that method over the buggy one I guess.

dereuromark avatar May 05 '25 00:05 dereuromark

This seems like a polyfill error not a cake error.

othercorey avatar May 17 '25 06:05 othercorey