[PATCH 13/13] parsemail: Handle cover letters sent in reply

Stephen Finucane stephen.finucane at intel.com
Fri Mar 11 23:08:17 AEDT 2016


Some people send cover letters (and therefore series) as replies to
existing series. Apply a second set of heuristics to cover this case:

* The message contains a '[0/n]' marker tag in the subject
* The message is not the root message, but the subject is unique, i.e.
  it is not a reply to a cover letter already stored in Patchwork

It is theoretically possible that the message could be a reply to a
cover letter that's been missed, but such occurences should be rare
and only get rarer the longer an instance is running.

Note that there is a third case which is not yet covered: a cover
letter with the same name but a different number of patches. This
will have to wait until series support is fully inplemented.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/bin/parsemail.py | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index a61b02a..0ccbffc 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -496,22 +496,36 @@ def parse_mail(mail, list_id=None):
         LOGGER.debug('Patch saved')
 
         return patch
-    elif refs == [] and x == 0:  # cover letters
+    elif x == 0:  # (potential) 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
+        # if refs are empty, it's implicitly a cover letter. If not,
+        # however, we need to see if a match already exists and, if
+        # not, assume that it is indeed a new cover letter
+        is_cover_letter = False
+        if not refs == []:
+            try:
+                CoverLetter.objects.all().get(name=name)
+            except CoverLetter.DoesNotExist:  # no match => new cover
+                is_cover_letter = True
+        else:
+            is_cover_letter = True
+
+
+        if is_cover_letter:
+            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
 
@@ -525,7 +539,7 @@ def parse_mail(mail, list_id=None):
         author.save()
 
     comment = Comment(
-        submission=patch,
+        submission=submission,
         msgid=msgid,
         date=date,
         headers=headers,
-- 
2.0.0



More information about the Patchwork mailing list