Skip to content

two issues found and corrected #208

Description

@beskhu

I found a bug on "processStructure" in the class Message
Some charsets are not declared with caps, which can lead to improper check by the function in_array on mb_list_encodings()... This can be corrected using strtoupper :

            if (function_exists('mb_convert_encoding')) {
                if (!in_array(strtoupper($parameters['charset']), mb_list_encodings())) {
                    if ($structure->encoding === 0) {
                        $parameters['charset'] = 'US-ASCII';
                    } else {
                        $parameters['charset'] = 'UTF-8';
                    }
                }

                $messageBody = @mb_convert_encoding($messageBody, self::$charset, $parameters['charset']);
                $mb_converted = true;
            }

I found an improvement on "decode" in the class MIME... Sometimes the charset in subjects are badly declared and wrongly interpreted as ASCII, and conversion can be handled doing like this :

public static function decode($text, $targetCharset = 'UTF-8')
{
    if (null === $text) {
        return null;
    }

    $result = '';

    foreach (imap_mime_header_decode($text) as $word) {
        $ch = 'default' === $word->charset ? 'ascii' : $word->charset;
        if ($ch==="ascii" && ($c=strtoupper(mb_detect_encoding($word->text)))!==strtoupper($ch)) {
        	$ch=$c;
        }
        $result .= iconv($ch, $targetCharset, $word->text);
    }

    return $result;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions