Skip to content

Commit

Permalink
Fixed string encoding converting for broken & WIN-1256 strings
Browse files Browse the repository at this point in the history
Closes #46
  • Loading branch information
barbushin committed Apr 20, 2015
1 parent 1c55597 commit 79b689d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/ImapMailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,29 +568,25 @@ protected function decodeRFC2231($string, $charset = 'utf-8') {
}
return $string;
}

/**
* Converts a string from one encoding to another.
* @param string $string
* @param string $fromEncoding
* @param string $toEncoding
* @return string Converted string if conversion was successful, or the original string if not
*/
protected function convertStringEncoding($string, $fromEncoding, $toEncoding)
{
$convertedString = false;
if ($string && $fromEncoding !== $toEncoding) {
if (extension_loaded('mbstring')) {
$convertedString = mb_convert_encoding($string, $toEncoding, $fromEncoding);
}
else {
$convertedString = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);
protected function convertStringEncoding($string, $fromEncoding, $toEncoding) {
$convertedString = null;
if($string && $fromEncoding != $toEncoding) {
$convertedString = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);
if(!$convertedString && extension_loaded('mbstring')) {
$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
}
}
// If conversion does not occur or is not successful, return the original string
return ($convertedString !== false) ? $convertedString : $string;
return $convertedString ?: $string;
}

public function __destruct() {
$this->disconnect();
}
Expand Down

0 comments on commit 79b689d

Please sign in to comment.