From 2e11e33e4e01547481d48b7773297b352d7e0dfe Mon Sep 17 00:00:00 2001 From: Andrei Petre Date: Thu, 5 Jul 2018 14:22:00 -0700 Subject: [PATCH] Handle case where slice_tree receives (start, end) slice with end <= start. --- quotequail/_html.py | 4 +++- tests/test_quotequail.py | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/quotequail/_html.py b/quotequail/_html.py index 64f3a0f..25866fb 100644 --- a/quotequail/_html.py +++ b/quotequail/_html.py @@ -116,7 +116,9 @@ def slice_tree(tree, start_refs, end_refs, slice_tuple, html_copy=None): slice_start, slice_end = slice_tuple if ((slice_start is not None and slice_start >= len(start_refs)) or - (slice_end is not None and slice_end <= 0)): + (slice_end is not None and slice_end <= 0) or + (slice_start is not None and slice_end is not None and + slice_end <= slice_start)): return get_html_tree('') if slice_start != None and slice_start <= 0: diff --git a/tests/test_quotequail.py b/tests/test_quotequail.py index a4d72e1..8d839ff 100644 --- a/tests/test_quotequail.py +++ b/tests/test_quotequail.py @@ -293,6 +293,26 @@ def test_gmail_forward(self): 'text': 'Spanish Classes\nLearn Spanish', }) + def test_gmail_forward_no_message(self): + # No more Hello message at the beginning, unlike test_gmail_forward + self.assertEqual(unwrap(""" +---------- Forwarded message ---------- +From: Someone +Date: Fri, Apr 26, 2013 at 8:13 PM +Subject: Weekend Spanish classes +To: recipient@example.com + +Spanish Classes +Learn Spanish +"""), { + 'type': 'forward', + 'from': 'Someone ', + 'date': 'Fri, Apr 26, 2013 at 8:13 PM', + 'subject': 'Weekend Spanish classes', + 'to': 'recipient@example.com', + 'text': 'Spanish Classes\nLearn Spanish', + }) + def test_apple_forward(self): # Apple Mail (10.9 and earlier) forward self.assertEqual(unwrap("""Hello @@ -702,6 +722,32 @@ def test_gmail_forward(self): 'html': '
Some text
', }) + def test_gmail_forward_no_message(self): + html = ''' + + + +
+

---------- Forwarded message ----------
+ From: Foo Bar <foo@bar.example>
+ Date: Thu, Mar 24, 2016 at 5:17 PM
+ Subject: The Subject
+ To: John Doe <john@doe.example>


+
Some text



+
+
+ +''' + + self.assertEqual(unwrap_html(html), { + 'type': 'forward', + 'subject': 'The Subject', + 'date': 'Thu, Mar 24, 2016 at 5:17 PM', + 'from': 'Foo Bar ', + 'to': 'John Doe ', + 'html': '\n
Some text
', + }) + def test_apple_reply(self): html = 'Foo

Bar

On 2016-03-25, at 23:01, John Doe <john@doe.example> wrote:

Some important email

'