Пример #1
0
    def test_sparrow_forward(self):
        # Sparrow forward
        self.assertEqual(unwrap("""Hello

Forwarded message:

> From: Some One <*****@*****.**>
> To: Other person <*****@*****.**>
> Date: Thursday, March 7, 2013 7:09:41 PM
> Subject: Re: Syncing Up
>
> OHAI
>
> Great news!

Text bottom
"""), {
            'text_top': 'Hello',
            'type': 'forward',
            'from': 'Some One <*****@*****.**>',
            'date': 'Thursday, March 7, 2013 7:09:41 PM',
            'subject': 'Re: Syncing Up',
            'to': 'Other person <*****@*****.**>',
            'text': 'OHAI\n\nGreat news!',
            'text_bottom': 'Text bottom',
        })
Пример #2
0
    def test_forward_no_headers(self):
        # No quote / headers in forwarded message
        self.assertEqual(unwrap("""Begin forwarded message:
Hello
"""), {
            'type': 'forward',
            'text': 'Hello',
        })
Пример #3
0
    def test_no_message(self):
        # No message
        self.assertEqual(unwrap("""hello world

Hey: This is very important

> No quoted message (just one line).
"""), None)
Пример #4
0
    def test_reply_1(self):
        data = unwrap("""Hello world.

On 2012-10-16 at 17:02 , Someone <*****@*****.**> wrote:

> Some quoted text
""")
        # TODO: parsing replies is not fully implemented
        self.assertEqual(data['type'], 'reply')
Пример #5
0
 def remove_replies(email_contents):
     r = quotequail.unwrap(email_contents)
     if r is None:
         return email_contents
     if "text_top" in r:
         return r["text_top"]
     elif "text" in r:
         return r["text"]
     return email_contents
Пример #6
0
    def test_long_subject(self):
        self.assertEqual(unwrap("""---------- Forwarded message ----------
From: Someone <*****@*****.**>
Subject: The email has a very long and confusing subject with spans over
multiple lines.
To: Destination <*****@*****.**>

Email text.
"""), {
            'type': 'forward',
            'from': 'Someone <*****@*****.**>',
            'to': 'Destination <*****@*****.**>',
            'subject': 'The email has a very long and confusing subject with spans over multiple lines.',
            'text': 'Email text.',
        })
def get_mail_body(msg):
    body = ''
    maintype = msg.get_content_maintype()
    if maintype == 'text':
        charset = msg.get_content_charset()
        body = body + msg.get_payload(decode=True)
    body = body.decode('ascii', 'ignore')
    if (bool(BeautifulSoup(body, "html.parser").find())):
        body = h.handle(body)
    z = quotequail.unwrap(body)

    if z is not None:
        if 'text_top' in z:
            body = z["text_top"]
    body = zp.parse(body)['body']
    return body
Пример #8
0
    def test_confusing_email_signature(self):
        self.assertEqual(unwrap("""Phone: 12345
Fax: 67890
Skype: foobar

---------- Forwarded message ----------
From: Someone <*****@*****.**>
Subject: The email

Email text.
"""), {
            'text_top': 'Phone: 12345\nFax: 67890\nSkype: foobar',
            'type': 'forward',
            'from': 'Someone <*****@*****.**>',
            'subject': 'The email',
            'text': 'Email text.',
        })
Пример #9
0
    def test_french(self):
        self.assertEqual(unwrap(u"""
De : Someone <*****@*****.**>
Répondre à : Reply <*****@*****.**>
Date : Wednesday, 17 September 2014 4:24 pm
À : "Someone Else" <*****@*****.**>
Objet : Re: test subject

Hello, thanks for your reply
        """), {
            'type': 'forward',
            'date': u'Wednesday, 17 September 2014 4:24 pm',
            'from': u'Someone <*****@*****.**>',
            'reply-to': 'Reply <*****@*****.**>',
            'to': u'"Someone Else" <*****@*****.**>',
            'subject': u'Re: test subject',
            'text': u'Hello, thanks for your reply',
        })
Пример #10
0
    def test_quote(self):
        # Just a quote
        self.assertEqual(unwrap("""hello world

Hey: This is very important

> Lorem ipsum
> dolor sit amet
> adipiscing elit.

--
kthxbye
"""), {
            'type': 'quote',
            'text_top': 'hello world\n\nHey: This is very important',
            'text': 'Lorem ipsum\ndolor sit amet\nadipiscing elit.',
            'text_bottom': '--\nkthxbye',
        })
Пример #11
0
    def test_outlook_forward(self):
        # Outlook?
        self.assertEqual(unwrap("""-------- Original Message --------
Subject: \tSome Newsletter
Date: \tFri, 19 Jun 2009 19:16:04 +0200
From: \tfrom <*****@*****.**>
Reply-To: \treply <*****@*****.**>
To: \[email protected]

OHAI"""), {
            'type': 'forward',
            'from': 'from <*****@*****.**>',
            'reply-to': 'reply <*****@*****.**>',
            'date': 'Fri, 19 Jun 2009 19:16:04 +0200',
            'subject': 'Some Newsletter',
            'to': '*****@*****.**',
            'reply-to': 'reply <*****@*****.**>',
            'text': 'OHAI',
        })
Пример #12
0
    def test_no_forward_text_quoted(self):
        # No forwarding message text
        self.assertEqual(unwrap("""Hello

> From: "Some One" <*****@*****.**>
> Date: 1. August 2011 23:28:15 GMT-07:00
> To: "Other Person" <*****@*****.**>
> Subject: AW: AW: Some subject
>
> Original text
"""), {
            'text_top': 'Hello',
            'type': 'forward',
            'from': '"Some One" <*****@*****.**>',
            'date': '1. August 2011 23:28:15 GMT-07:00',
            'subject': 'AW: AW: Some subject',
            'to': '"Other Person" <*****@*****.**>',
            'text': 'Original text',
        })
Пример #13
0
    def test_forward_french_thunderbird(self):
        self.assertEqual(unwrap(u'''
Text before

-------- Message transféré --------
Sujet :     Re: Some subject
Date :  Wed, 11 Nov 2015 12:31:25 +0100
De :    Foo Bar <*****@*****.**>
Pour :  Ham Spam <*****@*****.**>

Text after
'''), {
            'date': u'Wed, 11 Nov 2015 12:31:25 +0100',
            'from': u'Foo Bar <*****@*****.**>',
            'subject': 'Re: Some subject',
            'text': u'Text after',
            'text_top': u'Text before',
            'to': u'Ham Spam <*****@*****.**>',
            'type': 'forward'
        })
Пример #14
0
    def test_bold_headers(self):
        # Forwrad with *bold* text
        self.assertEqual(unwrap("""Hello

Forwarded message:

*From:* Some One <*****@*****.**>
*To:* Other Person <*****@*****.**>
*Date:* Wednesday, February 6, 2013 7:46:53 AM
*Subject:* Fwd: Hottest Startups

This is interesting."""), {
            'text_top': 'Hello',
            'type': 'forward',
            'from': 'Some One <*****@*****.**>',
            'date': 'Wednesday, February 6, 2013 7:46:53 AM',
            'subject': 'Fwd: Hottest Startups',
            'to': 'Other Person <*****@*****.**>',
            'text': 'This is interesting.',
        })
Пример #15
0
    def test_gmail_forward(self):
        # Gmail forward
        self.assertEqual(unwrap("""Hello

---------- Forwarded message ----------
From: Someone <*****@*****.**>
Date: Fri, Apr 26, 2013 at 8:13 PM
Subject: Weekend Spanish classes
To: [email protected]

Spanish Classes
Learn Spanish
"""), {
            'text_top': 'Hello',
            'type': 'forward',
            'from': 'Someone <*****@*****.**>',
            'date': 'Fri, Apr 26, 2013 at 8:13 PM',
            'subject': 'Weekend Spanish classes',
            'to': '*****@*****.**',
            'text': 'Spanish Classes\nLearn Spanish',
        })
Пример #16
0
    def test_forward_french_apple_mail(self):
        self.assertEqual(unwrap(u'''
Text before

Début du message réexpédié :

De: "Foo Bar" <*****@*****.**>
Date: 14 novembre 2015 15:14:53 UTC+1
À: "'Ham Spam'" <*****@*****.**>
Objet: RE: The subject

Text after
'''), {
            'date': u'14 novembre 2015 15:14:53 UTC+1',
            'from': u'"Foo Bar" <*****@*****.**>',
            'subject': 'RE: The subject',
            'text': u'Text after',
            'text_top': u'Text before',
            'to': u'"\'Ham Spam\'" <*****@*****.**>',
            'type': 'forward'
        })
Пример #17
0
    def test_spacing(self):
        # Some clients (Blackberry?) have weird whitespace rules
        self.assertEqual(unwrap("""hello world

-----Original Message-----
From: "Some One" <*****@*****.**>

Date: Sat, 22 Mar 2008 12:16:06
To:<*****@*****.**>


Subject: Antw: FW: html


OHAI...
"""), {
            'text_top': 'hello world',
            'type': 'forward',
            'from': '"Some One" <*****@*****.**>',
            'date': 'Sat, 22 Mar 2008 12:16:06',
            'subject': 'Antw: FW: html',
            'to': '<*****@*****.**>',
            'text': 'OHAI...',
        })
Пример #18
0
    def test_apple_forward_2(self):
        # Apple Mail (10.10) forward
        self.assertEqual(unwrap("""Hello

> Begin forwarded message:
>
> From: "Some One" <*****@*****.**>
> Date: 1. August 2011 23:28:15 GMT-07:00
> To: "Other Person" <*****@*****.**>
> Subject: AW: AW: Some subject
>
> Original text

Text bottom
"""), {
            'text_top': 'Hello',
            'type': 'forward',
            'from': '"Some One" <*****@*****.**>',
            'date': '1. August 2011 23:28:15 GMT-07:00',
            'subject': 'AW: AW: Some subject',
            'to': '"Other Person" <*****@*****.**>',
            'text': 'Original text',
            'text_bottom': 'Text bottom',
        })