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