From a2eb0f72015dd5d2453592e1dfa6d86560980528 Mon Sep 17 00:00:00 2001 From: smitcona Date: Tue, 14 Feb 2017 18:19:45 +0000 Subject: [PATCH] Creating new method which removes initial spaces and marks the message lines. Removing ambiguity introduced to mark_message_lines --- talon/quotations.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/talon/quotations.py b/talon/quotations.py index 811a21c..232c69d 100644 --- a/talon/quotations.py +++ b/talon/quotations.py @@ -188,7 +188,20 @@ def extract_from(msg_body, content_type='text/plain'): return msg_body -def mark_message_lines(lines, ignore_initial_spaces=False): +def remove_initial_spaces_and_mark_message_lines(lines): + """ + Removes the initial spaces in each line before marking message lines. + + This ensures headers can be identified if they are indented with spaces. + """ + i = 0 + while i < len(lines): + lines[i] = lines[i].lstrip(' ') + i += 1 + return mark_message_lines(lines) + + +def mark_message_lines(lines): """Mark message lines with markers to distinguish quotation lines. Markers: @@ -204,8 +217,6 @@ def mark_message_lines(lines, ignore_initial_spaces=False): 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]): @@ -489,7 +500,7 @@ def split_emails(msg): # don't process too long messages lines = msg_body.splitlines()[:MAX_LINES_COUNT] - markers = mark_message_lines(lines, ignore_initial_spaces=True) + markers = remove_initial_spaces_and_mark_message_lines(lines) markers = _mark_quoted_email_splitlines(markers, lines)