-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def read_file(): | ||
def _read_file(name: str) -> str: | ||
with open( | ||
os.path.join(os.path.dirname(__file__), "files", name), "rb" | ||
) as f: | ||
return f.read().decode("utf8") | ||
|
||
return _read_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">test<div class=""><br class=""></div><div class="">blah<br class=""><div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Foo Bar <<a href="mailto:[email protected]" class="">[email protected]</a>><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">The Subject</b><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">March 24, 2016 at 20:16:25 GMT+1<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">John Doe <<a href="mailto:[email protected]" class="">[email protected]</a>><br class=""></span></div><br class=""><div class=""><div dir="ltr" class="">Text of the original email</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<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 <<a href="mailto:[email protected]" class="">[email protected]</a>> 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><head></head><body><div dir="ltr">test<div><br></div><div>blah</div><div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Foo Bar</b> <span dir="ltr"><<a href="mailto:[email protected]">[email protected]</a>></span><br>Date: Thu, Mar 24, 2016 at 5:17 PM<br>Subject: The Subject<br>To: John Doe <<a href="mailto:[email protected]">[email protected]</a>><br><br><br><div dir="ltr">Some text<div><br></div><div><br></div></div></div><br></div></div></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html><head></head><body><div dir="ltr">foo<div><br></div><div>bar</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 16, 2016 at 12:49 AM, Foo Bar <span dir="ltr"><<a href="mailto:[email protected]" target="_blank">[email protected]</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br> | ||
<br>This is the reply<br> | ||
<br> | ||
Thanks a lot!<br> | ||
<span class="HOEnZb"><font color="#888888">Foo<br> | ||
<br> | ||
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><b>John Doe</b></div><div dir="ltr"><b>Senior Director</b><div>Some Company</div></div></div></div></div> | ||
</div> | ||
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import pytest | ||
|
||
from quotequail import unwrap_html | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("html", "expected"), | ||
[ | ||
("<p>html text</p>", None), | ||
( | ||
"Begin forwarded message:<br>\n<br>\nFrom: [email protected]<br>\nTo: [email protected]<br>\nSubject: You won<br>\n", | ||
{ | ||
"type": "forward", | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "You won", | ||
}, | ||
), | ||
], | ||
) | ||
def test_unwrap_html_simple(html, expected): | ||
assert unwrap_html(html) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("file", "expected"), | ||
[ | ||
( | ||
"apple_forward.html", | ||
{ | ||
"type": "forward", | ||
"subject": "The Subject", | ||
"date": "March 24, 2016 at 20:16:25 GMT+1", | ||
"from": "Foo Bar <[email protected]>", | ||
"to": "John Doe <[email protected]>", | ||
"html_top": '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">test<div class=""><br class=""></div><div class="">blah</div></body></html>', | ||
"html": '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div><div><div><div class=""><div dir="ltr" class="">Text of the original email</div></div></div></div></div></div></body></html>', | ||
}, | ||
), | ||
( | ||
"gmail_forward.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_top": '<html><head></head><body><div dir="ltr">test<div><br></div><div>blah</div></div></body></html>', | ||
"html": '<html><head></head><body><div dir="ltr"><div><div class="gmail_quote"><div dir="ltr">Some text</div></div></div></div></body></html>', | ||
}, | ||
), | ||
( | ||
"apple_reply.html", | ||
{ | ||
"type": "reply", | ||
"from": "John Doe <[email protected]>", | ||
"date": "2016-03-25, at 23:01", | ||
"html": '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div><div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Some <b class="">important</b> email</div></div></div></div></div></body></html>', | ||
"html_top": '<html><head></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></body></html>', | ||
}, | ||
), | ||
( | ||
"gmail_reply.html", | ||
{ | ||
"type": "reply", | ||
"from": "Foo Bar <[email protected]>", | ||
"date": "Wed, Mar 16, 2016 at 12:49 AM", | ||
"html_top": '<html><head></head><body><div dir="ltr">foo<div><br></div><div>bar</div></div></body></html>', | ||
"html": '<html><head></head><body><div class="gmail_extra"><div class="gmail_quote"><div>Hi,<br>\n<br>This is the reply<br>\n<br>\nThanks a lot!<br>\n<span class="HOEnZb"><font color="#888888">Foo</font></span></div></div></div></body></html>', | ||
"html_bottom": '<html><head></head><body><div class="gmail_extra">-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><b>John Doe</b></div><div dir="ltr"><b>Senior Director</b><div>Some Company</div></div></div></div></div>\n</div>\n</body></html>', | ||
}, | ||
), | ||
], | ||
) | ||
def test_unwrap_html_file(read_file, file, expected): | ||
html = read_file(file) | ||
assert unwrap_html(html) == expected | ||
|
||
|
||
def test_outlook_forward(read_file): | ||
data = read_file("outlook_forward.html") | ||
result = unwrap_html(data) | ||
assert result["type"] == "forward" | ||
assert result["from"] == "John Doe" | ||
assert result["to"] == "Foo Bar ([email protected])" | ||
assert result["date"] == "Wednesday, July 09, 2014 10:27 AM" | ||
assert result["subject"] == "The subject!" | ||
assert result["html"] == read_file("outlook_forward_unwrapped.html") | ||
assert result["html_top"] == read_file( | ||
"outlook_forward_unwrapped_top.html" | ||
) | ||
assert "html_bottom" not in result | ||
|
||
|
||
def test_thunderbird_forward(read_file): | ||
data = read_file("thunderbird_forward.html") | ||
result = unwrap_html(data) | ||
assert result["type"] == "forward" | ||
assert result["from"] == "John Doe <[email protected]>" | ||
assert result["to"] == "Foo Bar <[email protected]>" | ||
assert result["date"] == "Tue, 3 May 2016 14:54:27 +0200 (CEST)" | ||
assert result["subject"] == "Re: Example subject" | ||
assert "html_top" not in result | ||
assert result["html"] == read_file("thunderbird_forward_unwrapped.html") | ||
assert "html_bottom" not in result | ||
|
||
|
||
def test_mailru_forward(read_file): | ||
data = read_file("mailru_forward.html") | ||
result = unwrap_html(data) | ||
assert result["type"] == "forward" | ||
assert result["from"] == "Иван Иванов <[email protected]>" | ||
assert result["to"] == "Петр Петров <[email protected]>" | ||
assert result["date"] == "Среда, 14 июня 2017, 15:19 +03:00" | ||
assert result["subject"] == "Тестовая тема" | ||
assert "html_top" not in result | ||
assert result["html"] == read_file("mailru_forward_unwrapped.html") | ||
assert "html_bottom" not in result |