mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Minor PR cleanup and reorganization.
This commit is contained in:
parent
9954b74eae
commit
0f3cb09f94
3 changed files with 51 additions and 31 deletions
31
django_mailbox/utils.py
Normal file
31
django_mailbox/utils.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import email.header
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DEFAULT_CHARSET = getattr(
|
||||
settings,
|
||||
'DJANGO_MAILBOX_DEFAULT_CHARSET',
|
||||
'ascii',
|
||||
)
|
||||
|
||||
|
||||
def decode_header(header):
|
||||
try:
|
||||
return ''.join(
|
||||
[
|
||||
unicode(t[0], t[1] or DEFAULT_CHARSET)
|
||||
for t in email.header.decode_header(header)
|
||||
]
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
logger.exception(
|
||||
'Errors encountered decoding header %s into encoding %s.',
|
||||
header,
|
||||
DEFAULT_CHARSET,
|
||||
)
|
||||
return unicode(header, DEFAULT_CHARSET, 'replace')
|
||||
Loading…
Add table
Add a link
Reference in a new issue