def _getHTMLClone(self, help_topic=None): """Gets a clone of the HTML, with the footer timestamped, and version information added, ready to be modified and sent to the browser.""" clone = self.html.clone() timestamp = time.strftime("%H:%M on %A %B %d %Y", time.localtime()) clone.footer.timestamp = timestamp v = Version.get_current_version() clone.footer.version = v.get_long_version(self.app_for_version) if help_topic: clone.helplink.href = "help?topic=%s" % (help_topic,) return clone
def onSubmitreport(self, from_addr, message, subject, attach): """Send the help message/bug report to the specified address.""" import mimetypes from email import Encoders from email.MIMEBase import MIMEBase from email.MIMEAudio import MIMEAudio from email.MIMEMultipart import MIMEMultipart from email.MIMEImage import MIMEImage from email.MIMEText import MIMEText if not self._verifyEnteredDetails(from_addr, subject, message): self._writePreamble(_("Error"), ("help", _("Help"))) self.write( self._buildBox( _("Error"), "status.gif", _( "You must fill in the details that " "describe your specific problem " "before you can send the message." ), ) ) else: self._writePreamble(_("Sent"), ("help", _("Help"))) mailer = smtplib.SMTP(options["smtpproxy", "remote_servers"][0]) outer = MIMEMultipart() outer["Subject"] = subject outer["To"] = '"SpamBayes Mailing List" <*****@*****.**>' outer["CC"] = from_addr outer["From"] = from_addr v = Version.get_current_version() outer["X-Mailer"] = v.get_long_version(self.app_for_version) outer.preamble = wrap(message) outer.epilogue = "" try: ctype, encoding = mimetypes.guess_type(attach) if ctype is None or encoding is not None: ctype = "application/octet-stream" maintype, subtype = ctype.split("/", 1) if maintype == "text": fp = open(attach) msg = MIMEText(fp.read(), _subtype=subtype) fp.close() elif maintype == "image": fp = open(attach, "rb") msg = MIMEImage(fp.read(), _subtype=subtype) fp.close() elif maintype == "audio": fp = open(attach, "rb") msg = MIMEAudio(fp.read(), _subtype=subtype) fp.close() else: fp = open(attach, "rb") msg = MIMEBase(maintype, subtype) msg.set_payload(fp.read()) fp.close() Encoders.encode_base64(msg) except IOError: pass else: msg.add_header("Content-Disposition", "attachment", filename=os.path.basename(attach)) outer.attach(msg) msg = MIMEText(wrap(message)) outer.attach(msg) recips = [] for r in ["*****@*****.**", from_addr]: if r: recips.append(r) mailer.sendmail(from_addr, recips, outer.as_string()) self.write(_("Sent message. Please do not send again, or " "refresh this page!")) self._writePostamble()
def onBugreport(self): """Create a message to post to [email protected] that hopefully has enough information for us to help this person with their problem.""" self._writePreamble(_("Send Help Message"), ("help", _("Help"))) report = self.html.bugreport.clone() v = Version.get_current_version() sb_ver = v.get_long_version(self.app_for_version) if hasattr(sys, "frozen"): sb_type = "binary" else: sb_type = "source" py_ver = sys.version try: os_name = "Windows %d.%d.%d.%d (%s)" % sys.getwindowsversion() except AttributeError: os_name = os.name report.message_body = ( "I am using %s (%s), with version %s of " "Python; my operating system is %s. I have " "trained %d ham and %d spam.\n\nThe problem " "I am having is [DESCRIBE YOUR PROBLEM HERE] " % (sb_ver, sb_type, py_ver, os_name, self.classifier.nham, self.classifier.nspam) ) remote_servers = options["pop3proxy", "remote_servers"] if remote_servers: domain_guess = remote_servers[0] for pre in ["pop.", "pop3.", "mail."]: if domain_guess.startswith(pre): domain_guess = domain_guess[len(pre) :] else: domain_guess = "[YOUR ISP]" report.from_addr.value = "[YOUR EMAIL ADDRESS]@%s" % (domain_guess,) report.subject.value = "Problem with %s: [PROBLEM SUMMARY]" % (self.app_for_version,) try: import win32api except ImportError: pass else: if hasattr(sys, "frozen"): temp_dir = win32api.GetTempPath() for name in ["SpamBayesService", "SpamBayesServer"]: for i in xrange(3): pn = os.path.join(temp_dir, "%s%d.log" % (name, (i + 1))) if os.path.exists(pn): report.file.type = "text" report.file.value = pn break if report.file.value: break try: smtp_server = options["smtpproxy", "remote_servers"][0] except IndexError: smtp_server = None if not smtp_server: self.write( self._buildBox( _("Warning"), "status.gif", _( "You will be unable to send this message from " "this page, as you do not have your SMTP " "server's details entered in your configuration. " "Please either <a href='config'>enter those " "details</a>, or copy the text below into your " "regular mail application." ), ) ) del report.submitrow self.write(report) self._writePostamble()