]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/models.py
[mbox] Add extra newline after patch comment
[patchwork] / apps / patchwork / models.py
index a672f9ad41ebe5f16879db45a655a42b2c5643c8..793cb4ede5554e03d297668dee22adba576c1c3f 100644 (file)
@@ -227,6 +227,8 @@ class Patch(models.Model):
         return str.strip('-') + '.patch'
 
     def mbox(self):
+        postscript_re = re.compile('\n-{2,3} ?\n')
+
         comment = None
         try:
             comment = Comment.objects.get(patch = self, msgid = self.msgid)
@@ -237,6 +239,14 @@ class Patch(models.Model):
         if comment:
             body = comment.content.strip() + "\n"
 
+        parts = postscript_re.split(body, 1)
+        if len(parts) == 2:
+            (body, postscript) = parts
+            body = body.strip() + "\n"
+            postscript = postscript.strip() + "\n"
+        else:
+            postscript = ''
+
         responses = False
         for comment in Comment.objects.filter(patch = self) \
                 .exclude(msgid = self.msgid):
@@ -245,7 +255,10 @@ class Patch(models.Model):
         if body:
             body += '\n'
 
-        body += self.content
+        if postscript:
+            body += '---\n' + postscript.strip() + '\n'
+
+        body += '\n' + self.content
 
         mail = PatchMbox(body)
         mail['Subject'] = self.name