Skip to content

Commit a971756

Browse files
ajdlinuxstephenfin
authored andcommitted
parser: Don't crash when From: is list email but has weird mangle format
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: 8279a84 ("parser: Unmangle From: headers that have been mangled for DMARC purposes") Reported-by: Jeremy Kerr <[email protected]> Signed-off-by: Andrew Donnellan <[email protected]> Reviewed-by: Stephen Finucane <[email protected]>
1 parent 162b4ad commit a971756

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

patchwork/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ def get_original_sender(mail, name, email):
373373
# Mailman uses the format "<name> via <list>"
374374
# Google Groups uses "'<name>' via <list>"
375375
stripped_name = name[:name.rfind(' via ')].strip().strip("'")
376+
elif name.endswith(' via'):
377+
# Sometimes this seems to happen (perhaps if Mailman isn't set up with
378+
# any list name)
379+
stripped_name = name[:name.rfind(' via')].strip().strip("'")
380+
else:
381+
# We've hit a format that we don't expect
382+
stripped_name = None
376383

377384
original_from = clean_header(mail.get('X-Original-From', ''))
378385
if original_from:

patchwork/tests/test_parser.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,29 @@ def test_google_dmarc_munging(self):
366366
self.assertEqual(person_b._state.adding, False)
367367
self.assertEqual(person_b.id, person_a.id)
368368

369+
def test_weird_dmarc_munging(self):
370+
project = create_project()
371+
real_sender = 'Existing Sender <[email protected]>'
372+
munged_sender1 = "'Existing Sender' via <{}>".format(project.listemail)
373+
munged_sender2 = "'Existing Sender' <{}>".format(project.listemail)
374+
375+
# Unmunged author
376+
mail = self._create_email(real_sender)
377+
person_a = get_or_create_author(mail, project)
378+
person_a.save()
379+
380+
# Munged with no list name
381+
mail = self._create_email(munged_sender1, None, None, real_sender)
382+
person_b = get_or_create_author(mail, project)
383+
self.assertEqual(person_b._state.adding, False)
384+
self.assertEqual(person_b.id, person_a.id)
385+
386+
# Munged with no 'via'
387+
mail = self._create_email(munged_sender2, None, None, real_sender)
388+
person_b = get_or_create_author(mail, project)
389+
self.assertEqual(person_b._state.adding, False)
390+
self.assertEqual(person_b.id, person_a.id)
391+
369392

370393
class SeriesCorrelationTest(TestCase):
371394
"""Validate correct behavior of find_series."""

0 commit comments

Comments
 (0)