fix title decoding error. unknown-8bit charset
This commit is contained in:
parent
f368033559
commit
61d0891b47
2 changed files with 18 additions and 1 deletions
|
@ -121,7 +121,7 @@ def _email_non_ascii_to_uft8(string):
|
|||
# characters inside e-mail in a way that won’t confuse e-mail servers
|
||||
subject = ""
|
||||
for v, charset in email.header.decode_header(string):
|
||||
if charset is None:
|
||||
if charset is None or charset == 'unknown-8bit':
|
||||
if type(v) is bytes:
|
||||
v = v.decode()
|
||||
subject = subject + v
|
||||
|
|
17
tests/test_imap.py
Normal file
17
tests/test_imap.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from stacosys.core.imap import _to_utf8, _email_non_ascii_to_uft8
|
||||
from email.header import Header
|
||||
|
||||
|
||||
class ImapTestCase(unittest.TestCase):
|
||||
|
||||
def test_utf8_decode(self):
|
||||
h = Header(s="Chez Darty vous avez re\udcc3\udca7u un nouvel aspirateur Vacuum gratuit jl8nz",
|
||||
charset="unknown-8bit")
|
||||
decoded = _email_non_ascii_to_uft8(h)
|
||||
self.assertEquals(decoded, "Chez Darty vous avez reçu un nouvel aspirateur Vacuum gratuit jl8nz")
|
Loading…
Add table
Reference in a new issue