def test_link_breaks_quotation_markers_sequence(): # link starts and ends on the same line msg_body = """Blah On Thursday, October 25, 2012 at 3:03 PM, life is short. on Bob wrote: > > Post a response by replying to this email > (http://example.com/c/YzOTYzMmE) > > life is short. (http://example.com/c/YzMmE) > """ eq_("Blah", quotations.extract_from_plain(msg_body)) # link starts after some text on one line and ends on another msg_body = """Blah On Monday, 24 September, 2012 at 3:46 PM, bob wrote: > [Ticket #50] test from bob > > View ticket (http://example.com/action _nonce=3dd518) > """ eq_("Blah", quotations.extract_from_plain(msg_body))
def test_short_quotation(): msg_body = """Hi On 04/19/2011 07:10 AM, Roman Tkachenko wrote: > Hello""" eq_("Hi", quotations.extract_from_plain(msg_body))
def test_too_many_lines(): msg_body = """Test reply -----Original Message----- Test""" eq_(msg_body, quotations.extract_from_plain(msg_body))
def test_reply_after_quotations(): msg_body = """On 04/19/2011 07:10 AM, Roman Tkachenko wrote: > > Test Test reply""" eq_("Test reply", quotations.extract_from_plain(msg_body))
def test_french_from_block(): eq_( 'Lorem ipsum', quotations.extract_from_plain(u"""Lorem ipsum Le 23 janv. 2015 à 22:03, Brendan xxx <[email protected]<mailto:[email protected]>> a écrit: Bonjour!"""))
def test_pattern_on_date_somebody_wrote_allows_space_in_front(): msg_body = """Thanks Thanmai On Mar 8, 2012 9:59 AM, "Example.com" < *****@*****.**> wrote: >** > Blah-blah-blah""" eq_("Thanks Thanmai", quotations.extract_from_plain(msg_body))
def test_pattern_on_date_wrote_somebody(): eq_( 'Lorem', quotations.extract_from_plain("""Lorem Op 13-02-2014 3:18 schreef Julius Caesar <*****@*****.**>: Veniam laborum mlkshk kale chips authentic. Normcore mumblecore laboris, fanny pack readymade eu blog chia pop-up freegan enim master cleanse. """))
def test_norwegian_from_line(): eq_( 'Lorem', quotations.extract_from_plain(u"""Lorem På 14 september 2015 på 02:23:18, Valentino Rudy ([email protected]) skrev: Veniam laborum mlkshk kale chips authentic. Normcore mumblecore laboris, fanny pack readymade eu blog chia pop-up freegan enim master cleanse. """))
def test_weird_date_format_in_date_block(): msg_body = """Blah Date: Fri=2C 28 Sep 2012 10:55:48 +0000 From: [email protected] To: [email protected] Subject: [Ticket #8] Test """ eq_('Blah', quotations.extract_from_plain(msg_body))
def test_polish_from_block(): eq_( 'Lorem ipsum', quotations.extract_from_plain(u"""Lorem ipsum W dniu 28 stycznia 2015 01:53 użytkownik Zoe xxx <*****@*****.**> napisał: Blah! """))
def test_german_from_block2(): eq_( 'Allo! Follow up MIME!', quotations.extract_from_plain("""Allo! Follow up MIME! Am 17-feb.-2015 schrieb Julius Caesar <*****@*****.**>: Blah-blah-blah """))
def test_with_indent(): msg_body = """YOLO salvia cillum kogi typewriter mumblecore cardigan skateboard Austin. ------On 12/29/1987 17:32 PM, Julius Caesar wrote----- Brunch mumblecore pug Marfa tofu, irure taxidermy hoodie readymade pariatur. """ eq_( "YOLO salvia cillum kogi typewriter mumblecore cardigan skateboard Austin.", quotations.extract_from_plain(msg_body))
def test_quotation_separator_takes_3_lines(): msg_body = """Test reply On Nov 30, 2011, at 12:47 PM, Somebody < *****@*****.**> wrote: Test message """ eq_("Test reply", quotations.extract_from_plain(msg_body))
def test_pattern_on_date_somebody_sent(): msg_body = """Test reply On 11-Apr-2011, at 6:54 PM, Roman Tkachenko <*****@*****.**> sent: > > Test > > Roman""" eq_("Test reply", quotations.extract_from_plain(msg_body))
def _check_pattern_original_message(original_message_indicator): msg_body = u"""Test reply -----{}----- Test""" eq_( 'Test reply', quotations.extract_from_plain( msg_body.format(unicode(original_message_indicator))))
def test_link_closed_with_quotation_marker_on_new_line(): msg_body = '''8.45am-1pm From: [email protected] <http://email.example.com/c/dHJhY2tpbmdfY29kZT1mMDdjYzBmNzM1ZjYzMGIxNT > <[email protected] <mailto:[email protected]> > Requester: ''' eq_('8.45am-1pm', quotations.extract_from_plain(msg_body))
def test_pattern_on_date_somebody_wrote_date_with_slashes(): msg_body = """Test reply On 04/19/2011 07:10 AM, Roman Tkachenko wrote: > > Test. > > Roman""" eq_("Test reply", quotations.extract_from_plain(msg_body))
def test_dutch_from_block(): eq_( 'Gluten-free culpa lo-fi et nesciunt nostrud.', quotations.extract_from_plain( """Gluten-free culpa lo-fi et nesciunt nostrud. Op 17-feb.-2015, om 13:18 heeft Julius Caesar <*****@*****.**> het volgende geschreven: Small batch beard laboris tempor, non listicle hella Tumblr heirloom. """))
def test_bold_from_block(): msg_body = """Hi *From:* [email protected] [mailto: [email protected]] *Sent:* Wednesday, June 27, 2012 3:05 PM *To:* [email protected] *Subject:* Hello """ eq_("Hi", quotations.extract_from_plain(msg_body))
def test_dont_parse_quotations_for_forwarded_messages(): msg_body = """FYI ---------- Forwarded message ---------- From: [email protected] Date: Tue, Sep 4, 2012 at 1:35 PM Subject: Two line subject To: [email protected] Text""" eq_(msg_body, quotations.extract_from_plain(msg_body))
def check_part(email_part): text = email_part.body parsed = quotations.extract_from_plain(text) reply_text_fn = filename[:-4] + '_reply_text' if os.path.isfile(reply_text_fn): with open(reply_text_fn) as f: expected_text = f.read() else: expected_text = 'Hello' assert parsed == expected_text, 'Parsed text was incorrect for file {0}'.format( filename)
def test_english_from_block(): eq_( 'Allo! Follow up MIME!', quotations.extract_from_plain("""Allo! Follow up MIME! From: [email protected] Sent: March-19-11 5:42 PM To: Somebody Subject: The manager has commented on your Loop Blah-blah-blah """))
def test_german_from_block(): eq_( 'Allo! Follow up MIME!', quotations.extract_from_plain("""Allo! Follow up MIME! Von: [email protected] Gesendet: Dienstag, 25. November 2014 14:59 An: Somebody Betreff: The manager has commented on your Loop Blah-blah-blah """))
def test_french_multiline_from_block(): eq_( 'Lorem ipsum', quotations.extract_from_plain(u"""Lorem ipsum De : Brendan xxx [mailto:[email protected]] Envoyé : vendredi 23 janvier 2015 16:39 À : Camille XXX Objet : Follow Up Blah-blah-blah """))
def test_danish_from_block(): eq_( 'Allo! Follow up MIME!', quotations.extract_from_plain("""Allo! Follow up MIME! Fra: [email protected] Sendt: 19. march 2011 12:10 Til: Somebody Emne: The manager has commented on your Loop Blah-blah-blah """))
def test_reply_and_quotation_splitter_share_line(): # reply lines and 'On <date> <person> wrote:' splitter pattern # are on the same line msg_body = """reply On Wed, Apr 4, 2012 at 3:59 PM, [email protected] wrote: > Hi""" eq_('reply', quotations.extract_from_plain(msg_body)) # test pattern '--- On <date> <person> wrote:' with reply text on # the same line msg_body = """reply--- On Wed, Apr 4, 2012 at 3:59 PM, [email protected] wrote: > Hi""" eq_('reply', quotations.extract_from_plain(msg_body)) # test pattern '--- On <date> <person> wrote:' with reply text containing # '-' symbol msg_body = """reply bla-bla - bla--- On Wed, Apr 4, 2012 at 3:59 PM, [email protected] wrote: > Hi""" reply = """reply bla-bla - bla""" eq_(reply, quotations.extract_from_plain(msg_body))
def test_swedish_from_block(): eq_( 'Allo! Follow up MIME!', quotations.extract_from_plain(u"""Allo! Follow up MIME! Från: Anno Sportel [mailto:[email protected]] Skickat: den 26 augusti 2015 14:45 Till: Isacson Leiff Ämne: RE: Week 36 Blah-blah-blah """))
def test_reply_wraps_quotations(): msg_body = """Test reply On 04/19/2011 07:10 AM, Roman Tkachenko wrote: > > Test Regards, Roman""" reply = """Test reply Regards, Roman""" eq_(reply, quotations.extract_from_plain(msg_body))
def test_short_quotation_with_newline(): msg_body = """Btw blah blah... On Tue, Jan 27, 2015 at 12:42 PM -0800, "Company" <*****@*****.**> wrote: Hi Mark, Blah blah? Thanks,Christine On Jan 27, 2015, at 11:55 AM, Mark XXX <*****@*****.**> wrote: Lorem ipsum? Mark Sent from Acompli""" eq_("Btw blah blah...", quotations.extract_from_plain(msg_body))
def test_forwarded_message_in_quotations(): msg_body = """Blah -----Original Message----- FYI ---------- Forwarded message ---------- From: [email protected] Date: Tue, Sep 4, 2012 at 1:35 PM Subject: Two line subject To: [email protected] """ eq_("Blah", quotations.extract_from_plain(msg_body))