Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include html_top in a no-message forward #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -256,8 +258,6 @@ def tree_token_generator(el, indentation_level=0):
if not isinstance(el.tag, string_class):
return

tag_name = el.tag.lower()

is_indentation = is_indentation_element(el)

if is_indentation:
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 <noreply@example.com>
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 <noreply@example.com>',
'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
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:foo@bar.example">foo@bar.example</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:john@doe.example">john@doe.example</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 <foo@bar.example>',
'to': 'John Doe <john@doe.example>',
'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:john@doe.example" class="">john@doe.example</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