diff roundup/mailgw.py @ 4579:ba4c632143f6

issue2550535 Fix keep_quoted_text=yes setting. In some cases even when keep_quoted_text=yes is configured we would strip quoted sections. This hit the python bug-tracker especially for python interpreter examples with leading '>>>' strings. The fix is slightly different compared to the proposal as this broke keep_quoted_text=no in certain cases. We also fix a bug where keep_quoted_text=no would drop the last line of a non-quoted section if there wasn't an empty line between the next quotes.
author Ralf Schlatterbeck <rsc@runtux.com>
date Thu, 05 Jan 2012 20:55:47 +0100
parents c426cb251bc7
children 782737d1a2d7
line wrap: on
line diff
--- a/roundup/mailgw.py	Thu Jan 05 16:22:27 2012 +0100
+++ b/roundup/mailgw.py	Thu Jan 05 20:55:47 2012 +0100
@@ -1778,16 +1778,24 @@
     # extract out the summary from the message
     summary = ''
     l = []
-    for section in sections:
+    # find last non-empty section for signature matching
+    last_nonempty = len(sections) -1
+    while last_nonempty and not sections[last_nonempty]:
+        last_nonempty -= 1
+    for ns, section in enumerate(sections):
         #section = section.strip()
         if not section:
             continue
         lines = eol.split(section)
-        if (lines[0] and lines[0][0] in '>|') or (len(lines) > 1 and
-                lines[1] and lines[1][0] in '>|'):
+        quote_1st = lines[0] and lines[0][0] in '>|'
+        quote_2nd = len(lines) > 1 and lines[1] and lines[1][0] in '>|'
+        if quote_1st or quote_2nd:
+            # don't drop non-quoted first line of intermediate section:
+            if ns and not quote_1st and lines[0] and not keep_citations:
+                l.append(lines[0])
             # see if there's a response somewhere inside this section (ie.
             # no blank line between quoted message and response)
-            for line in lines[1:]:
+            for n, line in enumerate(lines[1:]):
                 if line and line[0] not in '>|':
                     break
             else:
@@ -1796,17 +1804,19 @@
                     l.append(section)
                 continue
             # keep this section - it has reponse stuff in it
-            lines = lines[lines.index(line):]
+            if not keep_citations:
+                lines = lines[n+1:]
             section = '\n'.join(lines)
-            # and while we're at it, use the first non-quoted bit as
-            # our summary
-            summary = section
 
+        is_last = ns == last_nonempty
+        # and while we're at it, use the first non-quoted bit as
+        # our summary
         if not summary:
             # if we don't have our summary yet use the first line of this
             # section
             summary = section
-        elif signature.match(lines[0]) and 2 <= len(lines) <= 10:
+        # match signature only in last section
+        elif is_last and signature.match(lines[0]) and 2 <= len(lines) <= 10:
             # lose any signature
             break
         elif original_msg.match(lines[0]):

Roundup Issue Tracker: http://roundup-tracker.org/