diff mbox

[v3,09/12] parsemail: Add cover letter parsing

Message ID 1460408967-16219-9-git-send-email-stephen.finucane@intel.com
State Accepted
Headers show

Commit Message

Stephen Finucane April 11, 2016, 9:09 p.m. UTC
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>
---
 patchwork/bin/parsemail.py | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

Comments

Andy Doan April 14, 2016, 3:56 p.m. UTC | #1
On 04/11/2016 04:09 PM, Stephen Finucane wrote:
> 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>

> diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
> @@ -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)

small nitpick, but "n" is an unused variable.
diff mbox

Patch

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 16cd9d1..17a8c0d 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -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