Example #1
0
    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&nbsp;:<br>
        </div>
        <blockquote type="cite"
        cite="mid:[email protected]">Réponse<br>
        <br>
        Le 28/11/2017 à 11:21, John Doe a écrit&nbsp;: <br>
        <blockquote type="cite"> <br>
        Test <br>
        <br>
        --&nbsp;<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
Example #2
0
 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,&quot;EmojiFont&quot;,&quot;Apple
           Color Emoji&quot;,&quot;Segoe UI
           Emoji&quot;,NotoColorEmoji,&quot;Segoe UI
           Symbol&quot;,&quot;Android Emoji&quot;,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
Example #3
0
    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&nbsp;:<br>
        </div>
        <blockquote type="cite"
          cite="mid:[email protected]">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
Example #4
0
    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
Example #5
0
 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">&lt;<a href="mailto:[email protected]"
     target="_blank">[email protected]</a>&gt;</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&nbsp;:<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
Example #6
0
 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
Example #7
0
 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> [email protected]<br>
     <b>Objet :</b> voila</font>
     <div>&nbsp;</div>
     </div>
     <style type="text/css" style="display:none">
     <!--
     p
     &#x09;{margin-top:0;
     &#x09;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,&quot;EmojiFont&quot;,&quot;Apple
         Color Emoji&quot;,&quot;Segoe UI
         Emoji&quot;,NotoColorEmoji,&quot;Segoe UI
         Symbol&quot;,&quot;Android Emoji&quot;,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
Example #8
0
    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">&lt;<a href="mailto:[email protected]"
                 target="_blank">[email protected]</a>&gt;</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&nbsp;:<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
Example #9
0
    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
Example #10
0
 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
Example #11
0
    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&nbsp;:<br>
        </div>
        <blockquote type="cite"
          cite="mid:[email protected]">
          <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&nbsp;:<br>
          </div>
          <blockquote type="cite"
            cite="mid:[email protected]">
            <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
Example #12
0
    def get_body(
        self,
        use_html_parsing=True,
        use_txt_parsing=True,
    ) -> typing.Optional[str]:
        body_part = self._get_mime_body_message()
        body = None
        if body_part:
            charset = body_part.get_content_charset('iso-8859-1')
            content_type = body_part.get_content_type()
            if content_type == CONTENT_TYPE_TEXT_PLAIN:
                txt_body = body_part.get_payload(decode=True).decode(charset)
                if use_txt_parsing:
                    txt_body = EmailReplyParser.parse_reply(txt_body)
                html_body = markdown.markdown(txt_body)
                body = HtmlSanitizer.sanitize(html_body)

            elif content_type == CONTENT_TYPE_TEXT_HTML:
                html_body = body_part.get_payload(decode=True).decode(charset)
                if use_html_parsing:
                    html_body = str(ParsedHTMLMail(html_body))
                body = HtmlSanitizer.sanitize(html_body)

        return body
Example #13
0
    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,&quot;EmojiFont&quot;,&quot;Apple
        Color Emoji&quot;,&quot;Segoe UI
        Emoji&quot;,NotoColorEmoji,&quot;Segoe UI
        Symbol&quot;,&quot;Android Emoji&quot;,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
        &lt;[email protected]&gt;<br>
        <b>Envoyé :</b> mardi 28 novembre 2017 12:51:42<br>
        <b>À :</b> John Doe<br>
        <b>Objet :</b> Re: Test</font>
        <div>&nbsp;</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&nbsp;:<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
Example #14
0
 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