php-imap: Problem with serverEncoding
Hey,
I get the following error, when using the server encoding:
PHP Fatal error: Uncaught exception 'ErrorException' with message 'Unknown: [BADCHARSET (US-ASCII)] The specified charset is not supported. (errflg=2)' in Unknown:0
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Unknown: [BADCH...', 'Unknown', 0, Array)
#1 {main}
thrown in Unknown on line 0
If I remove the server encoding from imap_search, everything works fine. With it I dont get any results and this error. Does anyone have an idea what the problem is (I’m trying to read from an exchange mailbox)?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (1 by maintainers)
Commits related to this issue
- Mime string encoding conversion failed https://github.com/barbushin/php-imap/issues/101 — committed to nickl-/php-imap by commanddotcom 6 years ago
PHP Fatal error: Uncaught ErrorException: Unknown: [BADCHARSET (US-ASCII)]
Before:
After:
Summary: Works perfectly without diggin’ into source code. If you know how to improve goto part, let me know.
Notice: You might want to limit attempts, in order to prevent goto looping.
@rustem-art
I tried that before. But then I got the wrong encoding subject and content. It seems that encoding in
ImapMailboxmeeds to beUTF-8too.At last I do the following changes temporarily:
Before:
public function searchMailbox($criteria = 'ALL') { $mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID, $this->serverEncoding); return $mailsIds ? $mailsIds : array(); }After:public function searchMailbox($criteria = 'ALL', $serverEncoding = null) { $mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID, $serverEncoding ?: $this->serverEncoding); return $mailsIds ? $mailsIds : array(); }And in my app:
$mailsIds = $mailbox->searchMailbox('UNSEEN', stripos($account->username, 'outlook.com') !== false ? 'US-ASCII' : 'UTF-8');It works for me.
And sorry for my english too 😃
PhpImap\Exception [ 0 ]: Mime string encoding conversion failed ~ APPPATH/vendor/php-imap/php-imap/src/PhpImap/Mailbox.php [753]
Before:
After:
Explanation:
To reproduce this problem you can use cyrrilic email’s subject. It will try to
convertStringEncoding($subject, "utf-8", "US-ASCII")and throw exception by …… However function’s docblock says: @return string Converted string if conversion was successful, or the original string if not
@littleylv i can solve this problem only by add specific character param in
and in your app you can select, if MS Outlook mail server then $encoding = ‘US-ASCII’; in other UTF-8…
PS sorry for my english.