all repos — listfix @ b31eac9fad56cc05e0cbdd6e4fdc350d04ecf67d

Postfix Mailing List Software; Maintained on behalf the of Agency Economy Incorporated NFP.

Improve strip_headers code.

	modified:   listfix/email.py
Brian Barto bartobrian@gmail.com
Fri, 01 Apr 2022 14:45:01 -0400
commit

b31eac9fad56cc05e0cbdd6e4fdc350d04ecf67d

parent

c36d302e757ae7eecc0be76b94402504e67ca191

1 files changed, 15 insertions(+), 23 deletions(-)

jump to
M listfix/email.pylistfix/email.py

@@ -40,7 +40,7 @@ if (re_header.match(line)):

header = line.rstrip() i += 1 while (i < len(headers) and re_header_cont.match(headers[i])): - header = header + " " + headers[i].lstrip().rstrip() + header = header + "\n" + headers[i].rstrip() i += 1 break

@@ -73,30 +73,22 @@ return False

if (auto_sub_line and re_auto_reply.match(auto_sub_line)): return True - def strip_headers(self, exclude=[]): - stripped_content = [] - append_next = False - in_header = True - for line in self.content: - if (in_header): - if (re_header_cont.match(line) and append_next): - stripped_content.append(line) - continue + def strip_headers(self, exclude): + ex_string = "|".join(exclude) + re_exclude = re.compile("^(" + ex_string + "): ", re.IGNORECASE) - if (re_header_end.match(line)): - stripped_content.append(line) - in_header = False - continue - - append_next = False - for ex in exclude: - if (re.match("^" + ex + ": ", line, re.IGNORECASE)): - stripped_content.append(line) - append_next = True - break + j = 0 + header_cont = False + for i, header in enumerate(self.get_headers()): + if (re_exclude.match(header)): + header_cont = True + continue + elif (header_cont == True and re_header_cont.match(header)): + continue else: - stripped_content.append(line) - self.content = stripped_content[:] + del self.content[i-j] + header_cont = False + j += 1 def add_header(self, header): header = header.rstrip() + "\n"