diff --git a/talon/quotations.py b/talon/quotations.py index e4ab2bb..1a8c4e8 100644 --- a/talon/quotations.py +++ b/talon/quotations.py @@ -188,7 +188,7 @@ def extract_from(msg_body, content_type='text/plain'): return msg_body -def mark_message_lines(lines): +def mark_message_lines(lines, ignore_initial_spaces=False): """Mark message lines with markers to distinguish quotation lines. Markers: @@ -204,6 +204,8 @@ def mark_message_lines(lines): markers = ['e' for _ in lines] i = 0 while i < len(lines): + if ignore_initial_spaces: + lines[i] = lines[i].lstrip(' ') if not lines[i].strip(): markers[i] = 'e' # empty line elif QUOT_PATTERN.match(lines[i]): @@ -480,10 +482,11 @@ def split_emails(msg): Return the corrected markers """ msg_body = _replace_link_brackets(msg) + ignore_initial_spaces = True # don't process too long messages lines = msg_body.splitlines()[:MAX_LINES_COUNT] - markers = mark_message_lines(lines) + markers = mark_message_lines(lines, ignore_initial_spaces) markers = _mark_quoted_email_splitlines(markers, lines) diff --git a/tests/text_quotations_test.py b/tests/text_quotations_test.py index 9d7deb0..6a87e9b 100644 --- a/tests/text_quotations_test.py +++ b/tests/text_quotations_test.py @@ -700,36 +700,48 @@ def test_standard_replies(): def test_split_email(): msg = """From: Mr. X -Date: 24 February 2016 -To: Mr. Y -Subject: Hi -Attachments: none -Goodbye. -From: Mr. Y -To: Mr. X -Date: 24 February 2016 -Subject: Hi -Attachments: none + Date: 24 February 2016 + To: Mr. Y + Subject: Hi + Attachments: none + Goodbye. + From: Mr. Y + To: Mr. X + Date: 24 February 2016 + Subject: Hi + Attachments: none -Hello. + Hello. --- Original Message -- -On 24th February 2016 at 09.32am Conal Wrote: -Hey! + On 24th February 2016 at 09.32am, Conal Wrote: -> Date: Mon, 2 Apr 2012 17:44:22 +0400 -> Subject: Test -> From: bob@xxx.mailgun.org -> To: xxx@gmail.com; xxx@hotmail.com; xxx@yahoo.com; xxx@aol.com; xxx@comcast.net; xxx@nyc.rr.com -> -> Hi -> -> > From: bob@xxx.mailgun.org -> > To: xxx@gmail.com; xxx@hotmail.com; xxx@yahoo.com; xxx@aol.com; xxx@comcast.net; xxx@nyc.rr.com -> > Date: Mon, 2 Apr 2012 17:44:22 +0400 -> > Subject: Test -> > Hi + Hey! + + On Mon, 2016-10-03 at 09:45 -0600, Stangel, Dan wrote: + > Mohan, + > + > We have not yet migrated the systems. + > + > Dan + > + > > -----Original Message----- + > > Date: Mon, 2 Apr 2012 17:44:22 +0400 + > > Subject: Test + > > From: bob@xxx.mailgun.org + > > To: xxx@gmail.com; xxx@hotmail.com; xxx@yahoo.com; xxx@aol.com; xxx@comcast.net; xxx@nyc.rr.com + > > + > > Hi + > > + > > > From: bob@xxx.mailgun.org + > > > To: xxx@gmail.com; xxx@hotmail.com; xxx@yahoo.com; xxx@aol.com; xxx@comcast.net; xxx@nyc.rr.com + > > > Date: Mon, 2 Apr 2012 17:44:22 +0400 + > > > Subject: Test + > > > Hi + > > > + > > + > + > """ - expected_markers = "stttttsttttetesttesmmmmmmsmmmm" + expected_markers = "stttttsttttetetetesmmmmmmssmmmmmmsmmmmmmmm" markers = quotations.split_emails(msg) eq_(markers, expected_markers)