import html
import mailbox
+# for diff preparation:
+# normalize whitespace sequences to single space, for when people reply from
+# gmail, which turns tabs into spaces
def join_whitespace(text):
return ' '.join(text.split())
for line in self.message.lines.lines[self.start_pos_orig:self.start_pos_orig+self.length_orig]:
line.real_quote = True
+ #print('CREATED TEXT BLOCK, '+('quote' if self.is_quote else 'orig'))
+ #print('<<<')
+ #print(self.get_text())
+ #print('>>>')
+
# returns exclusive end
def end_pos_child(self):
return self.start_pos_child + self.length
def drop_quotes(self):
self.ranges = list(filter(lambda r: not r.is_quote, self.ranges))
+ # must only be called once all the blocks have been pulled up to their diff-root
def trim_blocks(self):
for r in self.ranges:
r.trim_blanks_and_trailing_quote_header()
def as_hashable_line(self):
return join_whitespace(self.text.strip())
+def dump_string_list(string_list):
+ for idx, line in enumerate(string_list):
+ print(str(idx) + ' ' + line)
+
class Lines:
def __init__(self, text):
self.plain_lines = text.split('\n')
return list(map(lambda line: line.as_hashable_inherited_line(), self.lines))
def diff_to_parent(self, msg, parent):
+ #print('A (parent):')
+ #dump_string_list(parent.as_hashable_list())
+ #print('B (child):')
+ #dump_string_list(self.as_hashable_inherited_list())
sm = difflib.SequenceMatcher((lambda line: line == None or line == ''), parent.as_hashable_list(), self.as_hashable_inherited_list())
inherited_chunks = sm.get_matching_blocks()
#print(inherited_chunks)