Skip to content

Commit

Permalink
Handle case where slice_tree receives (start, end) slice with end <= …
Browse files Browse the repository at this point in the history
…start.
  • Loading branch information
andreip committed Jul 5, 2018
1 parent e9e6159 commit 2e11e33
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion quotequail/_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_quotequail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Date: Fri, Apr 26, 2013 at 8:13 PM
Subject: Weekend Spanish classes
To: [email protected]
Spanish Classes
Learn Spanish
"""), {
'type': 'forward',
'from': 'Someone <[email protected]>',
'date': 'Fri, Apr 26, 2013 at 8:13 PM',
'subject': 'Weekend Spanish classes',
'to': '[email protected]',
'text': 'Spanish Classes\nLearn Spanish',
})

def test_apple_forward(self):
# Apple Mail (10.9 and earlier) forward
self.assertEqual(unwrap("""Hello
Expand Down Expand Up @@ -702,6 +722,32 @@ def test_gmail_forward(self):
'html': '<html><head></head><body><div dir="ltr"><div><div class="gmail_quote"><div dir="ltr">Some text</div></div></div></div></body></html>',
})

def test_gmail_forward_no_message(self):
html = '''
<html>
<head></head>
<body>
<div dir="ltr">
<div><br><div class="gmail_quote">---------- Forwarded message ----------<br>
From: <b class="gmail_sendername">Foo Bar</b> <span dir="ltr">&lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</span><br>
Date: Thu, Mar 24, 2016 at 5:17 PM<br>
Subject: The Subject<br>
To: John Doe &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;<br><br><br>
<div dir="ltr">Some text<div><br></div><div><br></div></div></div><br>
</div>
</div>
</body>
</html>'''

self.assertEqual(unwrap_html(html), {
'type': 'forward',
'subject': 'The Subject',
'date': 'Thu, Mar 24, 2016 at 5:17 PM',
'from': 'Foo Bar <[email protected]>',
'to': 'John Doe <[email protected]>',
'html': '<html><head></head>\n <body><div dir="ltr"><div><div class="gmail_quote"><div dir="ltr">Some text</div></div></div></div></body></html>',
})

def test_apple_reply(self):
html = '<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Foo<div class=""><br class=""></div><div class="">Bar</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 2016-03-25, at 23:01, John Doe &lt;<a href="mailto:[email protected]" class="">[email protected]</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Some <b class="">important</b> email<br class=""></div></div></blockquote></div><br class=""></div></body></html>'

Expand Down

0 comments on commit 2e11e33

Please sign in to comment.