Opened 6 years ago

Closed 6 years ago

#1484290 closed Bugs (fixed)

mb_convert_encoding returns valid value even if there's an error

Reported by: wastiee Owned by:
Priority: 5 Milestone:
Component: Core functionality Version: git-master
Severity: major Keywords:
Cc:

Description

(this is for svn rev 508)

Well, even when mb_convert_encoding doesn't know about the encodings given, it just gives a warning and still returns the input string.

I was having problems with Windows-1254 encoded email. I've been digging the sources for 5 hours, and I've finally found that the main reason was because this "if" doesn't detect if mb_convert_encoding failed or not, but acts as if it always succeeds.

I've fixed the problem by checking the input/output charsets from mb_list_encodings(). I'm providing a patch for rcube_charset_convert() here, this goes to program/include/main.inc

About the patch; it will be a lot better if $enclist is made global (or at least some kind of static), so it won't call mb_list_encodings() on every call to rcube_charset_convert(), but as i don't know the coding specifications for the project, i didn't want to submit a larger patch :)

this goes to program/include/main.inc

966c966,967
<     if (($out = mb_convert_encoding($str, $to, $from)) != '')
---
>     $enclist = mb_list_encodings();
>     if (in_array($from, $enclist) && in_array($to, $enclist) && ($out = mb_convert_encoding($str, $to, $from)) != '')



About the background; As I know that windows-125x series are similar to CP125x series, I've added "WINDOWS-1252" => UTF8_MAP_DIR . "/CP1254.map" to program/lib/utf8.class.php but nothing changed. That was 5 hours ago, for the last 5 hours I've been trying to find what is happening behind (i've even thought (and examined:) ) there's no charset conversion for mail bodies), and I've later seen that it was just because of mb_convert_encoding :)

Kerem HADIMLI
wastiee_gmail.com

Change History (2)

comment:1 Changed 6 years ago by wastiee

note: of course i haven't added this: "WINDOWS-1252" => UTF8_MAP_DIR . "/CP1254.map", i've added this: "WINDOWS-1254" => UTF8_MAP_DIR . "/CP1254.map"

sorry for the typo :)

Kerem HADIMLI wastiee_gmail.com

comment:2 Changed 6 years ago by thomasb

  • Resolution set to fixed
  • Status changed from new to closed

Use iconv instead of mbstring. Should be fixed with [b8e65ce3]

Note: See TracTickets for help on using tickets.