From 4e0db9ebf1279afc0f2a187f25dbfcb97e314a78 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 10 Jun 2013 11:50:21 +0800 Subject: [PATCH] views/mbox: Use Date: header from original message Since we use UTC for internal date storage, we lose the timestamp info from the original patch submissions. This means that the mbox views (which are typically passed through to SCM commit logs) lose the timezone information. This change uses the Date header from the original message, if possible. Signed-off-by: Jeremy Kerr --- apps/patchwork/tests/mboxviews.py | 8 ++++++++ apps/patchwork/views/__init__.py | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/patchwork/tests/mboxviews.py b/apps/patchwork/tests/mboxviews.py index e619e7b..8c469a1 100644 --- a/apps/patchwork/tests/mboxviews.py +++ b/apps/patchwork/tests/mboxviews.py @@ -93,6 +93,7 @@ class MboxPassThroughHeaderTest(TestCase): self.cc_header = 'Cc: CC Person ' self.to_header = 'To: To Person ' + self.date_header = 'Date: Fri, 7 Jun 2013 15:42:54 +1000' self.patch = Patch(project = defaults.project, msgid = 'p1', name = 'testpatch', @@ -112,6 +113,13 @@ class MboxPassThroughHeaderTest(TestCase): response = self.client.get('/patch/%d/mbox/' % self.patch.id) self.assertContains(response, self.to_header) + def testDateHeader(self): + self.patch.headers = self.date_header + '\n' + self.patch.save() + + response = self.client.get('/patch/%d/mbox/' % self.patch.id) + self.assertContains(response, self.date_header) + class MboxBrokenFromHeaderTest(TestCase): """ Test that a person with characters outside ASCII in his name do produce correct From header. As RFC 2822 state we must retain the diff --git a/apps/patchwork/views/__init__.py b/apps/patchwork/views/__init__.py index cb35c1f..681532a 100644 --- a/apps/patchwork/views/__init__.py +++ b/apps/patchwork/views/__init__.py @@ -195,7 +195,6 @@ def patch_to_mbox(patch): mail = PatchMbox(body) mail['Subject'] = patch.name - mail['Date'] = email.utils.formatdate(utc_timestamp) mail['From'] = email.utils.formataddr(( str(Header(patch.submitter.name, mail.patch_charset)), patch.submitter.email)) @@ -204,10 +203,13 @@ def patch_to_mbox(patch): mail.set_unixfrom('From patchwork ' + patch.date.ctime()) - copied_headers = ['To', 'Cc'] + copied_headers = ['To', 'Cc', 'Date'] orig_headers = HeaderParser().parsestr(str(patch.headers)) for header in copied_headers: if header in orig_headers: mail[header] = orig_headers[header] + if 'Date' not in mail: + mail['Date'] = email.utils.formatdate(utc_timestamp) + return mail -- 2.39.2