123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- from bs4 import BeautifulSoup
- from nose.tools import raises
-
- from tracim.lib.email_processing.checkers import HtmlMailQuoteChecker
- from tracim.lib.email_processing.checkers import HtmlMailSignatureChecker
- from tracim.lib.email_processing.parser import ParsedHTMLMail
- from tracim.lib.email_processing.models import BodyMailPartType
- from tracim.lib.email_processing.models import BodyMailPart
- from tracim.lib.email_processing.models import BodyMailParts
- from tracim.tests import TestStandard
-
-
- class TestHtmlMailQuoteChecker(TestStandard):
- def test_unit__is_standard_quote_ok(self):
- soup = BeautifulSoup('<blockquote></blockquote>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_standard_quote(main_elem) is True
-
- def test_unit__is_standard_quote_no(self):
- soup = BeautifulSoup('<a></a>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_standard_quote(main_elem) is False
-
- def test_unit__is_thunderbird_quote_ok(self):
- soup = BeautifulSoup('<div class="moz-cite-prefix"></div>',
- 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_thunderbird_quote(main_elem) is True
-
- def test_unit__is_thunderbird_quote_no(self):
- soup = BeautifulSoup('<div class="nothing"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_thunderbird_quote(main_elem) is False
-
- def test_unit__is_gmail_quote_ok(self):
- html = '<div class="gmail_extra">' + \
- '<a></a><div class="gmail_quote"></div>' + \
- '</div>'
- soup = BeautifulSoup(html, 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_gmail_quote(main_elem) is True
-
- def test_unit__is_gmail_quote_no(self):
- soup = BeautifulSoup('<div class="nothing"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_gmail_quote(main_elem) is False
-
- def test_unit__is_gmail_quote_no_2(self):
- html = '<div class="gmail_extra">' + \
- '<a></a><div class="gmail_signature"></div>' + \
- '</div>'
- soup = BeautifulSoup(html, 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_gmail_quote(main_elem) is False
-
- def test_unit__is_outlook_com_quote_ok(self):
- soup = BeautifulSoup('<div id="divRplyFwdMsg"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_outlook_com_quote(main_elem) is True
-
- def test_unit__is_outlook_com_quote_no(self):
- soup = BeautifulSoup('<div id="Signature"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailQuoteChecker._is_outlook_com_quote(main_elem) is False
-
- # TODO - G.M - 2017-11-24 - Check Yahoo and New roundcube html mail with
- # correct mail example
-
-
- class TestHtmlMailSignatureChecker(TestStandard):
- def test_unit__is_thunderbird_signature_ok(self):
- soup = BeautifulSoup('<div class="moz-signature"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_thunderbird_signature(main_elem) is True # nopep8
-
- def test_unit__is_thunderbird_signature_no(self):
- soup = BeautifulSoup('<div class="other"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_thunderbird_signature(main_elem) is False # nopep8
-
- def test_unit__is_gmail_signature_ok(self):
- html = '<div class="gmail_extra">' + \
- '<a></a><div class="gmail_quote"></div>' + \
- '</div>'
- soup = BeautifulSoup(html, 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is False
-
- def test_unit__is_gmail_signature_no(self):
- soup = BeautifulSoup('<div class="nothing"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is False
-
- def test_unit__is_gmail_signature_yes(self):
- html = '<div class="gmail_extra">' + \
- '<a></a><div class="gmail_signature"></div>' + \
- '</div>'
- soup = BeautifulSoup(html, 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is True
-
- def test_unit__is_gmail_signature_yes_2(self):
- html = '<div class="gmail_signature">' + \
- '</div>'
- soup = BeautifulSoup(html, 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_gmail_signature(main_elem) is True
-
- def test_unit__is_outlook_com_signature_no(self):
- soup = BeautifulSoup('<div id="divRplyFwdMsg"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_outlook_com_signature(main_elem) \
- is False
-
- def test_unit__is_outlook_com_signature_ok(self):
- soup = BeautifulSoup('<div id="Signature"></div>', 'html.parser')
- main_elem = soup.find()
- assert HtmlMailSignatureChecker._is_outlook_com_signature(main_elem) \
- is True
-
-
- class TestBodyMailsParts(TestStandard):
-
- def test_unit__std_list_methods(self):
- mail_parts = BodyMailParts()
- assert len(mail_parts) == 0
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._list.append(a)
- assert len(mail_parts) == 1
- assert mail_parts[0] == a
- del mail_parts[0]
- assert len(mail_parts) == 0
-
- def test_unit__append_same_type(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._append(a)
- b = BodyMailPart('b', BodyMailPartType.Main)
- mail_parts._append(b)
- assert len(mail_parts) == 1
- assert mail_parts[0].part_type == BodyMailPartType.Main
- assert mail_parts[0].text == 'ab'
-
- def test_unit__append_different_type(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts.append(a)
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._append(b)
- assert len(mail_parts) == 2
- assert mail_parts[0] == a
- assert mail_parts[1] == b
-
- def test_unit__append_follow(self):
- mail_parts = BodyMailParts()
- mail_parts.follow = True
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._append(a)
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._append(b)
- assert len(mail_parts) == 1
- assert mail_parts[0].part_type == BodyMailPartType.Main
- assert mail_parts[0].text == 'ab'
-
- def test_unit__append_dont_follow_when_first(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._append(a, follow=True)
- assert len(mail_parts) == 1
- assert mail_parts[0].part_type == BodyMailPartType.Main
- assert mail_parts[0].text == 'a'
-
- @raises(TypeError)
- def test_unit__check_value__type_error(self):
- mail_parts = BodyMailParts()
- mail_parts._check_value('a')
-
- def test_unit__check_value__ok(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._check_value(a)
-
- def test_unit__drop_part_type(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._list.append(a)
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._list.append(b)
- c = BodyMailPart('c', BodyMailPartType.Signature)
- mail_parts._list.append(c)
- mail_parts.drop_part_type(BodyMailPartType.Quote)
- assert len(mail_parts) == 2
- assert mail_parts[0].text == 'a'
- assert mail_parts[0].part_type == BodyMailPartType.Main
- assert len(mail_parts) == 2
- assert mail_parts[1].text == 'c'
- assert mail_parts[1].part_type == BodyMailPartType.Signature
-
- def test_unit__drop_part_type_verify_no_follow_incidence(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._list.append(a)
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._list.append(b)
- c = BodyMailPart('c', BodyMailPartType.Signature)
- mail_parts._list.append(c)
- mail_parts.follow = True
- mail_parts.drop_part_type(BodyMailPartType.Quote)
- assert len(mail_parts) == 2
- assert mail_parts[0].text == 'a'
- assert mail_parts[0].part_type == BodyMailPartType.Main
- assert len(mail_parts) == 2
- assert mail_parts[1].text == 'c'
- assert mail_parts[1].part_type == BodyMailPartType.Signature
-
- def test_unit__drop_part_type_consistence(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._list.append(a)
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._list.append(b)
- c = BodyMailPart('c', BodyMailPartType.Main)
- mail_parts._list.append(c)
- mail_parts.drop_part_type(BodyMailPartType.Quote)
- assert len(mail_parts) == 1
- assert mail_parts[0].text == 'ac'
- assert mail_parts[0].part_type == BodyMailPartType.Main
-
- def test_unit__get_nb_part_type(self):
- mail_parts = BodyMailParts()
- assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 0
- assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 0
- assert mail_parts.get_nb_part_type(BodyMailPartType.Signature) == 0
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._list.append(a)
- assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 1
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._list.append(b)
- assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 1
- c = BodyMailPart('c', BodyMailPartType.Signature)
- mail_parts._list.append(c)
- assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 1
- assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 1
- assert mail_parts.get_nb_part_type(BodyMailPartType.Signature) == 1
-
- def test_unit__str(self):
- mail_parts = BodyMailParts()
- a = BodyMailPart('a', BodyMailPartType.Main)
- mail_parts._list.append(a)
- b = BodyMailPart('b', BodyMailPartType.Quote)
- mail_parts._list.append(b)
- c = BodyMailPart('c', BodyMailPartType.Signature)
- mail_parts._list.append(c)
- assert str(mail_parts) == 'abc'
-
-
- class TestParsedMail(TestStandard):
-
- def test_other__check_gmail_mail_text_only(self):
- text_only = '''<div dir="ltr">Voici le texte<br></div>'''
- mail = ParsedHTMLMail(text_only)
- elements = mail.get_elements()
- assert len(elements) == 1
- assert elements[0].part_type == BodyMailPartType.Main
-
- def test_other__check_gmail_mail_text_signature(self):
- text_and_signature = '''
- <div dir="ltr">POF<br clear="all"><div><br>-- <br>
- <div class="gmail_signature" data-smartmail="gmail_signature">
- <div dir="ltr">Voici Ma signature. En HTML <br><ol>
- <li>Plop</li>
- <li>Plip</li>
- <li>Plop<br>
- </li></ol></div></div></div></div>
- '''
- mail = ParsedHTMLMail(text_and_signature)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Signature
-
- def test_other__check_gmail_mail_text_quote(self):
- text_and_quote = '''
- <div dir="ltr">Réponse<br>
- <div class="gmail_extra"><br>
- <div class="gmail_quote">Le 28 novembre 2017 à 10:29, John Doe <span
- dir="ltr"><<a href="mailto:bidule@localhost.fr"
- target="_blank">bidule@localhost.fr</a>></span>
- a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma réponse<br>
- <br><br>
- Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">
- Voici le texte<span class="HOEnZb"><font color="#888888"><br>
- </font></span></blockquote>
- <span class="HOEnZb"><font color="#888888">
- <br>
- -- <br>
- TEST DE signature<br>
- </font></span></blockquote>
- </div><br></div></div>
- '''
- mail = ParsedHTMLMail(text_and_quote)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
-
- def test_other__check_gmail_mail_text_quote_text(self):
- text_quote_text = '''
- <div dir="ltr">Avant<br>
- <div class="gmail_extra"><br>
- <div class="gmail_quote">Le 28 novembre 2017 à 10:29, John Doe
- <span dir="ltr"><<a href="mailto:bidule@localhost.fr"
- target="_blank">bidule@localhost.fr</a>></span>
- a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma
- réponse<br>
- <br>
- <br>
- Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">
- Voici le texte<span class="HOEnZb"><font color="#888888"><br>
- </font></span></blockquote>
- <span class="HOEnZb"><font color="#888888">
- <br>
- -- <br>
- TEST DE signature<br>
- </font></span></blockquote>
- </div>
- <br>
- </div>
- <div class="gmail_extra">Aprés<br>
- </div>
- </div>
- '''
-
- mail = ParsedHTMLMail(text_quote_text)
- elements = mail.get_elements()
- assert len(elements) == 3
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
- assert elements[2].part_type == BodyMailPartType.Main
-
- def test_other__check_gmail_mail_text_quote_signature(self):
- text_quote_signature = '''
- <div dir="ltr">Hey !<br>
- </div>
- <div class="gmail_extra"><br>
- <div class="gmail_quote">Le 28 novembre 2017 à 10:29,
- John Doe <span
- dir="ltr"><<a href="mailto:bidule@localhost.fr"
- target="_blank">bidule@localhost.fr</a>></span>
- a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma
- réponse<br>
- <br>
- <br>
- Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">
- Voici le texte<span class="HOEnZb"><font color="#888888"><br>
- </font></span></blockquote>
- <span class="HOEnZb"><font color="#888888">
- <br>
- -- <br>
- TEST DE signature<br>
- </font></span></blockquote>
- </div>
- <br>
- <br clear="all">
- <br>
- -- <br>
- <div class="gmail_signature" data-smartmail="gmail_signature">
- <div dir="ltr">Voici Ma signature. En HTML <br>
- <ol>
- <li>Plop</li>
- <li>Plip</li>
- <li>Plop<br>
- </li>
- </ol>
- </div>
- </div>
- </div>
- '''
-
- # INFO - G.M - 2017-11-28 -
- # Now Quote + Signature block in Gmail is considered as one Quote
- # Block.
- mail = ParsedHTMLMail(text_quote_signature)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
-
- def test_other__check_gmail_mail_text_quote_text_signature(self):
- text_quote_text_sign = '''
- <div dir="ltr">Test<br>
- <div class="gmail_extra"><br>
- <div class="gmail_quote">Le 28 novembre 2017 à 10:29, John Doe <span
- dir="ltr"><<a href="mailto:bidule@localhost.fr"
- target="_blank">bidule@localhost.fr</a>></span>
- a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">Voici ma
- réponse<br>
- <br>
- <br>
- Le 28/11/2017 à 10:05, Foo Bar a écrit :<br>
- <blockquote class="gmail_quote" style="margin:0 0 0
- .8ex;border-left:1px #ccc solid;padding-left:1ex">
- Voici le texte<span class="HOEnZb"><font color="#888888"><br>
- </font></span></blockquote>
- <span class="HOEnZb"><font color="#888888">
- <br>
- -- <br>
- TEST DE signature<br>
- </font></span></blockquote>
- </div>
- <br>
- <br>
- </div>
- <div class="gmail_extra">RE test<br clear="all">
- </div>
- <div class="gmail_extra"><br>
- -- <br>
- <div class="gmail_signature" data-smartmail="gmail_signature">
- <div dir="ltr">Voici Ma signature. En HTML <br>
- <ol>
- <li>Plop</li>
- <li>Plip</li>
- <li>Plop<br>
- </li>
- </ol>
- </div>
- </div>
- </div>
- </div>
- '''
-
- mail = ParsedHTMLMail(text_quote_text_sign)
- elements = mail.get_elements()
- assert len(elements) == 4
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
- assert elements[2].part_type == BodyMailPartType.Main
- assert elements[3].part_type == BodyMailPartType.Signature
-
- def test_other__check_thunderbird_mail_text_only(self):
-
- text_only = '''Coucou<br><br><br>'''
- mail = ParsedHTMLMail(text_only)
- elements = mail.get_elements()
- assert len(elements) == 1
- assert elements[0].part_type == BodyMailPartType.Main
-
- def test_other__check_thunderbird_mail_text_signature(self):
- text_and_signature = '''
- <p>Test<br>
- </p>
- <div class="moz-signature">-- <br>
- TEST DE signature</div>
- '''
- mail = ParsedHTMLMail(text_and_signature)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Signature
-
- def test_other__check_thunderbird_mail_text_quote(self):
- text_and_quote = '''
- <p>Pof<br>
- </p>
- <br>
- <div class="moz-cite-prefix">Le 28/11/2017 à 11:21, John Doe a
- écrit :<br>
- </div>
- <blockquote type="cite"
- cite="mid:658592c1-14de-2958-5187-3571edea0aac@localhost.fr">
- <meta http-equiv="Context-Type"
- content="text/html; charset=utf-8">
- <p>Test<br>
- </p>
- <div class="moz-signature">-- <br>
- TEST DE signature</div>
- </blockquote>
- <br>
- '''
- mail = ParsedHTMLMail(text_and_quote)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
-
- def test_other__check_thunderbird_mail_text_quote_text(self):
- text_quote_text = '''
- <p>Pof<br>
- </p>
- <br>
- <div class="moz-cite-prefix">Le 28/11/2017 à 11:54,
- Bidule a
- écrit :<br>
- </div>
- <blockquote type="cite"
- cite="mid:b541b451-bb31-77a4-45b9-ad89969d7962@localhost.fr">
- <meta http-equiv="Context-Type"
- content="text/html; charset=utf-8">
- <p>Pof<br>
- </p>
- <br>
- <div class="moz-cite-prefix">Le 28/11/2017 à 11:21, John Doe a
- écrit :<br>
- </div>
- <blockquote type="cite"
- cite="mid:658592c1-14de-2958-5187-3571edea0aac@localhost.fr">
- <p>Test<br>
- </p>
- <div class="moz-signature">-- <br>
- TEST DE signature</div>
- </blockquote>
- <br>
- </blockquote>
- Pif<br>
- '''
-
- mail = ParsedHTMLMail(text_quote_text)
- elements = mail.get_elements()
- assert len(elements) == 3
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
- assert elements[2].part_type == BodyMailPartType.Main
-
- def test_other__check_thunderbird_mail_text_quote_signature(self):
- text_quote_signature = '''
- <p>Coucou<br>
- </p>
- <br>
- <div class="moz-cite-prefix">Le 28/11/2017 à 11:22, Bidule a
- écrit :<br>
- </div>
- <blockquote type="cite"
- cite="mid:4e6923e2-796d-eccf-84b7-6824da4151ee@localhost.fr">Réponse<br>
- <br>
- Le 28/11/2017 à 11:21, John Doe a écrit : <br>
- <blockquote type="cite"> <br>
- Test <br>
- <br>
- -- <br>
- TEST DE signature <br>
- </blockquote>
- <br>
- </blockquote>
- <br>
- <div class="moz-signature">-- <br>
- TEST DE signature</div>
- '''
-
- mail = ParsedHTMLMail(text_quote_signature)
- elements = mail.get_elements()
- assert len(elements) == 3
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
- assert elements[2].part_type == BodyMailPartType.Signature
-
- def test_other__check_thunderbird_mail_text_quote_text_signature(self):
- text_quote_text_sign = '''
- <p>Avant<br>
- </p>
- <br>
- <div class="moz-cite-prefix">Le 28/11/2017 à 11:19, Bidule a
- écrit :<br>
- </div>
- <blockquote type="cite"
- cite="mid:635df73c-d3c9-f2e9-2304-24ff536bfa16@localhost.fr">Coucou
- <br><br>
- </blockquote>
- Aprés<br>
- <br>
- <div class="moz-signature">-- <br>
- TEST DE signature</div>
- '''
-
- mail = ParsedHTMLMail(text_quote_text_sign)
- elements = mail.get_elements()
- assert len(elements) == 4
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
- assert elements[2].part_type == BodyMailPartType.Main
- assert elements[3].part_type == BodyMailPartType.Signature
-
- # INFO - G.M - 2017-11-28 - Test for outlook.com webapp html mail
- # outlook.com ui doesn't seems to allow complex reply, new message
- # and signature are always before quoted one.
-
- def test_other__check_outlook_com_mail_text_only(self):
-
- text_only = '''
- <div id="divtagdefaultwrapper"
- style="font-size:12pt;color:#000000;
- font-family:Calibri,Helvetica,sans-serif;"
- dir="ltr">
- <p style="margin-top:0;margin-bottom:0">message<br>
- </p>
- </div>
- '''
- mail = ParsedHTMLMail(text_only)
- elements = mail.get_elements()
- assert len(elements) == 1
- assert elements[0].part_type == BodyMailPartType.Main
-
- def test_other__check_outlook_com_mail_text_signature(self):
- text_and_signature = '''
- <div id="divtagdefaultwrapper"
- style="font-size:12pt;color:#000000;
- font-family:Calibri,Helvetica,sans-serif;"
- dir="ltr">
- <p style="margin-top:0;margin-bottom:0">Test<br>
- </p>
- <p style="margin-top:0;margin-bottom:0"><br>
- </p>
- <div id="Signature">
- <div id="divtagdefaultwrapper" style="font-size: 12pt; color:
- rgb(0, 0, 0); background-color: rgb(255, 255, 255);
- font-family:
- Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple
- Color Emoji","Segoe UI
- Emoji",NotoColorEmoji,"Segoe UI
- Symbol","Android Emoji",EmojiSymbols;">
- Envoyé à partir de <a href="http://aka.ms/weboutlook"
- id="LPNoLP">Outlook</a></div>
- </div>
- </div>
- '''
- mail = ParsedHTMLMail(text_and_signature)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Signature
-
- def test_other__check_outlook_com_mail_text_quote(self):
- text_and_quote = '''
- <div id="divtagdefaultwrapper"
- style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
- dir="ltr">
- <p style="margin-top:0;margin-bottom:0">Salut !<br>
- </p>
- </div>
- <hr style="display:inline-block;width:98%" tabindex="-1">
- <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
- color="#000000" face="Calibri, sans-serif"><b>De :</b> John Doe<br>
- <b>Envoyé :</b> mardi 28 novembre 2017 12:44:59<br>
- <b>À :</b> dev.bidule@localhost.fr<br>
- <b>Objet :</b> voila</font>
- <div> </div>
- </div>
- <style type="text/css" style="display:none">
- <!--
- p
- 	{margin-top:0;
- 	margin-bottom:0}
- -->
- </style>
- <div dir="ltr">
- <div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt;
- color:#000000; font-family:Calibri,Helvetica,sans-serif">
- Contenu
- <p style="margin-top:0; margin-bottom:0"><br>
- </p>
- <div id="x_Signature">
- <div id="x_divtagdefaultwrapper" dir="ltr"
- style="font-size:12pt; color:rgb(0,0,0);
- background-color:rgb(255,255,255);
- font-family:Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple
- Color Emoji","Segoe UI
- Emoji",NotoColorEmoji,"Segoe UI
- Symbol","Android Emoji",EmojiSymbols">
- DLMQDNLQNDMLQS<br>
- qs<br>
- dqsd<br>
- d<br>
- qsd<br>
- </div>
- </div>
- </div>
- </div>
- '''
- mail = ParsedHTMLMail(text_and_quote)
- elements = mail.get_elements()
- assert len(elements) == 2
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Quote
-
- def test_other__check_outlook_com_mail_text_signature_quote(self):
- text_signature_quote = '''
- <div id="divtagdefaultwrapper"
- style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;"
- dir="ltr">
- <p style="margin-top:0;margin-bottom:0">Salut !<br>
- </p>
- <p style="margin-top:0;margin-bottom:0"><br>
- </p>
- <div id="Signature">
- <div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt;
- color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);
- font-family:
- Calibri,Arial,Helvetica,sans-serif,"EmojiFont","Apple
- Color Emoji","Segoe UI
- Emoji",NotoColorEmoji,"Segoe UI
- Symbol","Android Emoji",EmojiSymbols;">
- Envoyée depuis Outlook<br>
- </div>
- </div>
- </div>
- <hr style="display:inline-block;width:98%" tabindex="-1">
- <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
- color="#000000" face="Calibri, sans-serif"><b>De :</b> John Doe
- <dev.bidule@localhost.fr><br>
- <b>Envoyé :</b> mardi 28 novembre 2017 12:51:42<br>
- <b>À :</b> John Doe<br>
- <b>Objet :</b> Re: Test</font>
- <div> </div>
- </div>
- <div style="background-color:#FFFFFF">
- <p>Coucou<br>
- </p>
- <br>
- <div class="x_moz-cite-prefix">Le 28/11/2017 à 12:39, John Doe a
- écrit :<br>
- </div>
- <blockquote type="cite">
- <div id="x_divtagdefaultwrapper" dir="ltr">
- <p>Test<br>
- </p>
- <p><br>
- </p>
- <div id="x_Signature">
- <div id="x_divtagdefaultwrapper">Envoyé à partir de <a
- href="http://aka.ms/weboutlook" id="LPNoLP">
- Outlook</a></div>
- </div>
- </div>
- </blockquote>
- <br>
- <div class="x_moz-signature">-- <br>
- TEST DE signature</div>
- </div>
- '''
-
- mail = ParsedHTMLMail(text_signature_quote)
- elements = mail.get_elements()
- assert len(elements) == 3
- assert elements[0].part_type == BodyMailPartType.Main
- assert elements[1].part_type == BodyMailPartType.Signature
- assert elements[2].part_type == BodyMailPartType.Quote
|