Skip to content

Commit

Permalink
parsemail: Never drop patches sent as attachments
Browse files Browse the repository at this point in the history
Even with git_send_email_only set to True, we don't want to drop patches
sent as attachments.

The purpose of git_send_email_only was to reduce the number of false
positives with people sending diff hunks inlined, but an attached patch
is always something we want to track.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Nov 11, 2015
1 parent 9591df7 commit 16af23c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion patchwork/bin/parsemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def find_content(project, mail):
patchbuf = None
commentbuf = ''
pullurl = None
is_attachment = False

for part in mail.walk():
if part.get_content_maintype() != 'text':
Expand Down Expand Up @@ -325,6 +326,7 @@ def find_content(project, mail):
return None

if subtype in ['x-patch', 'x-diff']:
is_attachment = True
patchbuf = payload

elif subtype == 'plain':
Expand All @@ -350,7 +352,8 @@ def find_content(project, mail):
is_patch = patchbuf is not None
is_git_send_email = mail.get('X-Mailer', '').startswith('git-send-email ')

drop_patch = project.git_send_email_only and not is_git_send_email
drop_patch = not is_attachment and \
project.git_send_email_only and not is_git_send_email

if pullurl or (is_patch and not drop_patch):
ret.patch_order = x or 1
Expand Down
22 changes: 20 additions & 2 deletions patchwork/tests/test_patchparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,13 @@ class MailFromPatchTest(TestCase):
patch_filename = '0001-add-line.patch'
msgid = '<1@example.com>'

def get_email(self):
email = create_email(self.patch)
def get_email(self, multipart=False):
if multipart:
email = create_email('See attached patch!', multipart=multipart)
attachment = MIMEText(self.patch, _subtype='x-patch')
email.attach(attachment)
else:
email = create_email(self.patch)
del email['List-ID']
email['List-ID'] = '<' + self.p1.listid + '>'
email['Message-Id'] = self.msgid
Expand Down Expand Up @@ -709,6 +714,19 @@ def testSettingOnNoGitSendEmail(self):
parse_mail(email)
self._assertNPatches(0)

def testAttachment(self):
"""Attachments can be patches even with git_send_email_only true"""

self.p1.git_send_email_only = True
self.p1.save()
email = self.get_email(multipart=True)

content = find_content(self.p1, email)
self.assertTrue(content.patch is not None)
self.assertEquals(content.patch.content, self.patch)
self.assertTrue(content.comment is not None)
self.assertEquals(content.comment.content, 'See attached patch!')

class ParseInitialTagsTest(PatchTest):
patch_filename = '0001-add-line.patch'
test_comment = ('test comment\n\n' +
Expand Down

0 comments on commit 16af23c

Please sign in to comment.