Skip to content

Commit

Permalink
Fix 'mb_convert_encoding(): Illegal character encoding specified' whe…
Browse files Browse the repository at this point in the history
…n encoding is windows
  • Loading branch information
Sebastian Krätzig committed May 25, 2019
1 parent f1a97a8 commit e4d5130
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ public function parseDateTime($dateHeader) {
* @throws Exception
*/
public function convertStringEncoding($string, $fromEncoding, $toEncoding) {
if(!$string || $fromEncoding == $toEncoding || preg_match("/default/i", $fromEncoding)) {
if(preg_match("/default|ascii|windows/i", $fromEncoding) || !$string || $fromEncoding == $toEncoding) {
return $string;
}
if(extension_loaded('mbstring')) {
Expand Down

3 comments on commit e4d5130

@Sebbo94BY
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ASCII is already a valid UTF-8, so we don't need to convert ASCII strings.
  • windows-1258 can not be converted to UTF-8 (returning it as it is)

When you try to convert eg. windows-1258 to utf-8 this will fail with the following error message: mb_convert_encoding(): Illegal character encoding specified

@ebrana-devs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, what about try mb_convert_encoding on supported encodings and to other use iconv?
I have string in windows-1250, try to covert it to UTF-8, mb_ ends with error, but iconv do the job ....

@Sebbo94BY
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try this as well. Let's check this out in #335.

Please sign in to comment.