From 914a774113f0a060f39defe30040c0d8d75152c2 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 27 Jan 2024 10:42:03 +0100 Subject: [PATCH] updated maildb state --- states/maildb/templates/maildb.py | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/states/maildb/templates/maildb.py b/states/maildb/templates/maildb.py index d091e4f..fccf535 100644 --- a/states/maildb/templates/maildb.py +++ b/states/maildb/templates/maildb.py @@ -13,10 +13,10 @@ def DBConfig(configfile): config.read(configfile) d_dbconfig = { - 'host' : config.get("maildb", "hostname"), - 'user' : config.get("maildb", "username"), - 'passwd' : config.get("maildb", "password"), - 'db' : config.get("maildb", "database") + "host" : config.get("maildb", "hostname"), + "user" : config.get("maildb", "username"), + "passwd" : config.get("maildb", "password"), + "db" : config.get("maildb", "database") } return d_dbconfig @@ -35,14 +35,16 @@ def CloseDB(conn): def CreateDB(conn, cursor): try: - cursor.execute('''CREATE TABLE IF NOT EXISTS mail ( - id serial NOT NULL, - sender text NULL, - recipient text NULL, - "date" timestamp NOT NULL DEFAULT NOW(), - "content" text NULL, - CONSTRAINT mail_pkey PRIMARY KEY (id) -)''') + cursor.execute(''' + CREATE TABLE IF NOT EXISTS mail ( + id serial NOT NULL, + sender text NULL, + recipient text NULL, + "date" timestamp NOT NULL DEFAULT NOW(), + "content" text NULL, + CONSTRAINT mail_pkey PRIMARY KEY (id) + ) + ''') conn.commit() except Exception as e: print(e) @@ -64,8 +66,8 @@ def ParseMail(input_data): content += line msgobj = email.message_from_string(content) - sender = parseaddr(msgobj['From'])[1] - recipient = parseaddr(msgobj['To'])[1] + sender = parseaddr(msgobj["From"])[1] + recipient = parseaddr(msgobj["To"])[1] return sender, recipient, content @@ -92,5 +94,5 @@ def main(): CloseDB(conn) -if __name__ == '__main__': +if __name__ == "__main__": main()