]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parser: Don't crash when From: is list email but has weird mangle format
authorAndrew Donnellan <ajd@linux.ibm.com>
Wed, 15 Apr 2020 09:06:56 +0000 (19:06 +1000)
committerStephen Finucane <stephen@that.guru>
Sat, 18 Apr 2020 11:04:19 +0000 (12:04 +0100)
get_original_sender() tries to demangle DMARC-mangled From headers, in
the case where the email's From address is the list address. It knows how
to handle Google Groups and Mailman style mangling, where the original
submitter's name will be turned into e.g. "Andrew Donnellan via
linuxppc-dev".

If an email has the From header set to the list address but has a name that
doesn't include " via ", we'll throw an exception because stripped_name
hasn't been set. Sometimes this is because the list name is seemingly
empty, resulting in a mangled name like "Andrew Donnellan via"
without the space after "via" that we detect. Handle this as well as we can
instead, and add a test.

Fixes: 8279a84238c10 ("parser: Unmangle From: headers that have been mangled for DMARC purposes")
Reported-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
(cherry picked from commit 4698499b9704b29244af4a873efc6c8ae6ca3ff8)

patchwork/parser.py
patchwork/tests/test_parser.py

index 45930b454359b556087386257760e25c0a50fff1..cf3e3cf0a70626d7a89aee407798fcdc95e4bdad 100644 (file)
@@ -392,6 +392,13 @@ def get_original_sender(mail, name, email):
         # Mailman uses the format "<name> via <list>"
         # Google Groups uses "'<name>' via <list>"
         stripped_name = name[:name.rfind(' via ')].strip().strip("'")
+    elif name.endswith(' via'):
+        # Sometimes this seems to happen (perhaps if Mailman isn't set up with
+        # any list name)
+        stripped_name = name[:name.rfind(' via')].strip().strip("'")
+    else:
+        # We've hit a format that we don't expect
+        stripped_name = None
 
     original_from = clean_header(mail.get('X-Original-From', ''))
     if original_from:
index 6fbc9da9f849b0280f508e66b971eb3fddff3596..d5c98091b31cbe7a52760a01d9da1d8ea7c8efff 100644 (file)
@@ -371,6 +371,29 @@ class SenderCorrelationTest(TestCase):
         self.assertEqual(person_b._state.adding, False)
         self.assertEqual(person_b.id, person_a.id)
 
+    def test_weird_dmarc_munging(self):
+        project = create_project()
+        real_sender = 'Existing Sender <existing@example.com>'
+        munged_sender1 = "'Existing Sender' via <{}>".format(project.listemail)
+        munged_sender2 = "'Existing Sender' <{}>".format(project.listemail)
+
+        # Unmunged author
+        mail = self._create_email(real_sender)
+        person_a = get_or_create_author(mail, project)
+        person_a.save()
+
+        # Munged with no list name
+        mail = self._create_email(munged_sender1, None, None, real_sender)
+        person_b = get_or_create_author(mail, project)
+        self.assertEqual(person_b._state.adding, False)
+        self.assertEqual(person_b.id, person_a.id)
+
+        # Munged with no 'via'
+        mail = self._create_email(munged_sender2, None, None, real_sender)
+        person_b = get_or_create_author(mail, project)
+        self.assertEqual(person_b._state.adding, False)
+        self.assertEqual(person_b.id, person_a.id)
+
 
 class SeriesCorrelationTest(TestCase):
     """Validate correct behavior of find_series."""