Skip to content

Solution for empty body issue #397

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

Closed
freescout-helpdesk opened this issue Apr 11, 2023 · 2 comments
Closed

Solution for empty body issue #397

freescout-helpdesk opened this issue Apr 11, 2023 · 2 comments
Labels
bug Something isn't working validated

Comments

@freescout-helpdesk
Copy link
Contributor

Maybe this info have not reached @Webklex by email, so we are posting it here.

This line https://github.com/Webklex/php-imap/blob/master/src/Message.php#L906 on some systems actually throws "iconv(): Wrong encoding, conversion from "ISO-8859-1" to "UTF-8//IGNORE" is not allowed" error. But it's suppressed via "@".

On some systems "iconv" works with "//IGNORE" on some without. So here is the solution:

            try {
                return iconv($from, $to.'//IGNORE', $str);
            } catch (\Exception $e) {
                return @iconv($from, $to, $str);
            }

https://github.com/freescout-helpdesk/freescout/blob/master/overrides/webklex/php-imap/src/Message.php#L727

Now we don't have an "empty body" issue anymore in our project.

@Webklex Webklex added bug Something isn't working validated labels Apr 11, 2023
@freescout-helpdesk
Copy link
Contributor Author

Addition. On some operating systems in some cases neither iconv($from, $to.'//IGNORE', $str) nor iconv($from, $to, $str) are able to decode the body. In such cases mb_convert_encoding is able to do it:

https://github.com/freescout-helpdesk/freescout/blob/master/overrides/webklex/php-imap/src/Message.php#L740

@Webklex
Copy link
Owner

Webklex commented Jun 23, 2023

Hi @freescout-helpdesk ,
many thanks for your report and great suggestion! I'm a bit afraid though of removing iconv and switching to purely relying on mb_convert_encoding instead. This is mainly caused by a lack of "testability" (Testbarkeit) on my end. Any idea how I could setup a testing environment for this - especially for the test-docker container?

Best regards and happy coding,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validated
Projects
None yet
Development

No branches or pull requests

2 participants