From 73e498ef282efdbcc7045badef8e1881a99953ec Mon Sep 17 00:00:00 2001 From: Andrei Petre Date: Wed, 4 Jul 2018 13:47:04 -0700 Subject: [PATCH 1/3] Use end+1 as start of headers section. Logically this makes more sense, since find_unwrap_start can theoretically return a distinct start and end. Although in practice the headers could appear only in "forward" scenario where start and end are the same, so this doesn't really matter. If you'd like to artificially build a test case where the previous code would fail, you'd put the forward pattern on two lines: ---------- Forwarded message ---------- From: Someone Date: Fri, Apr 26, 2013 at 8:13 PM Subject: Weekend Spanish classes --- quotequail/_internal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quotequail/_internal.py b/quotequail/_internal.py index cd7f537..3a587db 100644 --- a/quotequail/_internal.py +++ b/quotequail/_internal.py @@ -254,10 +254,10 @@ def unwrap(lines, max_wrap_lines, min_header_lines, min_quoted_lines): return main_type, (0, start), headers, (quoted_start, rest_start), (rest_start, None), True elif typ == 'headers': - hdrs, hdrs_length = extract_headers(lines[start+1:], max_wrap_lines) + hdrs, hdrs_length = extract_headers(lines[end+1:], max_wrap_lines) if hdrs: headers.update(hdrs) - rest_start = start + 1 + hdrs_length + rest_start = end + 1 + hdrs_length return main_type, (0, start), headers, (rest_start, None), None, False else: # Didn't find quoted section or headers, assume that everything From 75a6b133519e9e4690643d00c3c67d7f5efd5318 Mon Sep 17 00:00:00 2001 From: Andrei Petre Date: Wed, 4 Jul 2018 13:56:35 -0700 Subject: [PATCH 2/3] Use end+1 as start of quoted test instead of start+1. Same as before for headers starting, this makes more sense logically, if the previous pattern occupies two lines instead of one. One could artifically build a scenario where the reply header takes two lines and the quoted text doesn't have ">" in it, to reach this else branch logic: On 2012-10-16 at 17:02 , Someone wrote: Some quoted text --- quotequail/_internal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quotequail/_internal.py b/quotequail/_internal.py index 3a587db..52ae999 100644 --- a/quotequail/_internal.py +++ b/quotequail/_internal.py @@ -262,7 +262,7 @@ def unwrap(lines, max_wrap_lines, min_header_lines, min_quoted_lines): else: # Didn't find quoted section or headers, assume that everything # below is the qouted text. - return main_type, (0, start), headers, (start+(start2 or 0)+1, None), None, False + return main_type, (0, start), headers, (end+(start2 or 0)+1, None), None, False # We just found headers, which usually indicates a forwarding. elif typ == 'headers': From 1efa477dafd5c8a337c731fa3fc0dbe400d855a3 Mon Sep 17 00:00:00 2001 From: Andrei Petre Date: Wed, 4 Jul 2018 14:16:26 -0700 Subject: [PATCH 3/3] Use 0 for start as everywhere instead of None, even if equivalent. --- quotequail/_internal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quotequail/_internal.py b/quotequail/_internal.py index 52ae999..429a6dc 100644 --- a/quotequail/_internal.py +++ b/quotequail/_internal.py @@ -283,4 +283,4 @@ def unwrap(lines, max_wrap_lines, min_header_lines, min_quoted_lines): return main_type, (0, start), hdrs, (rest2_start, rest_start), (rest_start, None), True else: main_type = 'quote' - return main_type, (None, start), None, (start, rest_start), (rest_start, None), True + return main_type, (0, start), None, (start, rest_start), (rest_start, None), True