def test_header_from_mime_encoding(): assert not encoding.header_from_mime_encoding(None) assert_equal(len(BAD_HEADERS), len(encoding.header_from_mime_encoding(BAD_HEADERS))) for i, header in enumerate(BAD_HEADERS): assert_equal(DECODED_HEADERS[i], encoding.header_from_mime_encoding(header))
def test_headers_round_trip(): # round trip the headers to make sure they convert reliably back and forth for header in BAD_HEADERS: original = encoding.header_from_mime_encoding(header) assert original assert "=?" not in original and "?=" not in original, "Didn't decode: %r" % (encoding.SCANNER.scan(header),) encoded = encoding.header_to_mime_encoding(original) assert encoded return_original = encoding.header_from_mime_encoding(encoded) assert_equal(original, return_original) return_encoded = encoding.header_to_mime_encoding(return_original) assert_equal(encoded, return_encoded)
def test_headers_round_trip(): # round trip the headers to make sure they convert reliably back and forth for header in BAD_HEADERS: original = encoding.header_from_mime_encoding(header) assert original assert "=?" not in original and "?=" not in original, "Didn't decode: %r" % (encoding.SCANNER.scan(header),) encoded = encoding.header_to_mime_encoding(original) assert encoded return_original = encoding.header_from_mime_encoding(encoded) assert_equal(original, return_original) return_encoded = encoding.header_to_mime_encoding(return_original) assert_equal(encoded, return_encoded)
def test_header_from_mime_encoding(): assert not encoding.header_from_mime_encoding(None) assert_equal(len(BAD_HEADERS), len(encoding.header_from_mime_encoding(BAD_HEADERS))) for i, header in enumerate(BAD_HEADERS): assert_equal(DECODED_HEADERS[i], encoding.header_from_mime_encoding(header))
def test_dumb_shit(): # this is a sample of possibly the worst case Mutt can produce idiot = '=?iso-8859-1?B?SOlhdnkgTel05WwgVW7uY/hk?=\n\t=?iso-8859-1?Q?=E9?=' should_be = u'H\xe9avy M\xe9t\xe5l Un\xeec\xf8d\xe9' assert_equal(encoding.header_from_mime_encoding(idiot), should_be)
BAD_HEADERS = [ u'"\u8003\u53d6\u5206\u4eab" <*****@*****.**>'.encode('utf-8'), '"=?windows-1251?B?RXhxdWlzaXRlIFJlcGxpY2E=?="\n\t<*****@*****.**>', '=?iso-2022-jp?B?Zmlicm91c19mYXZvcmF0ZUB5YWhvby5jby5qcA==?=<*****@*****.**>', '=?windows-1252?Q?Global_Leadership_in_HandCare_-_Consumer,\n\t_Professional_and_Industrial_Products_OTC_:_FLKI?=', '=?windows-1252?q?Global_Leadership_in_Handcare_-_Consumer, _Auto,\n\t_Professional_&_Industrial_Products_-_OTC_:_FLKI?=', 'I am just normal.', '=?koi8-r?B?WW91ciBtYW6ScyBzdGFtaW5hIHdpbGwgY29tZSBiYWNrIHRvIHlvdSBs?=\n\t=?koi8-r?B?aWtlIGEgYm9vbWVyYW5nLg==?=', '=?koi8-r?B?WW91IGNhbiBiZSBvbiB0b3AgaW4gYmVkcm9vbSBhZ2FpbiCWIGp1c3Qg?=\n\t=?koi8-r?B?YXNrIHVzIGZvciBhZHZpY2Uu?=', '"=?koi8-r?B?5MXMz9DSz8na18/E09TXzw==?=" <*****@*****.**>', '=?utf-8?b?IumrlOiCsuWckuWNgOermSDihpIg6ZW35bqa6Yar6Zmi56uZIOKGkiDmlofljJbk?=\n =?utf-8?b?uInot6/nq5kiIDx2Z3hkcmp5Y2lAZG5zLmh0Lm5ldC50dz4=?=', '=?iso-8859-1?B?SOlhdnkgTel05WwgVW7uY/hk?=\n\t=?iso-8859-1?Q?=E9?=', ] DECODED_HEADERS = encoding.header_from_mime_encoding(BAD_HEADERS) NORMALIZED_HEADERS = [encoding.header_to_mime_encoding(x) for x in DECODED_HEADERS] def test_MailBase(): the_subject = u'p\xf6stal' m = encoding.MailBase() m['To'] = "testing@localhost" m['Subject'] = the_subject assert m['To'] == "testing@localhost" assert m['TO'] == m['To'] assert m['to'] == m['To']
def test_dumb_shit(): # this is a sample of possibly the worst case Mutt can produce idiot = '=?iso-8859-1?B?SOlhdnkgTel05WwgVW7uY/hk?=\n\t=?iso-8859-1?Q?=E9?=' should_be = u'H\xe9avy M\xe9t\xe5l Un\xeec\xf8d\xe9' assert_equal(encoding.header_from_mime_encoding(idiot), should_be)
BAD_HEADERS = [ u'"\u8003\u53d6\u5206\u4eab" <*****@*****.**>'.encode('utf-8'), '"=?windows-1251?B?RXhxdWlzaXRlIFJlcGxpY2E=?="\n\t<*****@*****.**>', '=?iso-2022-jp?B?Zmlicm91c19mYXZvcmF0ZUB5YWhvby5jby5qcA==?=<*****@*****.**>', '=?windows-1252?Q?Global_Leadership_in_HandCare_-_Consumer,\n\t_Professional_and_Industrial_Products_OTC_:_FLKI?=', '=?windows-1252?q?Global_Leadership_in_Handcare_-_Consumer, _Auto,\n\t_Professional_&_Industrial_Products_-_OTC_:_FLKI?=', 'I am just normal.', '=?koi8-r?B?WW91ciBtYW6ScyBzdGFtaW5hIHdpbGwgY29tZSBiYWNrIHRvIHlvdSBs?=\n\t=?koi8-r?B?aWtlIGEgYm9vbWVyYW5nLg==?=', '=?koi8-r?B?WW91IGNhbiBiZSBvbiB0b3AgaW4gYmVkcm9vbSBhZ2FpbiCWIGp1c3Qg?=\n\t=?koi8-r?B?YXNrIHVzIGZvciBhZHZpY2Uu?=', '"=?koi8-r?B?5MXMz9DSz8na18/E09TXzw==?=" <*****@*****.**>', '=?utf-8?b?IumrlOiCsuWckuWNgOermSDihpIg6ZW35bqa6Yar6Zmi56uZIOKGkiDmlofljJbk?=\n =?utf-8?b?uInot6/nq5kiIDx2Z3hkcmp5Y2lAZG5zLmh0Lm5ldC50dz4=?=', '=?iso-8859-1?B?SOlhdnkgTel05WwgVW7uY/hk?=\n\t=?iso-8859-1?Q?=E9?=', ] DECODED_HEADERS = encoding.header_from_mime_encoding(BAD_HEADERS) NORMALIZED_HEADERS = [ encoding.header_to_mime_encoding(x) for x in DECODED_HEADERS ] def test_MailBase(): the_subject = u'p\xf6stal' m = encoding.MailBase() m['To'] = "testing@localhost" m['Subject'] = the_subject assert m['To'] == "testing@localhost" assert m['TO'] == m['To']