Skip to content

Commit 36953bb

Browse files
committed
parsemail: Add cover letter parsing
Add support for both cover letters and comments on cover letters. This works using the following heuristics: * The message contains a '[0/n]' marker tag in the subject * The message is the root message Signed-off-by: Stephen Finucane <stephen.finucane@intel.com> Reviewed-by: Andy Doan <andy.doan@linaro.org>
1 parent de16d62 commit 36953bb

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

patchwork/bin/parsemail.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
from django.utils.six.moves import map
4343

4444
from patchwork.models import (Patch, Project, Person, Comment, State,
45-
DelegationRule, get_default_initial_patch_state)
45+
DelegationRule, Submission, CoverLetter,
46+
get_default_initial_patch_state)
4647
from patchwork.parser import parse_patch, patch_get_filenames
4748

4849
LOGGER = logging.getLogger(__name__)
@@ -280,15 +281,13 @@ def find_content(project, mail):
280281
return patchbuf, commentbuf
281282

282283

283-
def find_patch_for_comment(project, refs):
284+
def find_submission_for_comment(project, refs):
284285
for ref in refs:
285-
patch = None
286-
287286
# first, check for a direct reply
288287
try:
289-
patch = Patch.objects.get(project=project, msgid=ref)
290-
return patch
291-
except Patch.DoesNotExist:
288+
submission = Submission.objects.get(project=project, msgid=ref)
289+
return submission
290+
except Submission.DoesNotExist:
292291
pass
293292

294293
# see if we have comments that refer to a patch
@@ -462,7 +461,8 @@ def parse_mail(mail, list_id=None):
462461

463462
msgid = mail.get('Message-Id').strip()
464463
author, save_required = find_author(mail)
465-
name, _ = clean_subject(mail.get('Subject'), [project.linkname])
464+
name, prefixes = clean_subject(mail.get('Subject'), [project.linkname])
465+
x, n = parse_series_marker(prefixes)
466466
refs = find_references(mail)
467467
date = find_date(mail)
468468
headers = find_headers(mail)
@@ -496,12 +496,28 @@ def parse_mail(mail, list_id=None):
496496
LOGGER.debug('Patch saved')
497497

498498
return patch
499+
elif refs == [] and x == 0: # cover letters
500+
if save_required:
501+
author.save()
502+
503+
cover_letter = CoverLetter(
504+
msgid=msgid,
505+
project=project,
506+
name=name,
507+
date=date,
508+
headers=headers,
509+
submitter=author,
510+
content=message)
511+
cover_letter.save()
512+
LOGGER.debug('Cover letter saved')
513+
514+
return cover_letter
499515

500516
# comments
501517

502518
# we only save comments if we have the parent email
503-
patch = find_patch_for_comment(project, refs)
504-
if not patch:
519+
submission = find_submission_for_comment(project, refs)
520+
if not submission:
505521
return
506522

507523
# ...and we only save the author if we're saving the comment

0 commit comments

Comments
 (0)