all repos — listfix @ 0d94cacc881493397a1795c6f19ff0bbaf2cc4a0

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

Make content a required param for email init.

That way I don't have to always check if content exists in every other
method.

	modified:   listfix.py
	modified:   listfix/email.py
Brian Barto bartobrian@gmail.com
Tue, 29 Mar 2022 16:08:45 -0400
commit

0d94cacc881493397a1795c6f19ff0bbaf2cc4a0

parent

2c436afe9b73b8ebee1f1063fd20c9bc8917fb94

2 files changed, 5 insertions(+), 44 deletions(-)

jump to
M listfix.pylistfix.py

@@ -63,8 +63,7 @@ content = []

for line in sys.stdin: content.append(line) - email_in = Email() - email_in.set_content(content) + email_in = Email(content) if (email_in.is_auto_reply()): exit()

@@ -75,8 +74,7 @@

list_name = db.get_list_name(list_email) list_recipients = db.get_list_recipients(list_email) - email_out = Email() - email_out.set_content(email_in.get_content()) + email_out = Email(email_in.get_content()) email_out.strip_headers(exclude = ["To", "Cc", "Subject", "Content-[^:]+", "MIME-Version"]) if (sender_email not in list_recipients): email_out.add_header_prepend(f"Reply-To: {list_email}, {sender}")
M listfix/email.pylistfix/email.py

@@ -9,11 +9,9 @@ re_auto_reply = re.compile("^Auto-Submitted: (auto-generated|auto-replied)", re.IGNORECASE)

class Email: - def __init__(self): + def __init__(self, content): self.content = [] - return - def set_content(self, content): if (type(content) is list): if (len(content) > 0): self.content = content[:]

@@ -21,22 +19,14 @@ else:

return False else: return False - - return True def get_content(self): - if (len(self.content) == 0): - return False - return self.content[:] def get_header(self, header): rval = None - if (len(self.content) == 0): - return False - header = header.rstrip() if (header[-1] == ":"): header = header[0:-1]

@@ -65,9 +55,6 @@

def get_sender_email(self): sender_email = None - if (len(self.content) == 0): - return False - from_line = self.get_header("From") if (from_line): if (re_sender_info.match(from_line)):

@@ -83,9 +70,6 @@

def get_sender_name(self): sender_name = None - if (len(self.content) == 0): - return False - from_line = self.get_header("From") if (from_line): if (re_sender_info.match(from_line)):

@@ -99,19 +83,12 @@

return sender_name def is_auto_reply(self): - if (len(self.content) == 0): - return False - auto_sub_line = self.get_header("Auto-Submitted") if (auto_sub_line and re_auto_reply.match(auto_sub_line)): return True - return False def strip_headers(self, exclude): - if (len(self.content) == 0): - return False - stripped_content = [] append_next = False

@@ -141,32 +118,18 @@

return True def add_header(self, header): - if (len(self.content) == 0): - return False - header = header.rstrip() + "\n" - self.content.append(header) - - return + return True def add_header_prepend(self, header): - if (len(self.content) == 0): - return False - header = header.rstrip() + "\n" - self.content.insert(0, header) - - return + return True def send(self, recipient): - if (len(self.content) == 0): - return False - p = os.popen(f"/usr/sbin/sendmail -G -i {recipient}", "w") for line in self.content: p.write(line) p.close() - return True