mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Always decode headers into unicode objects before assigning to model; fixes #12.
This commit is contained in:
parent
d3a766ffd6
commit
79e189fb22
5 changed files with 36 additions and 15 deletions
|
|
@ -10,16 +10,19 @@ logger = logging.getLogger(__name__)
|
|||
DEFAULT_CHARSET = getattr(
|
||||
settings,
|
||||
'DJANGO_MAILBOX_DEFAULT_CHARSET',
|
||||
'ascii',
|
||||
'iso8859-1',
|
||||
)
|
||||
|
||||
|
||||
def decode_header(header):
|
||||
def convert_header_to_unicode(header):
|
||||
try:
|
||||
return ''.join(
|
||||
[
|
||||
unicode(t[0], t[1] or DEFAULT_CHARSET)
|
||||
for t in email.header.decode_header(header)
|
||||
(
|
||||
bytestr.decode(encoding, 'REPLACE')
|
||||
if encoding
|
||||
else bytestr.decode(DEFAULT_CHARSET, 'REPLACE')
|
||||
) for bytestr, encoding in email.header.decode_header(header)
|
||||
]
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue