From 9ccbeb7f669b0ba6da2884f0030358168c907a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zekeriya=20Akg=C3=BCl?= Date: Sat, 9 Nov 2019 12:01:43 +0300 Subject: [PATCH] Added control for attrs_json object item's type (#3126) item can be bytes or str in different situations. So let's keep defensive. --- data/Dockerfiles/dovecot/quarantine_notify.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/dovecot/quarantine_notify.py b/data/Dockerfiles/dovecot/quarantine_notify.py index f0e7d113..277a0472 100755 --- a/data/Dockerfiles/dovecot/quarantine_notify.py +++ b/data/Dockerfiles/dovecot/quarantine_notify.py @@ -110,7 +110,13 @@ for record in records: print('Could not determine last notification for %s, assuming never' % (record['rcpt'])) last_notification = 0 attrs_json = query_mysql('SELECT attributes FROM mailbox WHERE username = "%s"' % (record['rcpt'])) - attrs = json.loads(str(attrs_json[0]['attributes'])) + attrs = attrs_json[0]['attributes'] + if isinstance(attrs, str): + # if attr is str then just load it + attrs = json.loads(attrs) + else: + # if it's bytes then decode and load it + attrs = json.loads(attrs.decode('utf-8')) if attrs['quarantine_notification'] not in ('hourly', 'daily', 'weekly', 'never'): print('Abnormal quarantine_notification value') continue