[PATCH 1/2] views: Don't munge the 'From' field of patches

Stephen Finucane stephen at that.guru
Sun Nov 20 06:32:09 AEDT 2016


From: Doug Anderson <dianders at chromium.org>

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.

Reported-by: Wolfram Sang <wsa at the-dreams.de>
Signed-off-by: Doug Anderson <dianders at chromium.org>
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
v2:
- Rebase onto master
- Add unit tests
---
 patchwork/tests/test_mboxviews.py | 34 +++++++++++++++++++++++++---------
 patchwork/views/__init__.py       |  4 ++--
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py
index 164de3a..b3f4bf6 100644
--- a/patchwork/tests/test_mboxviews.py
+++ b/patchwork/tests/test_mboxviews.py
@@ -82,26 +82,30 @@ class MboxHeaderTest(TestCase):
 
     """Test the passthrough and generation of various headers."""
 
-    def test_header_passthrough_cc(self):
-        """Validate passthrough of 'Cc' header."""
-        header = 'Cc: CC Person <cc at example.com>'
+    def _test_header_passthrough(self, header):
         patch = create_patch(headers=header + '\n')
         response = self.client.get(reverse('patch-mbox', args=[patch.id]))
         self.assertContains(response, header)
 
+    def test_header_passthrough_cc(self):
+        """Validate passthrough of 'Cc' header."""
+        header = 'Cc: CC Person <cc at example.com>'
+        self._test_header_passthrough(header)
+
     def test_header_passthrough_to(self):
         """Validate passthrough of 'To' header."""
         header = 'To: To Person <to at example.com>'
-        patch = create_patch(headers=header + '\n')
-        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
-        self.assertContains(response, header)
+        self._test_header_passthrough(header)
 
     def test_header_passthrough_date(self):
         """Validate passthrough of 'Date' header."""
         header = 'Date: Fri, 7 Jun 2013 15:42:54 +1000'
-        patch = create_patch(headers=header + '\n')
-        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
-        self.assertContains(response, header)
+        self._test_header_passthrough(header)
+
+    def test_header_passthrough_from(self):
+        """Validate passthrough of 'From' header."""
+        header = 'From: John Doe <john at doe.com>'
+        self._test_header_passthrough(header)
 
     def test_patchwork_id_header(self):
         """Validate inclusion of generated 'X-Patchwork-Id' header."""
@@ -116,6 +120,18 @@ class MboxHeaderTest(TestCase):
         response = self.client.get(reverse('patch-mbox', args=[patch.id]))
         self.assertContains(response, 'X-Patchwork-Delegate: %s' % user.email)
 
+    def test_patchwork_from_header(self):
+        """Validate inclusion of generated 'X-Patchwork-From' header."""
+        email = 'jon at doe.com'
+        from_header = 'From: Jon Doe <%s>\n' % email
+
+        person = create_person(name='Jonathon Doe', email=email)
+        patch = create_patch(submitter=person, headers=from_header)
+        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
+        self.assertContains(response, from_header)
+        self.assertContains(response, 'X-Patchwork-Submitter: %s <%s>' % (
+            person.name, email))
+
     def test_from_header(self):
         """Validate non-ascii 'From' header.
 
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index a29da83..5dc3a0e 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -384,7 +384,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)
@@ -393,7 +393,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.7.4



More information about the Patchwork mailing list