Commit efad0307 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

HAX: email: Workaround FDO's header mangling

FDO started respecting DMARC, which means it cannot freely resend emails
without rewriting 'From:' header in some cases.

So this:
  From: Author <original@mail>
Changes to:
  From: Author via listname <listid@lists.freedesktop.org>
  Reply-To: Author <original@mail>

Let's recognize that and unmangle it for authorship and mbox purposes.
Signed-off-by: Arkadiusz Hiler's avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent c200b533
Pipeline #18948 passed with stage
in 3 minutes and 21 seconds
......@@ -180,6 +180,13 @@ def find_author(mail):
if email is None:
raise Exception("Could not parse From: header")
# XXX: FDO HAX
if '@lists.freedesktop.org' in email and 'Reply-To' in mail:
reply_to_header = clean_header(mail.get('Reply-To'))
(name, email) = extract_email_and_name(reply_to_header)
if email is None:
raise Exception("Could not parse Reply-To: header")
save_required = False
try:
......
......@@ -103,6 +103,46 @@ class MboxAuthorship(TestCase):
'From: {} <{}>'.format(self.person.name, self.person.email))
class FDOHaxFromHeaderMangling(TestCase):
fixtures = ['default_states', 'default_events']
def setUp(self):
defaults.project.save()
self.original_from = "Toto <original@author.com>"
self.fdo_forwarded_from = "Toto via Meep <meep@lists.freedesktop.org>"
self.bogus_reply_to = "Dev Null <dev@null.a>"
self.person = defaults.patch_author_person
self.person.save()
def testInReplyToShouldBeUsedForFDOForwardedMails(self):
headers = 'From: {}\nReply-To: {}'.format(self.fdo_forwarded_from,
self.original_from)
self.patch = Patch(project=defaults.project,
msgid='p1', name='testpatch',
submitter=self.person, content='',
headers=headers)
self.patch.save()
response = self.client.get('/patch/%d/mbox/' % self.patch.id)
self.assertContains(response, 'From: {}'.format(self.original_from))
def testInReplyToShouldNOTBeUsedForNONFDOForwardedMails(self):
headers = 'From: {}\nReply-To: {}'.format(self.original_from,
self.bogus_reply_to)
self.patch = Patch(project=defaults.project,
msgid='p1', name='testpatch',
submitter=self.person, content='',
headers=headers)
self.patch.save()
response = self.client.get('/patch/%d/mbox/' % self.patch.id)
self.assertContains(response, 'From: {}'.format(self.original_from))
class MboxPatchSplitResponseTest(TestCase):
fixtures = ['default_states', 'default_events']
......
......@@ -359,6 +359,40 @@ class DuplicatePatchInRevision(TransactionTestCase):
parse_mail(patch2)
class FDOHaxFromHeaderMangling(TestCase):
fixtures = ['default_states', 'default_events']
test_comment = 'Test Comment'
patch_filename = '0001-add-line.patch'
def testInReplyToShouldBeUsedForFDOForwardedMails(self):
raw_patch = read_patch(self.patch_filename)
patch = create_email(self.test_comment + '\n' + raw_patch,
subject="[PATCH] Meep Meep]")
del patch['From']
patch['From'] = 'Toto via Meep <meep@lists.freedesktop.org>'
patch['Reply-To'] = 'Toto <toto@tata.a>'
parse_mail(patch)
patch = Patch.objects.get()
self.assertEqual(patch.submitter.email, 'toto@tata.a')
self.assertEqual(patch.submitter.name, 'Toto')
def testInReplyToShouldNOTBeUsedForNONFDOForwardedMails(self):
raw_patch = read_patch(self.patch_filename)
patch = create_email(self.test_comment + '\n' + raw_patch,
subject="[PATCH] Meep Meep]")
del patch['From']
patch['From'] = 'Toto <toto@tata.a>'
patch['Reply-To'] = 'Dev Null <dev@null.a>'
parse_mail(patch)
patch = Patch.objects.get()
self.assertEqual(patch.submitter.email, 'toto@tata.a')
self.assertEqual(patch.submitter.name, 'Toto')
class MultipleProjectPatchCommentTest(MultipleProjectPatchTest):
"""Test that followups to multiple-project patches end up on the
......
......@@ -191,6 +191,11 @@ def get_from(patch, charset):
if patch.headers:
headers = HeaderParser().parsestr(patch.headers)
if 'From' in headers:
# XXX: FDO hax
if '@lists.freedesktop.org' in headers['From'] \
and 'Reply-To' in headers:
return headers['Reply-To']
return headers['From']
# just in case we don't have headers in some old patches
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment