Mercurial > p > roundup > code
diff roundup/cgi/client.py @ 4543:d16d9bf655d8
- 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.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Fri, 07 Oct 2011 19:08:54 +0000 |
| parents | c1c395058dee |
| children | 35adb3950a39 |
line wrap: on
line diff
--- a/roundup/cgi/client.py Fri Oct 07 18:04:00 2011 +0000 +++ b/roundup/cgi/client.py Fri Oct 07 19:08:54 2011 +0000 @@ -5,6 +5,7 @@ import base64, binascii, cgi, codecs, mimetypes, os import quopri, random, re, rfc822, stat, sys, time import socket, errno +from traceback import format_exc from roundup import roundupdb, date, hyperdb, password from roundup.cgi import templating, cgitb, TranslationService @@ -22,6 +23,10 @@ from roundup.anypy import http_ from roundup.anypy import urllib_ +from email.MIMEBase import MIMEBase +from email.MIMEText import MIMEText +from email.MIMEMultipart import MIMEMultipart + def initialiseSecurity(security): '''Create some Permissions and Roles on the security object @@ -547,7 +552,7 @@ if not self.instance.config.WEB_DEBUG: exc_info = sys.exc_info() subject = "Error: %s" % exc_info[1] - self.send_html_to_admin(subject, html) + self.send_error_to_admin(subject, html, format_exc()) self.write_html(self._(error_message)) else: self.write_html(html) @@ -1018,15 +1023,23 @@ self.additional_headers['Content-Length'] = str(len(content)) self.write(content) - def send_html_to_admin(self, subject, content): - + def send_error_to_admin(self, subject, html, txt): + """Send traceback information to admin via email. + We send both, the formatted html (with more information) and + the text version of the traceback. We use + multipart/alternative so the receiver can chose which version + to display. + """ to = [self.mailer.config.ADMIN_EMAIL] - message = self.mailer.get_standard_message(to, subject) - # delete existing content-type headers - del message['Content-type'] - message['Content-type'] = 'text/html; charset=utf-8' - message.set_payload(content) - encode_quopri(message) + message = MIMEMultipart('alternative') + self.mailer.set_message_attributes(message, to, subject) + part = MIMEBase('text', 'html') + part.set_charset('utf-8') + part.set_payload(html) + encode_quopri(part) + message.attach(part) + part = MIMEText(txt) + message.attach(part) self.mailer.smtp_send(to, message.as_string()) def renderFrontPage(self, message): @@ -1084,7 +1097,7 @@ # If possible, send the HTML page template traceback # to the administrator. subject = "Templating Error: %s" % exc_info[1] - self.send_html_to_admin(subject, cgitb.pt_html()) + self.send_error_to_admin(subject, cgitb.pt_html(), format_exc()) # Now report the error to the user. return self._(error_message) except:
