From ed6b861a47f279a99c442b078b76d87a7566988b Mon Sep 17 00:00:00 2001 From: Easy-D Date: Thu, 16 Jul 2015 21:24:49 +0200 Subject: [PATCH 1/2] add failing test that shows how regular blockquotes are removed --- tests/html_quotations_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/html_quotations_test.py b/tests/html_quotations_test.py index 27fec9e..385bac1 100644 --- a/tests/html_quotations_test.py +++ b/tests/html_quotations_test.py @@ -50,6 +50,24 @@ def test_quotation_splitter_outside_blockquote(): RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) +def test_regular_blockquote(): + msg_body = """Reply +
Regular
+ +
+ On 11-Apr-2011, at 6:54 PM, Bob <bob@example.com> wrote: +
+ +
+
+
Nested
+
+
+""" + eq_("

Reply

Regular
", + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + + def test_no_blockquote(): msg_body = """ From 390b0a6dc957784c2e73cc3b61b1ba3f790abad1 Mon Sep 17 00:00:00 2001 From: Easy-D Date: Thu, 16 Jul 2015 21:31:41 +0200 Subject: [PATCH 2/2] preserve regular blockquotes --- talon/html_quotations.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/talon/html_quotations.py b/talon/html_quotations.py index c270fe6..32bf634 100644 --- a/talon/html_quotations.py +++ b/talon/html_quotations.py @@ -138,9 +138,10 @@ def cut_by_id(html_message): def cut_blockquote(html_message): - ''' Cuts blockquote with wrapping elements. ''' - quote = html_message.find('.//blockquote') - if quote is not None: + ''' Cuts the last non-nested blockquote with wrapping elements. ''' + quote = html_message.xpath('(.//blockquote)[not(ancestor::blockquote)][last()]') + if quote: + quote = quote[0] quote.getparent().remove(quote) return True