예제 #1
0
        "=?utf-8?b?0JrQvtC90YbQtdCy0L7QuQ==?= <*****@*****.**>, Bob <*****@*****.**>, =?utf-8?b?0JLQuNC90YE=?= <*****@*****.**>"
    )
    eq_(u"Концевой <*****@*****.**>, Bob <*****@*****.**>, Винс <*****@*****.**>",
        v)

    v = '=?UTF-8?B?0J/RgNC+0LLQtdGA0Y/QtdC8INGA0YPRgdGB0LrQuNC1INGB0LDQsdC2?=\n =?UTF-8?B?0LXQutGC0Ysg0Lgg0Y7QvdC40LrQvtC0IOKYoA==?='
    eq_(u'Проверяем русские сабжекты и юникод ☠',
        encodedword.mime_to_unicode(v))

    v = '=?UTF-8?B?0J/RgNC+0LLQtdGA0Y/QtdC8INGA0YPRgdGB0LrQuNC1INGB0LDQsdC2?=\r\n =?UTF-8?B?0LXQutGC0Ysg0Lgg0Y7QvdC40LrQvtC0IOKYoA==?='
    eq_(u'Проверяем русские сабжекты и юникод ☠',
        encodedword.mime_to_unicode(v))

    v = u'=?utf-8?Q?Evaneos-Concepci=C3=B3n.pdf?='
    eq_(u'Evaneos-Concepción.pdf', encodedword.mime_to_unicode(v))


@patch.object(utils, '_guess_and_convert',
              Mock(side_effect=errors.EncodingError()))
def test_convert_to_utf8_unknown_encoding():
    v = "abc\x80def"
    eq_(u"abc\u20acdef", charsets.convert_to_unicode("windows-874", v))
    eq_(u"qwe", charsets.convert_to_unicode('X-UNKNOWN', u"qwe"))
    eq_(u"qwe", charsets.convert_to_unicode('ru_RU.KOI8-R', 'qwe'))
    eq_(u"qwe", charsets.convert_to_unicode('"utf-8"; format="flowed"', 'qwe'))


@patch.object(encodedword, 'unfold', Mock(side_effect=Exception))
def test_error_reporting():
    eq_("Sasha", encodedword.mime_to_unicode("Sasha"))
예제 #2
0
    eq_(u"Жека <*****@*****.**>, Концевой <*****@*****.**>", encodedword.mime_to_unicode(v))

    v = encodedword.mime_to_unicode("=?utf-8?b?0JrQvtC90YbQtdCy0L7QuQ==?= <*****@*****.**>, Bob <*****@*****.**>, =?utf-8?b?0JLQuNC90YE=?= <*****@*****.**>")
    eq_(u"Концевой <*****@*****.**>, Bob <*****@*****.**>, Винс <*****@*****.**>", v)

    v = '=?UTF-8?B?0J/RgNC+0LLQtdGA0Y/QtdC8INGA0YPRgdGB0LrQuNC1INGB0LDQsdC2?=\n =?UTF-8?B?0LXQutGC0Ysg0Lgg0Y7QvdC40LrQvtC0IOKYoA==?='
    eq_(u'Проверяем русские сабжекты и юникод ☠', encodedword.mime_to_unicode(v))

    v = '=?UTF-8?B?0J/RgNC+0LLQtdGA0Y/QtdC8INGA0YPRgdGB0LrQuNC1INGB0LDQsdC2?=\r\n =?UTF-8?B?0LXQutGC0Ysg0Lgg0Y7QvdC40LrQvtC0IOKYoA==?='
    eq_(u'Проверяем русские сабжекты и юникод ☠', encodedword.mime_to_unicode(v))

    v = '=?utf-8?Q?Evaneos-Concepci=C3=B3n.pdf?='
    eq_(u'Evaneos-Concepción.pdf', encodedword.mime_to_unicode(v))


@patch.object(utils, '_guess_and_convert', Mock(side_effect=errors.EncodingError()))
def test_convert_to_utf8_unknown_encoding():
    eq_(u"abc\u20acdef",
        charsets.convert_to_unicode("windows-874", b"abc\x80def"))
    eq_(u"qwe",
        charsets.convert_to_unicode('X-UNKNOWN', u'qwe'))
    eq_(u"qwe",
        charsets.convert_to_unicode('ru_RU.KOI8-R', 'qwe'))
    eq_(u"qwe",
        charsets.convert_to_unicode('"utf-8"; format="flowed"', 'qwe'))


@patch.object(encodedword, 'unfold', Mock(side_effect=Exception))
def test_error_reporting():
    eq_("Sasha", encodedword.mime_to_unicode("Sasha"))