]> git.ozlabs.org Git - patchwork/commitdiff
Copy headers from original mail into patch mbox output
authorJeremy Kerr <jk@ozlabs.org>
Wed, 30 Sep 2009 07:18:05 +0000 (17:18 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 30 Sep 2009 07:26:49 +0000 (17:26 +1000)
Preserve the Cc and To headers in the mbox output by parsing the saved
original headers, and adding them to the mail object.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/models.py
apps/patchwork/tests/mboxviews.py

index 75dc041dae49ca10bdfd9060c091bec5aa33526d..70003e086a0a39f0eb480c319b310b91813c29c2 100644 (file)
@@ -32,6 +32,7 @@ import random
 try:
     from email.mime.nonmultipart import MIMENonMultipart
     from email.encoders import encode_7or8bit
+    from email.parser import HeaderParser
     import email.utils
 except ImportError:
     # Python 2.4 compatibility
@@ -269,8 +270,14 @@ class Patch(models.Model):
         mail['Message-Id'] = self.msgid
         mail.set_unixfrom('From patchwork ' + self.date.ctime())
 
-        return mail
 
+        copied_headers = ['To', 'Cc']
+        orig_headers = HeaderParser().parsestr(str(self.headers))
+        for header in copied_headers:
+            if header in orig_headers:
+                mail[header] = orig_headers[header]
+
+        return mail
 
     @models.permalink
     def get_absolute_url(self):
index a7729d8598dea837b18568a84d8b7a1e56067dbc..a3c10cf0a7a2628e14bc5a8b989b39fc061c941e 100644 (file)
@@ -77,3 +77,33 @@ class MboxPatchSplitResponseTest(TestCase):
         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
         self.assertContains(response,
                 'Acked-by: 1\nAcked-by: 2\n')
+
+class MboxPassThroughHeaderTest(TestCase):
+    """ Test that we see 'Cc' and 'To' headers passed through from original
+        message to mbox view """
+
+    def setUp(self):
+        defaults.project.save()
+        self.person = defaults.patch_author_person
+        self.person.save()
+
+        self.cc_header = 'Cc: CC Person <cc@example.com>'
+        self.to_header = 'To: To Person <to@example.com>'
+
+        self.patch = Patch(project = defaults.project,
+                           msgid = 'p1', name = 'testpatch',
+                           submitter = self.person, content = '')
+
+    def testCCHeader(self):
+        self.patch.headers = self.cc_header + '\n'
+        self.patch.save()
+
+        response = self.client.get('/patch/%d/mbox/' % self.patch.id)
+        self.assertContains(response, self.cc_header)
+
+    def testToHeader(self):
+        self.patch.headers = self.to_header + '\n'
+        self.patch.save()
+
+        response = self.client.get('/patch/%d/mbox/' % self.patch.id)
+        self.assertContains(response, self.to_header)