From 1e5858179e82406c9533e50a6e3a7dae5d5d7e8b Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 15 May 2017 19:57:07 +0200 Subject: [PATCH] util: add check if purging is enabled Change-Id: I90cc2062513abec1ec947fc0adb4c3da9d125784 Signed-off-by: SJ --- util/pilerpurge.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/util/pilerpurge.py b/util/pilerpurge.py index 6028d835..fa8809b0 100755 --- a/util/pilerpurge.py +++ b/util/pilerpurge.py @@ -35,6 +35,18 @@ def read_options(filename="", opts={}): opts['server_id'] = "%02x" % config.getint('piler', 'server_id') +def is_purge_enabled(opts={}): + cursor = opts['db'].cursor() + + cursor.execute("SELECT `value` FROM `option` WHERE `key`='enable_purge'") + + row = cursor.fetchone() + if row and row[0] == '1': + return True + + return False + + def purge_m_files(ids=[], opts={}): if len(ids) > 0: remove_m_files(ids, opts) @@ -187,6 +199,10 @@ def main(): opts['db'] = dbapi.connect("localhost", opts['username'], opts['password'], opts['database']) + if is_purge_enabled(opts) is False: + syslog.syslog("Purging emails is disabled") + sys.exit(1) + cursor = opts['db'].cursor() cursor.execute(SQL_PURGE_SELECT_QUERY)