Skip to content

Commit

Permalink
fixed mailer attachment filename encoding, thanks dgmanns
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Aug 6, 2023
1 parent a984f1f commit b6cd403
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions py4web/utils/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,15 @@ def __init__(
if filename is None:
raise Exception("Missing attachment name")
payload = payload.read()
# FIXME PY3 can be used to_native?
filename = filename.encode(encoding)
if content_type is None:
content_type = mimetypes.guess_type(filename)
content_type = mimetypes.guess_type(filename)[0]
self.my_filename = filename
self.my_payload = payload
MIMEBase.__init__(self, *content_type.split("/", 1))
self.set_payload(payload)
self["Content-Disposition"] = 'attachment; filename="%s"' % to_native(
filename, encoding
)
self["Content-Disposition"] = f'attachment; filename="{filename}"'
if content_id is not None:
self["Content-Id"] = "<%s>" % to_native(content_id, encoding)
self["Content-Id"] = f"<{content_id}>"
Encoders.encode_base64(self)

def __init__(self, server=None, sender=None, login=None, tls=True, ssl=False):
Expand Down

0 comments on commit b6cd403

Please sign in to comment.