瀏覽代碼

Added control for attrs_json object item's type (#3126)

item can be bytes or str in different situations. So let's keep defensive.
Zekeriya Akgül 5 年之前
父節點
當前提交
9ccbeb7f66
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      data/Dockerfiles/dovecot/quarantine_notify.py

+ 7 - 1
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