src/IMAP/Message.php
public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {

        $from = EncodingAliases::get($from);
        $to = EncodingAliases::get($to);
        
        if ($from === $to) {
            return $str;
        }

        // We don't need to do convertEncoding() if charset is ASCII (us-ascii):
        //     ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded
        //     https://stackoverflow.com/a/11303410
        //
        // us-ascii is the same as ASCII:
        //     ASCII is the traditional name for the encoding system; the Internet Assigned Numbers Authority (IANA)
        //     prefers the updated name US-ASCII, which clarifies that this system was developed in the US and
        //     based on the typographical symbols predominantly in use there.
        //     https://en.wikipedia.org/wiki/ASCII
        //
        // convertEncoding() function basically means convertToUtf8(), so when we convert ASCII string into UTF-8 it gets broken.
        if (strtolower($from) == 'us-ascii' && $to == 'UTF-8') {
            return $str;
        }

        if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
            return @iconv($from, $to.'//IGNORE', $str);
        } else {
            if (!$from) {
                return mb_convert_encoding($str, $to);
            }
            return mb_convert_encoding($str, $to, $from);
        }
    }
public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {

        $from = EncodingAliases::get($from);
        $to = EncodingAliases::get($to);
        
        if ($from === $to) {
            return $str;
        }

        // We don't need to do convertEncoding() if charset is ASCII (us-ascii):
        //     ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded
        //     https://stackoverflow.com/a/11303410
        //
        // us-ascii is the same as ASCII:
        //     ASCII is the traditional name for the encoding system; the Internet Assigned Numbers Authority (IANA)
        //     prefers the updated name US-ASCII, which clarifies that this system was developed in the US and
        //     based on the typographical symbols predominantly in use there.
        //     https://en.wikipedia.org/wiki/ASCII
        //
        // convertEncoding() function basically means convertToUtf8(), so when we convert ASCII string into UTF-8 it gets broken.
        if (strtolower($from) == 'us-ascii' && $to == 'UTF-8') {
            return $str;
        }

        if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
            return @iconv($from, $to.'//IGNORE', $str);
        } else {
            if (!$from) {
                return mb_convert_encoding($str, $to);
            }
            return mb_convert_encoding($str, $to, $from);
        }
    }
public function convertEncoding ( $ str , $ from = "ISO-8859-2" , $ to = "UTF-8" ) { $ from = EncodingAliases :: get ( $ from ) ; $ to = EncodingAliases :: get ( $ to ) ; if ( $ from === $ to ) { return $ str ; } // We don't need to do convertEncoding() if charset is ASCII (us-ascii): //     ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded //     https://stackoverflow.com/a/11303410 // // us-ascii is the same as ASCII: //     ASCII is the traditional name for the encoding system; the Internet Assigned Numbers Authority (IANA) //     prefers the updated name US-ASCII, which clarifies that this system was developed in the US and //     based on the typographical symbols predominantly in use there. //     https://en.wikipedia.org/wiki/ASCII // // convertEncoding() function basically means convertToUtf8(), so when we convert ASCII string into UTF-8 it gets broken. if ( strtolower ( $ from ) == 'us-ascii' && $ to == 'UTF-8' ) { return $ str ; } if ( function_exists ( 'iconv' ) && $ from != 'UTF-7' && $ to != 'UTF-7' ) { return @ iconv ( $ from , $ to . '//IGNORE' , $ str ) ; } else { if ( ! $ from ) { return mb_convert_encoding ( $ str , $ to ) ; } return mb_convert_encoding ( $ str , $ to , $ from ) ; } }
Convert the encoding

@param $str
@param string $from
@param string $to

@return mixed|string
Convert the encoding