private static function extractCharset(array $contentTypeParts)
    {
        foreach ($contentTypeParts as $part) {
            $elements = explode('=', $part);
            $key = trim(array_shift($elements));
            if (strtolower($key) === 'charset') {
                $value = trim(reset($elements));
                return $value ?: null;
            }
        }
        return null;
    }