Esempio n. 1
0
    def test_alterative(self):
        msg = mail.MailRequest("", "", "", EXAMPLE_ALT)
        make_email(msg, self.inbox)
        email = models.Email.objects.get()
        message_object = make_message(email)
        new_msg = mail.MailRequest("", "", "", str(message_object))

        self.assertEqual(len(msg.keys()), len(new_msg.keys()))
        self.assertEqual(len(list(msg.walk())), len(list(new_msg.walk())))
Esempio n. 2
0
    def test_encoders_used(self):
        # make message with base64 part, uuencode part, 8bit part, 7bit part,
        # quopri part, and some invalid part
        body_data = b"Hello\n\nHow are you?\n"
        email = factories.EmailFactory(inbox=self.inbox)
        body = factories.BodyFactory(data=body_data)
        first_part = factories.PartListFactory(
            email=email, body=factories.BodyFactory(data=b""))
        factories.HeaderFactory(
            part=first_part,
            name="Content-Type",
            data="multipart/mixed; boundary=\"=-3BRZDE/skgKPPh+RuFa/\"")

        encodings = {
            "base64": check_base64,
            "quoted-printable": check_quopri,
            "uuencode": check_uu,
            "x-uuencode": check_uu,
            "uue": check_uu,
            "x-uue": check_uu,
            "7-bit": check_noop,
            "8-bit": check_noop,
            "9-bit": check_unknown,  # unknown encoding
        }

        for enc in encodings.keys():
            part = factories.PartListFactory(email=email,
                                             parent=first_part,
                                             body=body)
            factories.HeaderFactory(part=part,
                                    name="Content-Type",
                                    data="text/plain; name=\"my-file.txt\"")
            factories.HeaderFactory(part=part,
                                    name="Content-Transfer-Encoding",
                                    data=enc)

        # finally, make a part without content headers
        factories.PartListFactory(email=email, parent=first_part, body=body)

        # and now export
        message_object = make_message(email)

        for message_part in message_object.walk():
            ct = message_part.get("Content-Type", None)
            cte = message_part.get("Content-Transfer-Encoding", None)
            if ct is None:
                # default is to assume 7-bit
                check_noop(message_part, body_data)
                self.assertEqual(message_part.get_payload(decode=True),
                                 body_data)
            elif ct.startswith("multipart/mixed"):
                pass
            else:
                encodings[cte](message_part, body_data)
                self.assertEqual(message_part.get_payload(decode=True),
                                 body_data)
Esempio n. 3
0
    def test_bad_css(self):
        """This test uses an example email that causes issue #47"""
        msg = mail.MailRequest("", "", "", EXAMPLE_PREMAILER_BROKEN_CSS)
        make_email(msg, self.inbox)
        email = models.Email.objects.get()
        message_object = make_message(email)
        new_msg = mail.MailRequest("", "", "", str(message_object))

        self.assertEqual(len(msg.keys()), len(new_msg.keys()))
        self.assertEqual(len(list(msg.walk())), len(list(new_msg.walk())))
Esempio n. 4
0
    def test_signed_forwarded_digest(self):
        msg = mail.MailRequest("", "", "", EXAMPLE_SIGNED_FORWARDED_DIGEST)
        make_email(msg, self.inbox)
        self.email = models.Email.objects.get()
        email = models.Email.objects.get()
        message_object = make_message(email)
        new_msg = mail.MailRequest("", "", "", str(message_object))

        self.assertEqual(len(msg.keys()), len(new_msg.keys()))
        self.assertEqual(len(list(msg.walk())), len(list(new_msg.walk())))
Esempio n. 5
0
def liberate_message(mail_path, inbox, email_id):
    """ Take email from database and put on filesystem """
    maildir = mailbox.Maildir(mail_path, factory=None).get_folder(inbox)

    try:
        msg = Email.objects.get(id=email_id, flags=~Email.flags.deleted)
        msg = utils.make_message(msg)
        maildir.add(msg.as_string())
    except Exception as exc:
        msg_id = hex(int(email_id))[2:]
        log.warning("Exception processing %s", msg_id, exc_info=exc)
        return msg_id
Esempio n. 6
0
def liberate_message(mail_path, inbox, email_id):
    """ Take email from database and put on filesystem """
    maildir = mailbox.Maildir(mail_path, factory=None).get_folder(inbox)

    try:
        msg = Email.objects.get(id=email_id, flags=~Email.flags.deleted)
        msg = utils.make_message(msg)
        maildir.add(msg.as_string())
    except Exception, exc:
        msg_id = hex(int(email_id))[2:]
        log.warning("Exception processing %s", msg_id, exc_info=exc)
        return msg_id