@@ 100,13 100,18 @@ def attachment_from_string(data, filenam
if content_type is None or encoding is not None:
content_type = "application/octet-stream"
+ if isinstance(data, bytes):
+ data_str = lambda: data.decode(encoding or "UTF-8")
+ else:
+ data_str = lambda: data
+
maintype, subtype = content_type.split("/", 1)
if maintype == "text":
- attach = MIMEText(data, _subtype=subtype)
+ attach = MIMEText(data_str(), _subtype=subtype)
elif maintype == "message":
- attach = message_from_string(data)
+ attach = message_from_string(data_str())
elif maintype == "image":
attach = MIMEImage(data, _subtype=subtype)