Merge "Use correct charset when create a text/* type MIME"
This commit is contained in:
commit
0b1742a547
@ -325,8 +325,13 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
|
||||
subtype = os.path.splitext(filename)[0]
|
||||
if content is None:
|
||||
content = ''
|
||||
msg = (text.MIMEText(content, _subtype=subtype)
|
||||
if subtype else text.MIMEText(content))
|
||||
try:
|
||||
content.encode('us-ascii')
|
||||
charset = 'us-ascii'
|
||||
except UnicodeEncodeError:
|
||||
charset = 'utf-8'
|
||||
msg = (text.MIMEText(content, _subtype=subtype, _charset=charset)
|
||||
if subtype else text.MIMEText(content, _charset=charset))
|
||||
|
||||
msg.add_header('Content-Disposition', 'attachment',
|
||||
filename=filename)
|
||||
|
@ -154,8 +154,15 @@ class MultipartMime(software_config.SoftwareConfig):
|
||||
|
||||
@staticmethod
|
||||
def _create_message(part, subtype, filename):
|
||||
msg = (text.MIMEText(part, _subtype=subtype)
|
||||
if subtype else text.MIMEText(part))
|
||||
charset = 'us-ascii'
|
||||
try:
|
||||
part.encode(charset)
|
||||
except UnicodeEncodeError:
|
||||
charset = 'utf-8'
|
||||
msg = (text.MIMEText(part, _subtype=subtype,
|
||||
_charset=charset)
|
||||
if subtype else text.MIMEText(part, _charset=charset))
|
||||
|
||||
if filename:
|
||||
msg.add_header('Content-Disposition', 'attachment',
|
||||
filename=filename)
|
||||
|
Loading…
Reference in New Issue
Block a user