Remove the whitespace before the line if the flag is set

This commit is contained in:
smitcona
2017-02-03 12:57:26 +00:00
parent 3edb6578ba
commit 34c5b526c3
2 changed files with 44 additions and 29 deletions

View File

@@ -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)

View File

@@ -713,23 +713,35 @@ Attachments: none
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
> 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
On Mon, 2016-10-03 at 09:45 -0600, Stangel, Dan wrote:
> Mohan,
>
> Hi
> We have not yet migrated the systems.
>
> > 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
> 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)