Example #1
0
 def test_mbox_with_8bit_tags(self):
     self.cli_login()
     self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
     self.cli_logout()
     mbox = self.client.get('/QEMU/[email protected]/mbox')
     parser = email.parser.BytesParser(policy=email.policy.SMTP)
     msg = parser.parsebytes(mbox.content)
     payload = decode_payload(msg)
     self.assertIn('SynICState *synic = get_synic(cs);', payload)
     self.assertIn('Reviewed-by: Philippe Mathieu-Daudé <*****@*****.**>', payload)
Example #2
0
 def test_mbox_with_8bit_tags(self):
     self.cli_login()
     self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
     self.cli_logout()
     mbox = self.client.get(
         "/QEMU/[email protected]/mbox")
     parser = email.parser.BytesParser(policy=email.policy.SMTP)
     msg = parser.parsebytes(mbox.content)
     payload = decode_payload(msg)
     self.assertIn("SynICState *synic = get_synic(cs);", payload)
     self.assertIn(
         "Reviewed-by: Philippe Mathieu-Daudé <*****@*****.**>", payload)
Example #3
0
    def get_mbox_with_tags(m):
        mbox = m.get_mbox()
        try:
            msg = email.message_from_string(mbox)
        except:
            return mbox
        container = msg.get_payload(0) if msg.is_multipart() else msg
        if container.get_content_type() != "text/plain":
            return mbox

        payload = decode_payload(container)
        container.set_payload('\n'.join(mbox_with_tags_iter(payload, m.tags)))
        return msg.as_string()
Example #4
0
    def _get_mbox_with_tags(self, series_tags=[]):
        def mbox_with_tags_iter(mbox, tags):
            regex = "^[-A-Za-z]*:"
            old_tags = set()
            lines = lines_iter(mbox)
            need_minusminusminus = False
            for line in lines:
                if line.startswith("---"):
                    need_minusminusminus = True
                    break
                yield line
                if re.match(regex, line):
                    old_tags.add(line)

            # If no --- line, tags go at the end as there's no better place
            for tag in sorted(tags):
                if (
                    tag not in old_tags
                    and not tag.startswith("Based-on")
                    and not tag.startswith("Supersedes")
                ):
                    yield tag
            if need_minusminusminus:
                yield line
            yield from lines

        mbox = self.get_mbox()
        msg = email.message_from_string(mbox)
        container = msg.get_payload(0) if msg.is_multipart() else msg
        if container.get_content_type() != "text/plain":
            return msg.as_bytes(unixfrom=True)

        payload = decode_payload(container)
        # We might be adding 8-bit trailers to a message with 7bit CTE.  For
        # patches, quoted-printable is safe and mostly human-readable.
        try:
            container.replace_header("Content-Transfer-Encoding", "quoted-printable")
        except KeyError:
            msg.add_header("Content-Transfer-Encoding", "quoted-printable")
        payload = "\n".join(
            mbox_with_tags_iter(payload, set(self.tags).union(series_tags))
        )
        payload = quopri.encodestring(payload.encode("utf-8"))
        container.set_payload(payload, charset="utf-8")
        return msg.as_bytes(unixfrom=True)
Example #5
0
    def get_mbox_with_tags(m, series_tags):
        mbox = m.get_mbox()
        msg = email.message_from_string(mbox)
        container = msg.get_payload(0) if msg.is_multipart() else msg
        if container.get_content_type() != "text/plain":
            return msg.as_bytes(unixfrom=True)

        payload = decode_payload(container)
        # We might be adding 8-bit trailers to a message with 7bit CTE.  For
        # patches, quoted-printable is safe and mostly human-readable.
        try:
            container.replace_header('Content-Transfer-Encoding', 'quoted-printable')
        except KeyError:
            msg.add_header('Content-Transfer-Encoding', 'quoted-printable')
        payload = '\n'.join(mbox_with_tags_iter(payload, set(m.tags).union(series_tags)))
        payload = quopri.encodestring(payload.encode('utf-8'))
        container.set_payload(payload, charset='utf-8')
        return msg.as_bytes(unixfrom=True)