Skip to content
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

mb_convert_encoding(): Illegal character encoding specified #545

Closed
ivanghisleni opened this issue Aug 23, 2022 · 4 comments · Fixed by #546
Closed

mb_convert_encoding(): Illegal character encoding specified #545

ivanghisleni opened this issue Aug 23, 2022 · 4 comments · Fixed by #546
Labels

Comments

@ivanghisleni
Copy link
Contributor

ivanghisleni commented Aug 23, 2022

Q A
ddeboer/imap version 1.10.0
PHP version 7.4.29
IMAP provider -

Summary

I have a problem importing some mail with header with unsupported cherset which block the import, I'm asking if is it possible to handle the exception thown into src/Message/Transcoder.php::decode() maybe into src/Message/Headers.php::__constructor() with try catch with safely ignore?

Here a sample how should be fixed:

final class Headers extends Parameters
{
    /**
     * Constructor.
     */
    public function __construct(\stdClass $headers)
    {
        parent::__construct();

        // Store all headers as lowercase
        $headers = \array_change_key_case((array) $headers);

        foreach ($headers as $key => $value) {
            try {
                $this[$key] = $this->parseHeader($key, $value);
            } catch (\Exception $e) {
                // safely skip header with Unsupported charset
            }
        }
    }

Current behavior

Unsupported charset "": mb_convert_encoding(): Illegal character encoding specified
imap_alerts (0):
imap_errors (0):

How to reproduce: code & error stack trace

this is a sample of EML causing the issue:
[ Header "Subject" is the bugged header ]

X-Real-To: <[email protected]>
X-Stored-In: BlaBla
Return-Path: <[email protected]>
Received: from <[email protected]>
  by bla.bla (CommuniGate Pro RULE 6.1.13)
  with RULE id 14057804; Mon, 27 Feb 2017 13:21:44 +0930
X-Autogenerated: Mirror
Resent-From: <[email protected]>
Resent-Date: Mon, 27 Feb 2017 13:21:44 +0930

Message-Id: <[email protected]>
From: =?X-IAS-German?B?bXlHb3Y=?=<[email protected]>
To: [email protected]
Subject: =?X-IAS-German?B?U3VibWl0IHlvdXIgdGF4IHJlZnVuZCB8IEF1c3RyYWxpYW4gVGF4YXRpb24gT2ZmaWNlLg==?=
Date: 27 Feb 2017 04:51:29 +0100
MIME-Version: 1.0
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

)

Expected behavior

Handle the error conversion maybe skipping the not supported header.

@Slamdunk
Copy link
Collaborator

Slamdunk commented Aug 23, 2022

From: =?X-IAS-German?B?bXlHb3Y=?=<[email protected]>

Is this the original header that caused the issue? If not, may you post the original one please?

@ivanghisleni
Copy link
Contributor Author

From: =?X-IAS-German?B?bXlHb3Y=?=<[email protected]>

Is this the original header that caused the issue? If not, may you post the original one please?

Yes, I only replaced the original domain with bla.bla, Subject is original and not modified.

@Slamdunk
Copy link
Collaborator

What the hell is X-IAS-German which doesn't exist in Google https://www.google.com/search?q=%22X-IAS-German%22 🤷

Your fix looks promising, can you open a PR with a test case along the fix please?

@ivanghisleni
Copy link
Contributor Author

@Slamdunk Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants