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

add support for yahoo mail #192

Open
wants to merge 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions talon/html_quotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def cut_gmail_quote(html_message):
return True


def cut_yahoo_quote(html_message):
''' Cuts the outermost block element with class yahoo_quoted. '''
yahoo_quote = cssselect('div.yahoo_quoted', html_message)
if yahoo_quote and (yahoo_quote[0].text is None or not RE_FWD.match(yahoo_quote[0].text)):
yahoo_quote[0].getparent().remove(yahoo_quote[0])
return True


def cut_microsoft_quote(html_message):
''' Cuts splitter block and all following blocks. '''
#use EXSLT extensions to have a regex match() function with lxml
Expand Down
1 change: 1 addition & 0 deletions talon/quotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ def extract_from_html_tree(html_tree):
then deleting necessary tags.
"""
cut_quotations = (html_quotations.cut_gmail_quote(html_tree) or
html_quotations.cut_yahoo_quote(html_tree) or
html_quotations.cut_zimbra_quote(html_tree) or
html_quotations.cut_blockquote(html_tree) or
html_quotations.cut_microsoft_quote(html_tree) or
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/html_replies/yahoo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px"class=ydp8a2f2dc5yahoo-style-wrap><div><div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px">Hi. I am fine.</div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px"><br clear=none></div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px">Thanks,</div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px">Alex</div><div><br></div></div><br></div><div><br></div></div><div class=yahoo_quoted id=yahoo_quoted_0033794750><div style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;color:#26282a"><div>On Tuesday, June 4, 2019, 5:41:43 PM PDT, John Smith &lt;[email protected]> wrote:</div><div><br></div><div><br></div><div><div id=yiv3423441790><div dir=ltr>Hello! How are you?</div></div></div></div></div>
25 changes: 25 additions & 0 deletions tests/html_quotations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ def test_gmail_quote_blockquote():
RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)))


def test_yahoo_quote():
msg_body = """Reply
<div id="yahoo_quoted_0033794750" class="yahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Tuesday, June 4, 2019, 5:41:43 PM PDT, John Smith &lt;[email protected]&gt; wrote:
</div>
<div><br></div>
<div><br></div>
<div>
<div id="yiv3423441790">
<div dir="ltr">Test</div>
</div>
</div>
</div>
</div>
"""
eq_("<html><head></head><body>Reply</body></html>",
RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)))


def test_unicode_in_reply():
msg_body = u"""Reply \xa0 \xa0 Text<br>

Expand Down Expand Up @@ -326,6 +347,10 @@ def test_gmail_reply():
extract_reply_and_check("tests/fixtures/html_replies/gmail.html")


def test_yahoo_reply():
extract_reply_and_check("tests/fixtures/html_replies/yahoo.html")


def test_mail_ru_reply():
extract_reply_and_check("tests/fixtures/html_replies/mail_ru.html")

Expand Down