|
5 | 5 | import base64, binascii, cgi, codecs, mimetypes, os |
6 | 6 | import quopri, random, re, rfc822, stat, sys, time |
7 | 7 | import socket, errno |
| 8 | +from traceback import format_exc |
8 | 9 |
|
9 | 10 | from roundup import roundupdb, date, hyperdb, password |
10 | 11 | from roundup.cgi import templating, cgitb, TranslationService |
|
22 | 23 | from roundup.anypy import http_ |
23 | 24 | from roundup.anypy import urllib_ |
24 | 25 |
|
| 26 | +from email.MIMEBase import MIMEBase |
| 27 | +from email.MIMEText import MIMEText |
| 28 | +from email.MIMEMultipart import MIMEMultipart |
| 29 | + |
25 | 30 | def initialiseSecurity(security): |
26 | 31 | '''Create some Permissions and Roles on the security object |
27 | 32 |
|
@@ -547,7 +552,7 @@ def inner_main(self): |
547 | 552 | if not self.instance.config.WEB_DEBUG: |
548 | 553 | exc_info = sys.exc_info() |
549 | 554 | subject = "Error: %s" % exc_info[1] |
550 | | - self.send_html_to_admin(subject, html) |
| 555 | + self.send_error_to_admin(subject, html, format_exc()) |
551 | 556 | self.write_html(self._(error_message)) |
552 | 557 | else: |
553 | 558 | self.write_html(html) |
@@ -1018,15 +1023,23 @@ def _serve_file(self, lmt, mime_type, content=None, filename=None): |
1018 | 1023 | self.additional_headers['Content-Length'] = str(len(content)) |
1019 | 1024 | self.write(content) |
1020 | 1025 |
|
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 | + """ |
1023 | 1033 | 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) |
1030 | 1043 | self.mailer.smtp_send(to, message.as_string()) |
1031 | 1044 |
|
1032 | 1045 | def renderFrontPage(self, message): |
@@ -1084,7 +1097,7 @@ def renderContext(self): |
1084 | 1097 | # If possible, send the HTML page template traceback |
1085 | 1098 | # to the administrator. |
1086 | 1099 | 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()) |
1088 | 1101 | # Now report the error to the user. |
1089 | 1102 | return self._(error_message) |
1090 | 1103 | except: |
|
0 commit comments