downloadEmail error on Save

4 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: September 20   (RSS)

I have encountered a new error with downloadEmail plugin.

After configuration, it worked well for a day or so. However, that was soon replaced by its downloading messages more than a dozen times.

After that, it has been failing each time, retrieving nothing and generating the error:

_mb_is_valid_encoding(): Argument #1 ($encoding) must be of type string, null given, called in /chroot/home/avisitwj/avisitwithjesus.com/html/cmsCSoft/plugins/downloadMail/downloadMail.php on line 473.

The full error message received by email is:

The following Scheduled Task did not complete successfully:

Date/Time: 2024-08-25 11:00:01Activity: Download MailSummary: Returned errorsCompleted: 0Function: downloadMail_startTaskOutput: Checking mail account: xxxxxxxx@example.com
Connecting to IMAP host: cloudvpstemplate.xxxx.example.com
Downloading 4 of 4 new messages
Downloading message #1 - UID: 102 - Message-Id: <945705112.1573113.1724580058952@nvirginia-se-email-delivery-5f58bbb4b8-phlbn>
_mb_is_valid_encoding(): Argument #1 ($encoding) must be of type string, null given, called in /chroot/home/user/example.com/html/cmsCSoft/plugins/downloadMail/downloadMail.php on line 473 in /chroot/home/user/example.com/html/cmsCSoft/plugins/downloadMail/downloadMail.php on line 473

Line 473 references the function...

472     function _mb_convert_to_utf8($string, $fromEncoding, $defaultEncoding = 'UTF-8') {
473.    $encoding = _mb_is_valid_encoding($fromEncoding) ? $fromEncoding : $defaultEncoding;
474.     return mb_convert_encoding($string, 'UTF-8', $encoding);
            }

Has anyone else encountered this behavior?

Hello pgplast,

Sorry I hadn't seen this sooner. Hopefully you got this resolved on your own, but if not I have a fix for you. The bug you encountered is something I have seen in another project using download mail so thought I would provide a fix below for anyone else who may encounter the problem inside the download mail plugin...

function _mb_convert_to_utf8($string, $fromEncoding, $defaultEncoding = 'UTF-8') {
  $encoding = (!is_null($fromEncoding) && _mb_is_valid_encoding($fromEncoding)) ? $fromEncoding : $defaultEncoding;
  return mb_convert_encoding($string, 'UTF-8', $encoding);
}

The error occurs due to the $fromEncoding sometimes being null. Here we check for it. If it is null, we will use the default encoding (UTF-8). 

Before implementing, be sure to backup your plugin. Keep in mind that this fix will get overwritten if you choose to update the plugin. I will have Dave put it in the next official release of the plugin.

Thanks again for the report!

Tim Hurd
Senior Web Programmer
Interactivetools.com

Thanks very much, Tim.

Dave had earlier provided a similar solution.

Appreciate the followup.

Philip