greco: "detect" plain text attachment encoding (#47236)
This commit is contained in:
parent
17e733f2cc
commit
bb943bfbde
|
@ -134,7 +134,13 @@ class Greco(BaseResource):
|
|||
content_type = attachment.get('content_type') or 'application/octet-stream'
|
||||
maintype, subtype = content_type.split('/', 1)
|
||||
if maintype == 'text':
|
||||
part = MIMEText(content, _subtype=subtype)
|
||||
for encoding in ('utf-8', 'iso-8859-15'):
|
||||
try:
|
||||
content.decode(encoding)
|
||||
break
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
part = MIMEText(content, _subtype=subtype, _charset=encoding)
|
||||
else:
|
||||
part = MIMEBase(maintype, subtype, name=filename)
|
||||
attachment['real_bytes'] = content
|
||||
|
|
Loading…
Reference in New Issue