all repos — listfix @ 91ea57e1c8b0f8e97e08fe371d6a3403bae6ffac

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

Add destory command to remove email list and all recipients.

	modified:   listfix_filter.py
Brian Barto bartobrian@gmail.com
Wed, 23 Mar 2022 17:28:07 -0400
commit

91ea57e1c8b0f8e97e08fe371d6a3403bae6ffac

parent

04069e48fbcdcc00ec5a4a323d81d3ba68d9ccbc

1 files changed, 42 insertions(+), 3 deletions(-)

jump to
M listfix_filter.pylistfix_filter.py

@@ -357,7 +357,6 @@

def command_create(): list_email = None - list_id = None list_name = None ## Check args

@@ -389,6 +388,42 @@ print(f"New list ({list_email}) added.")

return True +def command_destroy(): + + list_email = None + list_id = None + + ## Check args + + if (len(sys.argv) >= 3): + if (not re_email_arg.match(sys.argv[2])): + print(f"Invalid argument for destroy command: {sys.argv[2]}") + return False + else: + print(f"Missing argument for destroy command.") + return False + + list_email = sys.argv[2] + + ## Get id from database + + row = db.execute("SELECT id FROM lists WHERE email = ?", [list_email]).fetchone() + if (not row): + print(f"Email list {list_email} not defined in database.") + return False + + list_id = row[0] + + ## Delete from database + + db.execute("DELETE FROM lists WHERE id = ?", [list_id]) + db.execute("DELETE FROM recipients WHERE list_id = ?", [list_id]) + db.commit() + + print(f"Email list ({list_email}) deleted.") + + return True + def command_add(): list_email = None

@@ -446,10 +481,10 @@ ## Check Args

if (len(sys.argv) >= 4): if (not re_email_arg.match(sys.argv[2]) or not re_email_arg.match(sys.argv[3])): - print(f"Invalid arguments for add command: {sys.argv[2]}, {sys.argv[3]}") + print(f"Invalid arguments for remove command: {sys.argv[2]}, {sys.argv[3]}") return False else: - print(f"Missing arguments for add command.") + print(f"Missing arguments for remove command.") return False list_email = sys.argv[2]

@@ -519,6 +554,10 @@ elif (command == "create"):

rval = command_create() if (not rval): raise ValueError(f"Error while executing command_create()") +elif (command == "destroy"): + rval = command_destroy() + if (not rval): + raise ValueError(f"Error while executing command_destroy()") elif (command == "add"): rval = command_add() if (not rval):