]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parsemail: Add cover letter parsing
authorStephen Finucane <stephen.finucane@intel.com>
Sun, 6 Mar 2016 01:48:11 +0000 (01:48 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Thu, 14 Apr 2016 16:29:17 +0000 (17:29 +0100)
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>
patchwork/bin/parsemail.py

index 16cd9d1b55691b65955f32005b735a8ae0441894..17a8c0da17264f5569f47d6004c5d4e8b2e55feb 100755 (executable)
@@ -42,7 +42,8 @@ from django.utils import six
 from django.utils.six.moves import map
 
 from patchwork.models import (Patch, Project, Person, Comment, State,
-                              DelegationRule, get_default_initial_patch_state)
+                              DelegationRule, Submission, CoverLetter,
+                              get_default_initial_patch_state)
 from patchwork.parser import parse_patch, patch_get_filenames
 
 LOGGER = logging.getLogger(__name__)
@@ -280,15 +281,13 @@ def find_content(project, mail):
     return patchbuf, commentbuf
 
 
-def find_patch_for_comment(project, refs):
+def find_submission_for_comment(project, refs):
     for ref in refs:
-        patch = None
-
         # first, check for a direct reply
         try:
-            patch = Patch.objects.get(project=project, msgid=ref)
-            return patch
-        except Patch.DoesNotExist:
+            submission = Submission.objects.get(project=project, msgid=ref)
+            return submission
+        except Submission.DoesNotExist:
             pass
 
         # see if we have comments that refer to a patch
@@ -462,7 +461,8 @@ def parse_mail(mail, list_id=None):
 
     msgid = mail.get('Message-Id').strip()
     author, save_required = find_author(mail)
-    name, _ = clean_subject(mail.get('Subject'), [project.linkname])
+    name, prefixes = clean_subject(mail.get('Subject'), [project.linkname])
+    x, n = parse_series_marker(prefixes)
     refs = find_references(mail)
     date = find_date(mail)
     headers = find_headers(mail)
@@ -496,12 +496,28 @@ def parse_mail(mail, list_id=None):
         LOGGER.debug('Patch saved')
 
         return patch
+    elif refs == [] and x == 0:  # cover letters
+        if save_required:
+            author.save()
+
+        cover_letter = CoverLetter(
+            msgid=msgid,
+            project=project,
+            name=name,
+            date=date,
+            headers=headers,
+            submitter=author,
+            content=message)
+        cover_letter.save()
+        LOGGER.debug('Cover letter saved')
+
+        return cover_letter
 
     # comments
 
     # we only save comments if we have the parent email
-    patch = find_patch_for_comment(project, refs)
-    if not patch:
+    submission = find_submission_for_comment(project, refs)
+    if not submission:
         return
 
     # ...and we only save the author if we're saving the comment