Commit 65404776 authored by Jeremy Kerr's avatar Jeremy Kerr
Browse files

[encoding] Don't output patch mbox as quoted-printable

git-am doesn't like quoted-printable, so output mbox files as raw 7- or
8-bit mbox files. This means we have to create a new MIMEText class, so
that the content isn't automatically QP-encoded on __init__().
Signed-off-by: default avatarJeremy Kerr <>
parent e0fac2b8
......@@ -31,11 +31,13 @@ import string
import random
from email.mime.text import MIMEText
from email.mime.nonmultipart import MIMENonMultipart
from email.encoders import encode_7or8bit
import email.utils
except ImportError:
# Python 2.4 compatibility
from email.MIMEText import MIMEText
from email.MIMENonMultipart import MIMENonMultipart
from email.Encoders import encode_7or8bit
import email.Utils
email.utils = email.Utils
......@@ -167,6 +169,14 @@ class HashField(models.CharField):
def db_type(self):
return 'char(%d)' % self.n_bytes
class PatchMbox(MIMENonMultipart):
patch_charset = 'utf-8'
def __init__(self, _text):
MIMENonMultipart.__init__(self, 'text', 'plain',
**{'charset': self.patch_charset})
class Patch(models.Model):
project = models.ForeignKey(Project)
msgid = models.CharField(max_length=255, unique = True)
......@@ -238,7 +248,7 @@ class Patch(models.Model):
body += self.content
mail = MIMEText(body, _charset = 'utf-8')
mail = PatchMbox(body)
mail['Subject'] =
mail['Date'] = email.utils.formatdate(
......@@ -48,6 +48,14 @@ class UTF8PatchViewTest(TestCase):
def testMboxView(self):
response = self.client.get('/patch/%d/mbox/' %
self.assertEquals(response.status_code, 200)
self.assertTrue(self.patch.content in \
def testRawView(self):
response = self.client.get('/patch/%d/raw/' %
self.assertEquals(response.status_code, 200)
def tearDown(self):
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