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 breaks code #57

Closed
user1007017 opened this issue Oct 8, 2014 · 2 comments
Closed

mb_convert_encoding breaks code #57

user1007017 opened this issue Oct 8, 2014 · 2 comments
Milestone

Comments

@user1007017
Copy link

On this code

$messages = $mailbox->getMessages();

        foreach ($messages as $message) {
            // $message is instance of \Ddeboer\Imap\Message
            echo "\ngetting Message...";
            echo "\n".$message->getSubject();
        }

it breaks at a certain point...

getting Message...PHP Warning 'yii\base\ErrorException' with message 'mb_convert_encoding(): Unable to detect character encoding'
in /var/www/myhost.com/vendor/ddeboer/imap/src/Ddeboer/Imap/Message/Headers.php:20

// Decode subject, as it may be UTF-8 encoded
    if (isset($headers->subject)) {
        $subject = '';
        foreach (\imap_mime_header_decode($headers->subject) as $part) {
            // $part->charset can also be 'default', i.e. plain US-ASCII
            $charset = $part->charset == 'default' ? 'auto' : $part->charset;
            $subject .= \mb_convert_encoding($part->text, 'UTF-8', $charset);
        }
        $this->array['subject'] = $subject;
    }
@sergbass
Copy link

Also, mb_convert_encoding breaks when unsupported encoding occurs, for instance, windows-1257. And there's no way to avoid code break. I suggest to do 2 things:

  1. add workarounds for known unsupported encodings, may be for this purpose separate class could be created;
  2. add fallback for other unexpected unsupported encodings: when source encoding isn't in mb_list_encodings, set it to auto.

@spshe4
Copy link

spshe4 commented Jun 26, 2017

@ddeboer
I got this error "mb_convert_encoding(): Unable to detect character encoding".
I use - "ddeboer/imap": "^0.5.2"

Can I fix something in my code so that I do not change the vendor files?

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

No branches or pull requests

4 participants