Skip to content

Commit 944b5df

Browse files
author
Ralf Schlatterbeck
committed
- fix handling of traceback mails to the roundup admin
- now this mail is a multipart/alternative with the HTML part *and* the traceback in text-format.
1 parent dbae47c commit 944b5df

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

roundup/cgi/client.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import base64, binascii, cgi, codecs, mimetypes, os
66
import quopri, random, re, rfc822, stat, sys, time
77
import socket, errno
8+
from traceback import format_exc
89

910
from roundup import roundupdb, date, hyperdb, password
1011
from roundup.cgi import templating, cgitb, TranslationService
@@ -22,6 +23,10 @@
2223
from roundup.anypy import http_
2324
from roundup.anypy import urllib_
2425

26+
from email.MIMEBase import MIMEBase
27+
from email.MIMEText import MIMEText
28+
from email.MIMEMultipart import MIMEMultipart
29+
2530
def initialiseSecurity(security):
2631
'''Create some Permissions and Roles on the security object
2732
@@ -547,7 +552,7 @@ def inner_main(self):
547552
if not self.instance.config.WEB_DEBUG:
548553
exc_info = sys.exc_info()
549554
subject = "Error: %s" % exc_info[1]
550-
self.send_html_to_admin(subject, html)
555+
self.send_error_to_admin(subject, html, format_exc())
551556
self.write_html(self._(error_message))
552557
else:
553558
self.write_html(html)
@@ -1018,15 +1023,23 @@ def _serve_file(self, lmt, mime_type, content=None, filename=None):
10181023
self.additional_headers['Content-Length'] = str(len(content))
10191024
self.write(content)
10201025

1021-
def send_html_to_admin(self, subject, content):
1022-
1026+
def send_error_to_admin(self, subject, html, txt):
1027+
"""Send traceback information to admin via email.
1028+
We send both, the formatted html (with more information) and
1029+
the text version of the traceback. We use
1030+
multipart/alternative so the receiver can chose which version
1031+
to display.
1032+
"""
10231033
to = [self.mailer.config.ADMIN_EMAIL]
1024-
message = self.mailer.get_standard_message(to, subject)
1025-
# delete existing content-type headers
1026-
del message['Content-type']
1027-
message['Content-type'] = 'text/html; charset=utf-8'
1028-
message.set_payload(content)
1029-
encode_quopri(message)
1034+
message = MIMEMultipart('alternative')
1035+
self.mailer.set_message_attributes(message, to, subject)
1036+
part = MIMEBase('text', 'html')
1037+
part.set_charset('utf-8')
1038+
part.set_payload(html)
1039+
encode_quopri(part)
1040+
message.attach(part)
1041+
part = MIMEText(txt)
1042+
message.attach(part)
10301043
self.mailer.smtp_send(to, message.as_string())
10311044

10321045
def renderFrontPage(self, message):
@@ -1084,7 +1097,7 @@ def renderContext(self):
10841097
# If possible, send the HTML page template traceback
10851098
# to the administrator.
10861099
subject = "Templating Error: %s" % exc_info[1]
1087-
self.send_html_to_admin(subject, cgitb.pt_html())
1100+
self.send_error_to_admin(subject, cgitb.pt_html(), format_exc())
10881101
# Now report the error to the user.
10891102
return self._(error_message)
10901103
except:

0 commit comments

Comments
 (0)