コード例 #1
0
    def test_alterative(self):
        self.msg = mail.MailRequest("", "", "", EXAMPLE_ALT)
        make_email(self.msg, self.inbox)
        self.email = models.Email.objects.get()

        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context["email"]["bodies"]), 1)
コード例 #2
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())))
コード例 #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())))
コード例 #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())))
コード例 #5
0
    def test_unicode(self):
        """This test uses an example email that contains unicode chars"""
        msg = mail.MailRequest("", "", "", EXAMPLE_MISSING_CTE)
        make_email(msg, self.inbox)
        email = models.Email.objects.get()
        message_object = make_message(email)
        new_msg = mail.MailRequest("", "", "",
                                   message_object.as_bytes().decode())

        self.assertEqual(len(msg.keys()), len(new_msg.keys()))
        self.assertEqual(len(list(msg.walk())), len(list(new_msg.walk())))
コード例 #6
0
    def test_premime(self):
        self.msg = mail.MailRequest("", "", "", EXAMPLE_PREMIME_EMAIL)
        make_email(self.msg, self.inbox)
        self.email = models.Email.objects.get()

        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)

        self.assertEqual(self.email.parts.all().count(), 1)
        self.assertEqual(len(response.context["email"]["bodies"]), 1)
        self.assertEqual(response.context["email"]["bodies"][0],
                         "<pre>Hi,\n\nHow are you?\n\nThanks,\nTest\n</pre>")
コード例 #7
0
    def test_bad_css(self):
        """This test uses an example email that causes issue #47"""
        self.msg = mail.MailRequest("", "", "", EXAMPLE_PREMAILER_BROKEN_CSS)
        make_email(self.msg, self.inbox)
        self.email = models.Email.objects.get()

        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context["email"]["bodies"]), 1)
        self.assertNotIn(
            "Part of this message could not be parsed - it may not display correctly",
            response.content.decode("utf-8"))
コード例 #8
0
    def test_digest(self):
        self.msg = mail.MailRequest("", "", "", EXAMPLE_DIGEST)
        make_email(self.msg, self.inbox)
        self.email = models.Email.objects.get()

        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)

        # this email should display all leaves
        leaf_part_count = len([
            i for i in self.email.parts.all() if i.is_leaf_node()
            and i.content_type != "application/pgp-signature"
        ])
        self.assertEqual(len(response.context["email"]["bodies"]),
                         leaf_part_count)
コード例 #9
0
    def test_signed_forwarded_digest(self):
        self.msg = mail.MailRequest("", "", "",
                                    EXAMPLE_SIGNED_FORWARDED_DIGEST)
        make_email(self.msg, self.inbox)
        self.email = models.Email.objects.get()

        leaf_part_count = len(
            [i for i in self.email.parts.all() if i.is_leaf_node()])
        self.assertEqual(leaf_part_count, 12)

        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)

        self.assertEqual(len(response.context["email"]["bodies"]), 1)
        self.assertEqual(response.context["email"]["bodies"][0],
                         "<pre>Hello\n</pre>")
コード例 #10
0
    def test_make_email(self):
        inbox = factories.InboxFactory()
        message = MailRequest("locahost", "test@localhost", str(inbox),
                              TEST_MSG)

        router_utils.make_email(message, inbox)
        self.assertEqual(models.Email.objects.count(), 1)
        self.assertEqual(models.PartList.objects.count(), 6)

        email = models.Email.objects.first()
        self.assertEqual(email.inbox, inbox)
        self.assertNotEqual(email.search_tsv, None)

        bodies = [
            bytes(part.body.data)
            for part in models.PartList.objects.select_related(
                "body").order_by("level", "lft")
        ]
        self.assertEqual(bodies, BODIES)
コード例 #11
0
    def test_centos_announce_digest(self):
        self.msg = mail.MailRequest("", "", "", EXAMPLE_CENTOS_ANNOUNCE_DIGEST)
        make_email(self.msg, self.inbox)
        self.email = models.Email.objects.get()

        leaf_part_count = len(
            [i for i in self.email.parts.all() if i.is_leaf_node()])
        self.assertEqual(leaf_part_count, 5)

        response = self.client.get(self.get_url())
        self.assertEqual(response.status_code, 200)

        # one of the leaf nodes is a pgp signature, so it won't be shown to the
        # user
        self.assertEqual(len(response.context["email"]["bodies"]), 4)
        for i in range(4):
            with self.subTest(i=i):
                self.assertNotEqual(response.context["email"]["bodies"][i],
                                    "<pre></pre>")
コード例 #12
0
ファイル: server.py プロジェクト: 3nprob/Inboxen
def process_message(message, inbox=None, domain=None):
    try:
        with transaction.atomic():
            inbox = Inbox.objects.filter(inbox=inbox, domain__domain=domain)
            inbox = inbox.select_related("user",
                                         "user__inboxenprofile").receiving()
            inbox = inbox.get()

            make_email(message, inbox)

            inbox.new = True
            inbox.save(update_fields=["new"])

            if not inbox.exclude_from_unified:
                profile = inbox.user.inboxenprofile
                profile.unified_has_new_messages = True
                profile.save(update_fields=["unified_has_new_messages"])
    except DatabaseError as e:
        log.exception("DB error: %s", e)
        raise SMTPError(451, "Error processing message, try again later.")
    except Inbox.DoesNotExist:
        raise SMTPError(550, "No such address")