Skip to content

Commit 9579ee4

Browse files
freescout-helpdeskWebklex
authored andcommitted
Fix broken non-latin characters in body in ASCII (us-ascii) charset (#156)
* Fix broken non-latin characters in body in ASCII (us-ascii) charset * Move us-ascii check into convertEncoding()
1 parent bf0a586 commit 9579ee4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/IMAP/Message.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,21 @@ public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {
702702
$from = EncodingAliases::get($from);
703703
$to = EncodingAliases::get($to);
704704

705+
// We don't need to do convertEncoding() if charset is ASCII (us-ascii):
706+
// ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded
707+
// https://stackoverflow.com/a/11303410
708+
//
709+
// us-ascii is the same as ASCII:
710+
// ASCII is the traditional name for the encoding system; the Internet Assigned Numbers Authority (IANA)
711+
// prefers the updated name US-ASCII, which clarifies that this system was developed in the US and
712+
// based on the typographical symbols predominantly in use there.
713+
// https://en.wikipedia.org/wiki/ASCII
714+
//
715+
// convertEncoding() function basically means convertToUtf8(), so when we convert ASCII string into UTF-8 it gets broken.
716+
if (strtolower($from) == 'us-ascii' && $to == 'UTF-8') {
717+
return $str;
718+
}
719+
705720
if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
706721
return iconv($from, $to.'//IGNORE', $str);
707722
} else {

0 commit comments

Comments
 (0)