diff mbox

[04/15] parsemail: Extract building the list of mail references

Message ID 1444387202-25735-5-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Oct. 9, 2015, 10:39 a.m. UTC
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@intel.com>
---
 patchwork/bin/parsemail.py | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

Comments

Stephen Finucane Oct. 9, 2015, 11:21 p.m. UTC | #1
> 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@intel.com>


While you didn't write this code initially, it would be incredibly useful to add some documentation on what this is doing why (i.e. a link to RFC822, RFC2822 and/or RFC5822 that defines how these fields work). I can add them in a follow up commit if not.

Acked-by: Stephen Finucane <stephen.finucane@hotmail.com>
diff mbox

Patch

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index a98066f..8bbb7ee 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -160,6 +160,22 @@  class MailContent:
         self.patch = None
         self.comment = None
 
+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):
     """If this patch is part a of multi-patches series, ie has x/n in its
        subject, return (x, n). Otherwise, return (None, None)."""
@@ -244,7 +260,8 @@  def find_content(project, mail):
                     headers = mail_headers(mail))
 
         else:
-            cpatch = find_patch_for_comment(project, mail)
+            refs = build_references_list(mail)
+            cpatch = find_patch_for_comment(project, refs)
             if not cpatch:
                 return ret
             ret.comment = Comment(patch = cpatch, date = mail_date(mail),
@@ -253,19 +270,7 @@  def find_content(project, mail):
 
     return ret
 
-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