示例#1
0
    def test_render_body_bad_http_equiv(self):
        email = {"display_images": True, "eid": "abc"}
        part = mock.Mock()
        part.content_type = "text/html"
        part.charset = "utf-8"
        part.body.data = BAD_HTTP_EQUIV_BODY

        returned_body = email_utils.render_body(None, email, [part])
        self.assertIsInstance(returned_body, six.text_type)
示例#2
0
    def test_render_body_bad_http_equiv(self):
        email = {"display_images": True, "eid": "abc"}
        part = mock.Mock()
        part.content_type = "text/html"
        part.charset = "utf-8"
        part.body.data = BAD_HTTP_EQUIV_BODY

        returned_body = email_utils.render_body(None, email, [part])
        self.assertIsInstance(returned_body, str)
示例#3
0
文件: email.py 项目: Kunal18/Inboxen
    def get_context_data(self, **kwargs):
        if "all-headers" in self.request.GET:
            headers = None
            headers_fetch_all = bool(int(self.request.GET["all-headers"]))
        else:
            headers = cache.get(self.object.id, version="email-header")
            headers_fetch_all = bool(self.object.flags.view_all_headers)

        if headers is None:
            headers = models.Header.objects.filter(part__email=self.object,
                                                   part__parent=None)
            if headers_fetch_all:
                headers = headers.get_many()
            else:
                headers = headers.get_many("Subject", "From")

        email_dict = {}
        email_dict["headers"] = headers
        email_dict["date"] = self.object.received_date
        email_dict["inbox"] = self.object.inbox
        email_dict["eid"] = self.object.eid

        # GET params for users with `ask_image` set in their profile
        if "imgDisplay" in self.request.GET and int(
                self.request.GET["imgDisplay"]) == 1:
            email_dict["display_images"] = True
            email_dict["ask_images"] = False
        elif self.request.user.inboxenprofile.flags.ask_images:
            email_dict["display_images"] = False
            email_dict["ask_images"] = True
        else:
            email_dict[
                "display_images"] = self.request.user.inboxenprofile.flags.display_images
            email_dict["ask_images"] = False

        # iterate over MIME parts
        root_part = self.object.get_parts()

        email_dict["bodies"] = []
        email_dict["has_images"] = False

        email_dict["bodies"] = [
            render_body(self.request, email_dict, parts)
            for parts in find_bodies(root_part)
        ]

        context = super(EmailView, self).get_context_data(**kwargs)
        context.update({
            "email": email_dict,
            "attachments": root_part,
            "headersfetchall": headers_fetch_all,
        })

        self._has_images = email_dict["display_images"]
        return context
示例#4
0
    def test_render_body_bad_encoding(self):
        email = {"display_images": True, "eid": "abc"}
        part = mock.Mock()
        part.content_type = "text/html"
        part.charset = "utf-8"
        part.body.data = BADLY_ENCODED_BODY

        with mock.patch("inboxen.utils.email.messages") as msg_mock:
            returned_body = email_utils.render_body(None, email, [part])
            self.assertEqual(msg_mock.error.call_count, 1)
        self.assertIsInstance(returned_body, six.text_type)
示例#5
0
    def test_render_body_bad_encoding(self):
        email = {"display_images": True, "eid": "abc"}
        part = mock.Mock()
        part.content_type = "text/html"
        part.charset = "utf-8"
        part.body.data = BADLY_ENCODED_BODY

        with mock.patch("inboxen.utils.email.messages") as msg_mock:
            returned_body = email_utils.render_body(None, email, [part])
            self.assertEqual(msg_mock.error.call_count, 1)
        self.assertIsInstance(returned_body, str)
示例#6
0
文件: email.py 项目: Inboxen/Inboxen
    def get_context_data(self, **kwargs):
        if "all-headers" in self.request.GET:
            headers = None
            headers_fetch_all = bool(int(self.request.GET["all-headers"]))
        else:
            headers = cache.get(self.object.id, version="email-header")
            headers_fetch_all = self.object.view_all_headers

        if headers is None:
            headers = models.Header.objects.filter(part__email=self.object, part__parent=None)
            if headers_fetch_all:
                headers = headers.get_many()
            else:
                headers = headers.get_many("Subject", "From")

        email_dict = {}
        email_dict["headers"] = headers
        email_dict["date"] = self.object.received_date
        email_dict["inbox"] = self.object.inbox
        email_dict["eid"] = self.object.eid

        # GET params for users with `ask_image` set in their profile
        if "imgDisplay" in self.request.GET and int(self.request.GET["imgDisplay"]) == 1:
            email_dict["display_images"] = True
            email_dict["ask_images"] = False
        elif self.request.user.inboxenprofile.display_images == models.UserProfile.ASK:
            email_dict["display_images"] = False
            email_dict["ask_images"] = True
        else:
            email_dict["display_images"] = self.request.user.inboxenprofile.display_images == models.UserProfile.DISPLAY
            email_dict["ask_images"] = False

        # iterate over MIME parts
        root_part = self.object.get_parts()

        email_dict["bodies"] = []
        email_dict["has_images"] = False

        email_dict["bodies"] = [render_body(self.request, email_dict, parts) for parts in find_bodies(root_part)]

        context = super(EmailView, self).get_context_data(**kwargs)
        context.update({
            "email": email_dict,
            "attachments": root_part,
            "headersfetchall": headers_fetch_all,
        })

        self._has_images = email_dict["display_images"]
        return context