Exemplo n.º 1
0
def create_form_from_mail(config, mail, tmpfn):
    subject = mail.get("Subject", "[no subject]")
    sender = mail.get("From", "Unknown <*****@*****.**>")
    
    xml = None
    body = ""

    if mail.is_multipart():
        html = None
        for part in mail.walk():
            if part.get_content_maintype() == "multipart":
                continue
            elif part.get_content_type() == "d-rats/form_xml":
                xml = str(part.get_payload())
                break # A form payload trumps all
            elif part.get_content_type() == "text/plain":
                body += part.get_payload(decode=True)
            elif part.get_content_type() == "text/html":
                html = part.get_payload(decode=True)
        if not body:
            body = html
    else:
        body = mail.get_payload(decode=True)

    if not body and not xml:
        raise Exception("Unable to find a usable part")

    messageid = mail.get("Message-ID", time.strftime("%m%d%Y%H%M%S"))
    if not msgrouting.msg_lock(tmpfn):
        print "AIEE: Unable to lock incoming email message file!"

    if xml:
        f = file(tmpfn, "w")
        f.write(xml)
        f.close()
        form = formgui.FormFile(tmpfn)
        recip = form.get_recipient_string()
        if "%" in recip:
            recip, addr = recip.split("%", 1)
            recip = recip.upper()
    else:
        print "Email from %s: %s" % (sender, subject)

        recip, addr = rfc822.parseaddr(mail.get("To", "UNKNOWN"))

        efn = os.path.join(config.form_source_dir(), "email.xml")
        form = formgui.FormFile(efn)
        form.set_field_value("_auto_sender", sender)
        form.set_field_value("recipient", recip)
        form.set_field_value("subject", "EMAIL: %s" % subject)
        form.set_field_value("message", utils.filter_to_ascii(body))
        form.set_path_src(sender.strip())
        form.set_path_dst(recip.strip())
        form.set_path_mid(messageid)

    form.save_to(tmpfn)

    return form
Exemplo n.º 2
0
def create_form_from_mail(config, mail, tmpfn):
    subject = mail.get("Subject", "[no subject]")
    sender = mail.get("From", "Unknown <*****@*****.**>")

    xml = None
    body = ""

    if mail.is_multipart():
        html = None
        for part in mail.walk():
            if part.get_content_maintype() == "multipart":
                continue
            elif part.get_content_type() == "d-rats/form_xml":
                xml = str(part.get_payload())
                break  # A form payload trumps all
            elif part.get_content_type() == "text/plain":
                body += part.get_payload(decode=True)
            elif part.get_content_type() == "text/html":
                html = part.get_payload(decode=True)
        if not body:
            body = html
    else:
        body = mail.get_payload(decode=True)

    if not body and not xml:
        raise Exception("Unable to find a usable part")

    messageid = mail.get("Message-ID", time.strftime("%m%d%Y%H%M%S"))
    if not msgrouting.msg_lock(tmpfn):
        print "AIEE: Unable to lock incoming email message file!"

    if xml:
        f = file(tmpfn, "w")
        f.write(xml)
        f.close()
        form = formgui.FormFile(tmpfn)
        recip = form.get_recipient_string()
        if "%" in recip:
            recip, addr = recip.split("%", 1)
            recip = recip.upper()
    else:
        print "Email from %s: %s" % (sender, subject)

        recip, addr = rfc822.parseaddr(mail.get("To", "UNKNOWN"))

        efn = os.path.join(config.form_source_dir(), "email.xml")
        form = formgui.FormFile(efn)
        form.set_field_value("_auto_sender", sender)
        form.set_field_value("recipient", recip)
        form.set_field_value("subject", "EMAIL: %s" % subject)
        form.set_field_value("message", utils.filter_to_ascii(body))
        form.set_path_src(sender.strip())
        form.set_path_dst(recip.strip())
        form.set_path_mid(messageid)

    form.save_to(tmpfn)

    return form
Exemplo n.º 3
0
    def worker(self, path):
        md = os.path.join(self.coord.config.form_store_dir(), _("Inbox"))
        newfn = time.strftime(os.path.join(md, "form_%m%d%Y_%H%M%S.xml"))
        if not msgrouting.msg_lock(newfn):
            print "AIEE! Unable to lock incoming new message file!"

        fn = self.session.recv_file(newfn)

        name = "%s %s %s" % (self.session.name, _("from"),
                             self.session.get_station())

        if fn == newfn:
            form = formgui.FormFile(fn)
            form.add_path_element(self.coord.config.get("user", "callsign"))
            form.save_to(fn)

            self.completed("form")
            self.coord.session_newform(self.session, fn)
        else:
            self.failed()
            print "<--- Form transfer failed -->"
Exemplo n.º 4
0
    def worker(self, path):
        md = os.path.join(self.coord.config.form_store_dir(), _("Inbox"))
        newfn = time.strftime(os.path.join(md, "form_%m%d%Y_%H%M%S.xml"))
        if not msgrouting.msg_lock(newfn):
            print "AIEE! Unable to lock incoming new message file!"

        fn = self.session.recv_file(newfn)

        name = "%s %s %s" % (self.session.name,
                               _("from"),
                               self.session.get_station())

        if fn == newfn:
            form = formgui.FormFile(fn)
            form.add_path_element(self.coord.config.get("user", "callsign"))
            form.save_to(fn)

            self.completed("form")
            self.coord.session_newform(self.session, fn)
        else:
            self.failed()
            print "<--- Form transfer failed -->"