From 6c013e7e3d170fd58d3e3e19406ff16d019909c4 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 30 Sep 2009 17:18:05 +1000 Subject: [PATCH] Copy headers from original mail into patch mbox output 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 --- apps/patchwork/models.py | 9 ++++++++- apps/patchwork/tests/mboxviews.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 75dc041d..70003e08 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -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): diff --git a/apps/patchwork/tests/mboxviews.py b/apps/patchwork/tests/mboxviews.py index a7729d85..a3c10cf0 100644 --- a/apps/patchwork/tests/mboxviews.py +++ b/apps/patchwork/tests/mboxviews.py @@ -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 ' + self.to_header = 'To: To Person ' + + 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) -- 2.47.3