diff --git a/src/Fetch/MIME.php b/src/Fetch/MIME.php index b63d72b..9ddbb4a 100644 --- a/src/Fetch/MIME.php +++ b/src/Fetch/MIME.php @@ -36,8 +36,14 @@ public static function decode($text, $targetCharset = 'utf-8') foreach (imap_mime_header_decode($text) as $word) { $ch = 'default' === $word->charset ? 'ascii' : $word->charset; + $text = $word->text; + if (function_exists('mb_convert_encoding')) { + // This will strip any unrecognised characters and ensure we avoid + // "Detected an incomplete multibyte character in input string" errors + $text = mb_convert_encoding($text, $ch, $ch); + } - $result .= iconv($ch, $targetCharset, $word->text); + $result .= iconv($ch, $targetCharset, $text); } return $result;