示例#1
0
文件: views.py 项目: wildone/pycopia
def emailrequest(request):
    """Send HTTP request headers to provided email address."""
    resp = framework.ResponseDocument(request,
                                      doc_constructor,
                                      title="Web Responder")
    recipients = request.GET.getlist("recipient") + request.GET.getlist(
        "rcpt") or resp.config.ADMINS
    # some basic validation. Mailer shuould validate the rest.
    recipients = filter(lambda name: "@" in name, recipients)
    recipients = filter(lambda name: "." in name, recipients)

    if recipients:
        rpt = XHTML.new_document()
        get_header_table(rpt.body, request.environ)

        body = ezmail.AutoMessage(EMAILBODY)
        body["Content-Disposition"] = 'inline'
        msg = ezmail.AutoMessage(str(rpt),
                                 mimetype=rpt.MIMETYPE,
                                 charset=rpt.encoding)
        msg["Content-Disposition"] = 'attachment; filename=headers.html'
        ezmail.mail([body, msg],
                    To=recipients,
                    subject="Webtool header request from %s." %
                    (request.environ.get("REMOTE_ADDR", "<unknown>"), ))

    get_header_table(resp.doc.content, request.environ)

    if recipients:
        resp.doc.content.new_para("Header data emailed to %s." %
                                  (", ".join(recipients), ))
    else:
        resp.doc.content.new_para("No valid email recipients.")
    return resp.finalize()
示例#2
0
 def __call__(self, timestamp, ip, community, pdu):
     tr = traps.TrapRecord(timestamp, ip, community, pdu)
     ezmail.mail(str(tr),
                 To=self._recipients,
                 From=self._from,
                 subject="Trap from %r" % (str(ip), ))
     return False
示例#3
0
def emailrequest(request):
    """Send HTTP request headers to provided email address."""
    resp = framework.ResponseDocument(request, doc_constructor, title="Web Responder")
    recipients = request.GET.getlist("recipient")+request.GET.getlist("rcpt") or resp.config.ADMINS
    # some basic validation. Mailer shuould validate the rest.
    recipients = filter(lambda name: "@" in name, recipients)
    recipients = filter(lambda name: "." in name, recipients)

    if recipients:
        rpt = XHTML.new_document()
        get_header_table(rpt.body, request.environ)

        body = ezmail.AutoMessage(EMAILBODY)
        body["Content-Disposition"] = 'inline'
        msg = ezmail.AutoMessage(str(rpt), mimetype=rpt.MIMETYPE, charset=rpt.encoding)
        msg["Content-Disposition"] = 'attachment; filename=headers.html'
        ezmail.mail([body, msg], To=recipients,
                  subject="Webtool header request from %s." % (request.environ.get("REMOTE_ADDR", "<unknown>"),))

    get_header_table(resp.doc.content, request.environ)

    if recipients:
        resp.doc.content.new_para("Header data emailed to %s." % (", ".join(recipients),))
    else:
        resp.doc.content.new_para("No valid email recipients.")
    return resp.finalize()
示例#4
0
def mailmessage(cp):
    parts = []
    # main message text and subject line
    body = CF.mail.body(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name)
    parts.append(body)
    subj = CF.mail.Subject(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name)
    # ogg file attachment
    oggfile = tempfile.NamedTemporaryFile(suffix=".ogg", prefix="voicemail", dir="/var/tmp")
    Vgetty.rmd2ogg(cp.inname, oggfile.name)
    oggfile.seek(0)
    ogg = ezmail.MIMEApplication.MIMEApplication(oggfile.read(), "ogg")
    ogg["Content-Disposition"] = "attachment; filename=%s" % (os.path.basename(cp.inname.replace("rmd", "ogg")), )
    oggfile.close()
    parts.append(ogg)
    # mail it!
    ezmail.mail(parts, subject=subj, To=CF.mail.To)
示例#5
0
 def finalize(self):
     """finalizing this Report sends off the email."""
     self.write(self._formatter.finalize())
     report = ezmail.MIMEText.MIMEText(self._fo.getvalue(), 
                     self._formatter.MIMETYPE.split("/")[1])
     report["Content-Disposition"] = "inline"
     self._message.attach(report)
     if self._logfile:
         try:
             lfd = open(self._logfile).read()
         except:
             pass # non-fatal
             print >>sys.stderr, "could not read or attach log file: %r" % (self._logfile,)
         else:
             logmsg = ezmail.MIMEText.MIMEText(lfd)
             logmsg["Content-Disposition"] = 'attachment; filename=%s' % (os.path.basename(self._logfile), )
             self._message.attach(logmsg)
     ezmail.mail(self._message)
示例#6
0
 def finalize(self):
     """finalizing this Report sends off the email."""
     self.write(self._formatter.finalize())
     report = ezmail.MIMEText.MIMEText(self._fo.getvalue(),
                     self._formatter.MIMETYPE.split("/")[1])
     report["Content-Disposition"] = "inline"
     self._message.attach(report)
     if self._attach_logfile and self._logfile:
         try:
             lfd = open(self._logfile, "rb").read()
         except:
             pass # non-fatal
         else:
             logmsg = ezmail.MIMEText.MIMEText(lfd, charset=chardet.detect(lfd))
             logmsg["Content-Disposition"] = 'attachment; filename=%s' % (
                     os.path.basename(self._logfile), )
             self._message.attach(logmsg)
     ezmail.mail(self._message)
示例#7
0
 def finalize(self):
     """finalizing this Report sends off the email."""
     self.write(self._formatter.finalize())
     report = ezmail.MIMEText.MIMEText(
         self._fo.getvalue(),
         self._formatter.MIMETYPE.split("/")[1])
     report["Content-Disposition"] = "inline"
     self._message.attach(report)
     if self._attach_logfile and self._logfile:
         try:
             lfd = open(self._logfile, "rb").read()
         except:
             pass  # non-fatal
         else:
             logmsg = ezmail.MIMEText.MIMEText(lfd,
                                               charset=chardet.detect(lfd))
             logmsg["Content-Disposition"] = 'attachment; filename=%s' % (
                 os.path.basename(self._logfile), )
             self._message.attach(logmsg)
     ezmail.mail(self._message)
示例#8
0
 def finalize(self):
     """finalizing this Report sends off the email."""
     self.write(self._formatter.finalize())
     report = ezmail.MIMEText.MIMEText(
         self._fo.getvalue(),
         self._formatter.MIMETYPE.split("/")[1])
     report["Content-Disposition"] = "inline"
     self._message.attach(report)
     if self._logfile:
         try:
             lfd = open(self._logfile).read()
         except:
             pass  # non-fatal
             print >> sys.stderr, "could not read or attach log file: %r" % (
                 self._logfile, )
         else:
             logmsg = ezmail.MIMEText.MIMEText(lfd)
             logmsg["Content-Disposition"] = 'attachment; filename=%s' % (
                 os.path.basename(self._logfile), )
             self._message.attach(logmsg)
     ezmail.mail(self._message)
示例#9
0
def mailmessage(cp):
    parts = []
    # main message text and subject line
    body = CF.mail.body(line=CF.lines.get(cp._device),
                        caller_id=cp.caller_id,
                        caller_name=cp.caller_name)
    parts.append(body)
    subj = CF.mail.Subject(line=CF.lines.get(cp._device),
                           caller_id=cp.caller_id,
                           caller_name=cp.caller_name)
    # ogg file attachment
    oggfile = tempfile.NamedTemporaryFile(suffix=".ogg",
                                          prefix="voicemail",
                                          dir="/var/tmp")
    Vgetty.rmd2ogg(cp.inname, oggfile.name)
    oggfile.seek(0)
    ogg = ezmail.MIMEApplication.MIMEApplication(oggfile.read(), "ogg")
    ogg["Content-Disposition"] = "attachment; filename=%s" % (os.path.basename(
        cp.inname.replace("rmd", "ogg")), )
    oggfile.close()
    parts.append(ogg)
    # mail it!
    ezmail.mail(parts, subject=subj, To=CF.mail.To)
示例#10
0
 def __call__(self, timestamp, ip, community, pdu):
     tr = traps.TrapRecord(timestamp, ip, community, pdu)
     ezmail.mail(str(tr), To=self._recipients, From=self._from,
                 subject="Trap from %r" % (str(ip),))
     return False