]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/bin/parsemail.py
parser: allow short-form List-Id headers
[patchwork] / apps / patchwork / bin / parsemail.py
index 772728e41e82ffbba9e2d42a54ca17004652e3bf..68bd94cd37174a4f25851f2a2596cea2e56f34d9 100755 (executable)
@@ -57,11 +57,17 @@ def clean_header(header):
 
 def find_project(mail):
     project = None
-    listid_re = re.compile('.*<([^>]+)>.*', re.S)
+    listid_res = [re.compile('.*<([^>]+)>.*', re.S),
+                  re.compile('^([\S]+)$', re.S)]
 
     for header in list_id_headers:
         if header in mail:
-            match = listid_re.match(mail.get(header))
+
+            for listid_re in listid_res:
+                match = listid_re.match(mail.get(header))
+                if match:
+                    break
+
             if not match:
                 continue
 
@@ -173,7 +179,7 @@ def find_content(project, mail):
         if patch:
             cpatch = patch
         else:
-            cpatch = find_patch_for_comment(mail)
+            cpatch = find_patch_for_comment(project, mail)
             if not cpatch:
                 return (None, None)
         comment = Comment(patch = cpatch, date = mail_date(mail),
@@ -182,7 +188,7 @@ def find_content(project, mail):
 
     return (patch, comment)
 
-def find_patch_for_comment(mail):
+def find_patch_for_comment(project, mail):
     # construct a list of possible reply message ids
     refs = []
     if 'In-Reply-To' in mail:
@@ -200,14 +206,14 @@ def find_patch_for_comment(mail):
 
         # first, check for a direct reply
         try:
-            patch = Patch.objects.get(msgid = ref)
+            patch = Patch.objects.get(project = project, msgid = ref)
             return patch
         except Patch.DoesNotExist:
             pass
 
         # see if we have comments that refer to a patch
         try:
-            comment = Comment.objects.get(msgid = ref)
+            comment = Comment.objects.get(patch__project = project, msgid = ref)
             return comment.patch
         except Comment.DoesNotExist:
             pass
@@ -319,8 +325,7 @@ def clean_content(str):
     str = sig_re.sub('', str)
     return str.strip()
 
-def main(args):
-    mail = message_from_file(sys.stdin)
+def parse_mail(mail):
 
     # some basic sanity checks
     if 'From' not in mail:
@@ -376,5 +381,9 @@ def main(args):
 
     return 0
 
+def main(args):
+    mail = message_from_file(sys.stdin)
+    return parse_mail(mail)
+
 if __name__ == '__main__':
     sys.exit(main(sys.argv))