|
@@ -1,11 +1,11 @@
|
|
-#!/usr/bin/python3
|
|
|
|
|
|
+#!/usr/bin/python
|
|
|
|
|
|
import smtplib
|
|
import smtplib
|
|
import os
|
|
import os
|
|
import mysql.connector
|
|
import mysql.connector
|
|
-from email.mime.multipart import MIMEMultipart
|
|
|
|
-from email.mime.text import MIMEText
|
|
|
|
-from email.utils import COMMASPACE, formatdate
|
|
|
|
|
|
+from email.MIMEMultipart import MIMEMultipart
|
|
|
|
+from email.MIMEText import MIMEText
|
|
|
|
+from email.Utils import COMMASPACE, formatdate
|
|
import cgi
|
|
import cgi
|
|
import jinja2
|
|
import jinja2
|
|
from jinja2 import Template
|
|
from jinja2 import Template
|
|
@@ -20,7 +20,7 @@ while True:
|
|
r = redis.StrictRedis(host='redis', decode_responses=True, port=6379, db=0)
|
|
r = redis.StrictRedis(host='redis', decode_responses=True, port=6379, db=0)
|
|
r.ping()
|
|
r.ping()
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
- print("{0} - trying again...".format(ex))
|
|
|
|
|
|
+ print '%s - trying again...' % (ex)
|
|
time.sleep(3)
|
|
time.sleep(3)
|
|
else:
|
|
else:
|
|
break
|
|
break
|
|
@@ -32,7 +32,7 @@ def query_mysql(query, headers = True, update = False):
|
|
try:
|
|
try:
|
|
cnx = mysql.connector.connect(unix_socket = '/var/run/mysqld/mysqld.sock', user='__DBUSER__', passwd='__DBPASS__', database='__DBNAME__', charset="utf8")
|
|
cnx = mysql.connector.connect(unix_socket = '/var/run/mysqld/mysqld.sock', user='__DBUSER__', passwd='__DBPASS__', database='__DBNAME__', charset="utf8")
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
- print("{0} - trying again...".format(ex))
|
|
|
|
|
|
+ print '%s - trying again...' % (ex)
|
|
time.sleep(3)
|
|
time.sleep(3)
|
|
else:
|
|
else:
|
|
break
|
|
break
|
|
@@ -60,7 +60,7 @@ def notify_rcpt(rcpt, msg_count, quarantine_acl):
|
|
try:
|
|
try:
|
|
template = Template(r.get('Q_HTML'))
|
|
template = Template(r.get('Q_HTML'))
|
|
except:
|
|
except:
|
|
- print("Error: Cannot parse quarantine template, falling back to default template.")
|
|
|
|
|
|
+ print "Error: Cannot parse quarantine template, falling back to default template."
|
|
with open('/templates/quarantine.tpl') as file_:
|
|
with open('/templates/quarantine.tpl') as file_:
|
|
template = Template(file_.read())
|
|
template = Template(file_.read())
|
|
else:
|
|
else:
|
|
@@ -91,7 +91,7 @@ def notify_rcpt(rcpt, msg_count, quarantine_acl):
|
|
break
|
|
break
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
server.quit()
|
|
server.quit()
|
|
- print('{0}'.format(ex))
|
|
|
|
|
|
+ print '%s' % (ex)
|
|
time.sleep(3)
|
|
time.sleep(3)
|
|
|
|
|
|
records = query_mysql('SELECT IFNULL(user_acl.quarantine, 0) AS quarantine_acl, count(id) AS counter, rcpt FROM quarantine LEFT OUTER JOIN user_acl ON user_acl.username = rcpt WHERE notified = 0 AND rcpt in (SELECT username FROM mailbox) GROUP BY rcpt')
|
|
records = query_mysql('SELECT IFNULL(user_acl.quarantine, 0) AS quarantine_acl, count(id) AS counter, rcpt FROM quarantine LEFT OUTER JOIN user_acl ON user_acl.username = rcpt WHERE notified = 0 AND rcpt in (SELECT username FROM mailbox) GROUP BY rcpt')
|
|
@@ -102,25 +102,25 @@ for record in records:
|
|
try:
|
|
try:
|
|
last_notification = int(r.hget('Q_LAST_NOTIFIED', record['rcpt']))
|
|
last_notification = int(r.hget('Q_LAST_NOTIFIED', record['rcpt']))
|
|
if last_notification > time_now:
|
|
if last_notification > time_now:
|
|
- print('Last notification is > time now, assuming never')
|
|
|
|
|
|
+ print 'Last notification is > time now, assuming never'
|
|
last_notification = 0
|
|
last_notification = 0
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
- print('Could not determine last notification for {0}, assuming never'.format(record['rcpt']))
|
|
|
|
|
|
+ print 'Could not determine last notification for %s, assuming never' % (record['rcpt'])
|
|
last_notification = 0
|
|
last_notification = 0
|
|
attrs_json = query_mysql('SELECT attributes FROM mailbox WHERE username = "%s"' % (record['rcpt']))
|
|
attrs_json = query_mysql('SELECT attributes FROM mailbox WHERE username = "%s"' % (record['rcpt']))
|
|
attrs = json.loads(str(attrs_json[0]['attributes']))
|
|
attrs = json.loads(str(attrs_json[0]['attributes']))
|
|
if attrs['quarantine_notification'] not in ('hourly', 'daily', 'weekly', 'never'):
|
|
if attrs['quarantine_notification'] not in ('hourly', 'daily', 'weekly', 'never'):
|
|
- print('Abnormal quarantine_notification value')
|
|
|
|
|
|
+ print 'Abnormal quarantine_notification value'
|
|
continue
|
|
continue
|
|
if attrs['quarantine_notification'] == 'hourly':
|
|
if attrs['quarantine_notification'] == 'hourly':
|
|
if last_notification == 0 or (last_notification + 3600) < time_now:
|
|
if last_notification == 0 or (last_notification + 3600) < time_now:
|
|
- print("Notifying {0} about {1} new items in quarantine".format(record['rcpt'], record['counter']))
|
|
|
|
|
|
+ print "Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|
|
elif attrs['quarantine_notification'] == 'daily':
|
|
elif attrs['quarantine_notification'] == 'daily':
|
|
if last_notification == 0 or (last_notification + 86400) < time_now:
|
|
if last_notification == 0 or (last_notification + 86400) < time_now:
|
|
- print("Notifying {0} about {1} new items in quarantine".format(record['rcpt'], record['counter']))
|
|
|
|
|
|
+ print "Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|
|
elif attrs['quarantine_notification'] == 'weekly':
|
|
elif attrs['quarantine_notification'] == 'weekly':
|
|
if last_notification == 0 or (last_notification + 604800) < time_now:
|
|
if last_notification == 0 or (last_notification + 604800) < time_now:
|
|
- print("Notifying {0} about {1} new items in quarantine".format(record['rcpt'], record['counter']))
|
|
|
|
|
|
+ print "Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|