Commit f3bd0565 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler
Browse files

mboxviews: Use QP for payloads with lines over 78 characters

RFC 5322 requires us to not have lines longer than 998 characters and
strongly suggests that we should impose even stricter limitation of 78

Let's follow that recommendation and use quoted-printable transfer
encoding if any line of payload is longer than 78 characters.
Reported-by: Petri Latvala's avatarPetri Latvala <>
Signed-off-by: default avatarArkadiusz Hiler <>
parent bc734cd9
Pipeline #136460 passed with stage
in 1 minute and 29 seconds
......@@ -365,3 +365,44 @@ class MboxCommentPostcriptUnchangedTest(TestCase):
self.assertContains(response, self.txt)
self.txt += "\n"
self.assertNotContains(response, self.txt)
class MboxEncoding(TestCase):
fixtures = ['default_states', 'default_events']
def create_patch(self, message, diff):
patch = Patch(project=defaults.project,
msgid='p1', name='testpatch',
submitter=self.person, content=diff)
comment = Comment(patch=patch, msgid='p1',
return patch
def setUp(self):
self.person = defaults.patch_author_person
def testQuotedPrintableIfLineOver78(self):
patch = self.create_patch("x", "y" * 79)
response = self.client.get('/patch/%d/mbox/' %
'Content-Transfer-Encoding: quoted-printable')
def test7bitIfLine78orLess(self):
patch = self.create_patch("x", "y" * 78)
response = self.client.get('/patch/%d/mbox/' %
'Content-Transfer-Encoding: 7bit')
def test8bitIfNonAscii(self):
patch = self.create_patch("x", "hą hą hą")
response = self.client.get('/patch/%d/mbox/' %
'Content-Transfer-Encoding: 8bit')
......@@ -252,20 +252,20 @@ class APITest(APITestBase):
# XXX: since Python 3 email module wrap header lines differently
self.check_mbox("/series/%s/revisions/1/mbox/" %,
def testMboxWithCoverLetter(self):
# XXX: since Python 3 email module wrap header lines differently
self.check_mbox("/series/%s/revisions/1/mbox_with_cover/" %,
def testCoverLetterMbox(self):
self.check_mbox("/series/%s/revisions/1/cover/" %,
def testMboxAndMboxWithCoverShouldBeIdenticalForSeriesWithNoCL(self):
mbox = self.client.get('/api/1.0' +
......@@ -21,7 +21,7 @@ from __future__ import absolute_import
import datetime
import time
from email.encoders import encode_7or8bit
from email.encoders import encode_7or8bit, encode_quopri
from email.header import Header
from email.mime.nonmultipart import MIMENonMultipart
from email.parser import HeaderParser
......@@ -184,6 +184,10 @@ class PatchMbox(MIMENonMultipart):
MIMENonMultipart.__init__(self, 'text', 'plain',
**{'charset': self.patch_charset})
if max((len(line) for line in _text.splitlines()), default=0) > 78:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment