[PATCH v3 04/12] parsemail: Extract building the list of mail references

Stephen Finucane stephen.finucane at intel.com
Tue Apr 12 07:09:19 AEST 2016


From: Damien Lespiau <damien.lespiau at intel.com>

We'll need to figure out whether the mail we are parsing is the root of
the thread to automatically build series, and we'll need the list of
references for that.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/bin/parsemail.py | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 3ade49e..ae1ccb2 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -193,6 +193,23 @@ def try_decode(payload, charset):
     return payload
 
 
+def build_references_list(mail):
+    """Construct a list of possible reply message ids."""
+    refs = []
+
+    if 'In-Reply-To' in mail:
+        refs.append(mail.get('In-Reply-To'))
+
+    if 'References' in mail:
+        rs = mail.get('References').split()
+        rs.reverse()
+        for r in rs:
+            if r not in refs:
+                refs.append(r)
+
+    return refs
+
+
 def parse_series_marker(subject_prefixes):
     """Extract series markers from subject.
 
@@ -286,7 +303,8 @@ def find_content(project, mail):
                       headers=mail_headers(mail))
 
     if commentbuf and not patch:
-        cpatch = find_patch_for_comment(project, mail)
+        refs = build_references_list(mail)
+        cpatch = find_patch_for_comment(project, refs)
         if not cpatch:
             return (None, None, None)
         comment = Comment(submission=cpatch,
@@ -297,19 +315,7 @@ def find_content(project, mail):
     return (patch, comment, filenames)
 
 
-def find_patch_for_comment(project, mail):
-    # construct a list of possible reply message ids
-    refs = []
-    if 'In-Reply-To' in mail:
-        refs.append(mail.get('In-Reply-To'))
-
-    if 'References' in mail:
-        rs = mail.get('References').split()
-        rs.reverse()
-        for r in rs:
-            if r not in refs:
-                refs.append(r)
-
+def find_patch_for_comment(project, refs):
     for ref in refs:
         patch = None
 
-- 
2.0.0



More information about the Patchwork mailing list