From 48c0e00a9eef60e40a6f6888df37d599803096dd Mon Sep 17 00:00:00 2001 From: Doug Anderson Date: Sat, 19 Nov 2016 19:32:09 +0000 Subject: [PATCH] views: Don't munge the 'From' field of patches At the moment patchwork always uses the official submitter name (as patchwork understands it) as the "From" for patches that you receive. This isn't quite what users expect and has some unfortunate consequences. The biggest problem is that patchwork saves the "official" name for an email address the first time it sees an email from them. If that name is wrong (or was missing) patchwork will be confused even if future emails from this person are fixed. There are similar problems if a user changes his/her name (get married?). It seems better to just have each patch report the actual "From" that was used to send that patch. We'll still return the submitter in 'X-Patchwork-Submitter' just in case someone wants it. Conflicts: patchwork/tests/test_mboxviews.py Reported-by: Wolfram Sang Signed-off-by: Doug Anderson Signed-off-by: Stephen Finucane (cherry picked from commit d365402fb98dfb2c4aea4b58346096f85bdfa0c3) --- patchwork/tests/test_mboxviews.py | 12 ++++++++++++ patchwork/views/__init__.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index a2bee0d1..5e98457e 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -107,6 +107,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.from_header = 'From: John Doe ' self.patch = Patch(project=defaults.project, msgid='p1', name='testpatch', @@ -133,6 +134,13 @@ class MboxPassThroughHeaderTest(TestCase): response = self.client.get('/patch/%d/mbox/' % self.patch.id) self.assertContains(response, self.date_header) + def testFromHeader(self): + self.patch.headers = self.from_header = '\n' + self.patch.save() + + response = self.client.get('/patch/%d/mbox/' % self.patch.id) + self.assertContains(response, self.from_header) + class MboxGeneratedHeaderTest(TestCase): fixtures = ['default_states'] @@ -161,6 +169,10 @@ class MboxGeneratedHeaderTest(TestCase): self.assertContains(response, 'X-Patchwork-Delegate: %s' % self.user.email) + def testPatchworkFromHeader(self): + response = self.client.get('/patch/%d/mbox/' % self.patch.id) + self.assertContains(response, 'X-Patchwork-Submitter:') + class MboxBrokenFromHeaderTest(TestCase): fixtures = ['default_states'] diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index ae0d561d..a38da9d3 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -353,7 +353,7 @@ def patch_to_mbox(patch): mail = PatchMbox(body) mail['Subject'] = patch.name - mail['From'] = email.utils.formataddr(( + mail['X-Patchwork-Submitter'] = email.utils.formataddr(( str(Header(patch.submitter.name, mail.patch_charset)), patch.submitter.email)) mail['X-Patchwork-Id'] = str(patch.id) @@ -362,7 +362,7 @@ def patch_to_mbox(patch): mail['Message-Id'] = patch.msgid mail.set_unixfrom('From patchwork ' + patch.date.ctime()) - copied_headers = ['To', 'Cc', 'Date'] + copied_headers = ['To', 'Cc', 'Date', 'From'] orig_headers = HeaderParser().parsestr(str(patch.headers)) for header in copied_headers: if header in orig_headers: -- 2.47.3