Skip to content

Send exceptions using quoted-printable encoding to avoid line length limits #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions webware/ExceptionHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from random import randint
from time import time, localtime

import email
from email.message import Message
from email.utils import formatdate

Expand Down Expand Up @@ -489,6 +490,12 @@ def emailException(self, htmlErrMsg):
Send the exception via mail, either as an attachment,
or as the body of the mail.
"""

# we use quoted-printable encoding, which will automatically split long lines.
# this is important because tracebacks can contain long representations of python
# data, longer than the max line length smtp servers will accept (a typical limit is 990 bytes).
cs = email.charset.Charset('utf-8')
cs.body_encoding = email.charset.QP
message = Message()

# Construct the message headers
Expand Down Expand Up @@ -519,19 +526,18 @@ def emailException(self, htmlErrMsg):
message.attach(part)
part = Message()
# now add htmlErrMsg
part.add_header('Content-Transfer-Encoding', '7bit')
part.add_header(
'Content-Description',
'HTML version of Webware error message')
part.add_header(
'Content-Disposition',
'attachment', filename='WebwareErrorMsg.html')
part.set_type('text/html')
part.set_payload(htmlErrMsg)
part.set_payload(htmlErrMsg, charset=cs)
message.attach(part)
else:
message.set_type('text/html')
message.set_payload(htmlErrMsg, 'us-ascii')
message.set_payload(htmlErrMsg, charset=cs)

# Send the message
server = self.setting('ErrorEmailServer')
Expand Down