Skip to content

Commit

Permalink
parsemail: Detect git send-email emails without X-Mailer headers
Browse files Browse the repository at this point in the history
git send-email has an option to omit the X-Mailer header (--no-xmailer
aka sendemail.xmailer). If the user decides to use this, then our git
send-email detection fails.

In those cases, we can still fall back to looking at the Message-ID. git
send-email helpfully uses the 'git-send-email' string in its
Message-IDs.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Feb 9, 2016
1 parent 6bc5dd2 commit a8af1e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions patchwork/bin/parsemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ def parse_series_marker(subject_prefixes):
return (None, None)


def is_git_send_email(mail):
return mail.get('X-Mailer', '').startswith('git-send-email ') or \
'git-send-email' in mail.get('Message-ID', '')


def find_content(project, mail):
patchbuf = None
commentbuf = ''
Expand Down Expand Up @@ -375,10 +380,9 @@ def find_content(project, mail):
is_root = refs == []
is_cover_letter = is_root and x == 0
is_patch = patchbuf is not None
is_git_send_email = mail.get('X-Mailer', '').startswith('git-send-email ')

drop_patch = not is_attachment and \
project.git_send_email_only and not is_git_send_email
project.git_send_email_only and not is_git_send_email(mail)

if pullurl or (is_patch and not drop_patch):
ret.patch_order = x or 1
Expand Down
11 changes: 11 additions & 0 deletions patchwork/tests/test_patchparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,17 @@ def testSettingOnGitSendEmail(self):
parse_mail(email)
self._assertNPatches(1)

def testSettingOnGitSendEmailNoXMailer(self):
"""git_send_email_only is true and email has been sent with
git send-email --no-xmailer"""
self.p1.git_send_email_only = True
self.p1.save()
email = self.get_email()
del email['Message-Id']
email['Message-Id'] = '<1454600601-21900-1-git-send-email-cpaul@redhat.com>'
parse_mail(email)
self._assertNPatches(1)

def testSettingOnNoGitSendEmail(self):
"""git_send_email_only is true and email has been not sent with
git send-email"""
Expand Down

0 comments on commit a8af1e4

Please sign in to comment.