diff --git a/data/Dockerfiles/dovecot/quarantine_notify.py b/data/Dockerfiles/dovecot/quarantine_notify.py index 3b1d105c..07f14682 100755 --- a/data/Dockerfiles/dovecot/quarantine_notify.py +++ b/data/Dockerfiles/dovecot/quarantine_notify.py @@ -27,6 +27,10 @@ while True: time_now = int(time.time()) +max_score = float(r.get('Q_MAX_SCORE') or "9999.0") +if max_score == "": + max_score = 9999.0 + def query_mysql(query, headers = True, update = False): while True: try: @@ -55,7 +59,7 @@ def query_mysql(query, headers = True, update = False): cnx.close() def notify_rcpt(rcpt, msg_count, quarantine_acl): - meta_query = query_mysql('SELECT SHA2(CONCAT(id, qid), 256) AS qhash, id, subject, score, sender, created FROM quarantine WHERE notified = 0 AND rcpt = "%s"' % (rcpt)) + meta_query = query_mysql('SELECT SHA2(CONCAT(id, qid), 256) AS qhash, id, subject, score, sender, created FROM quarantine WHERE notified = 0 AND rcpt = "%s" AND score < %f' % (rcpt, max_score)) if r.get('Q_HTML'): try: template = Template(r.get('Q_HTML')) @@ -100,7 +104,7 @@ def notify_rcpt(rcpt, msg_count, quarantine_acl): server.sendmail(msg['From'], [str(redirect)] + [str(bcc)], text) server.quit() for res in meta_query: - query_mysql('UPDATE quarantine SET notified = 1 WHERE id = "%d"' % (res['id']), update = True) + query_mysql('UPDATE quarantine SET notified = 1 WHERE id = "%d"' % (res['id']), update = True) r.hset('Q_LAST_NOTIFIED', record['rcpt'], time_now) break except Exception as ex: @@ -108,7 +112,7 @@ def notify_rcpt(rcpt, msg_count, quarantine_acl): print('%s' % (ex)) 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 score < %f AND rcpt in (SELECT username FROM mailbox) GROUP BY rcpt' % (max_score)) for record in records: attrs = '' @@ -134,13 +138,13 @@ for record in records: continue if attrs['quarantine_notification'] == 'hourly': if last_notification == 0 or (last_notification + 3600) < time_now: - print("Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])) + print("Notifying %s: Considering %d new items in quarantine" % (record['rcpt'], record['counter'])) notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl']) elif attrs['quarantine_notification'] == 'daily': if last_notification == 0 or (last_notification + 86400) < time_now: - print("Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])) + print("Notifying %s: Considering %d new items in quarantine" % (record['rcpt'], record['counter'])) notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl']) elif attrs['quarantine_notification'] == 'weekly': if last_notification == 0 or (last_notification + 604800) < time_now: - print("Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])) + print("Notifying %s: Considering %d new items in quarantine" % (record['rcpt'], record['counter'])) notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl']) diff --git a/data/web/admin.php b/data/web/admin.php index 2bbf103d..928d1690 100644 --- a/data/web/admin.php +++ b/data/web/admin.php @@ -821,6 +821,12 @@ if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CAC +
+ +
+ +
+
diff --git a/data/web/inc/functions.quarantine.inc.php b/data/web/inc/functions.quarantine.inc.php index 77498e9c..3518fc6f 100644 --- a/data/web/inc/functions.quarantine.inc.php +++ b/data/web/inc/functions.quarantine.inc.php @@ -299,6 +299,12 @@ function quarantine($_action, $_data = null) { $release_format = 'raw'; } $max_size = $_data['max_size']; + if ($_data['max_score'] == "") { + $max_score = ''; + } + else { + $max_score = floatval($_data['max_score']); + } $max_age = intval($_data['max_age']); $subject = $_data['subject']; if (!filter_var($_data['bcc'], FILTER_VALIDATE_EMAIL)) { @@ -327,6 +333,7 @@ function quarantine($_action, $_data = null) { try { $redis->Set('Q_RETENTION_SIZE', intval($retention_size)); $redis->Set('Q_MAX_SIZE', intval($max_size)); + $redis->Set('Q_MAX_SCORE', $max_score); $redis->Set('Q_MAX_AGE', $max_age); $redis->Set('Q_EXCLUDE_DOMAINS', json_encode($exclude_domains)); $redis->Set('Q_RELEASE_FORMAT', $release_format); @@ -794,6 +801,7 @@ function quarantine($_action, $_data = null) { $settings['exclude_domains'] = json_decode($redis->Get('Q_EXCLUDE_DOMAINS'), true); } $settings['max_size'] = $redis->Get('Q_MAX_SIZE'); + $settings['max_score'] = $redis->Get('Q_MAX_SCORE'); $settings['max_age'] = $redis->Get('Q_MAX_AGE'); $settings['retention_size'] = $redis->Get('Q_RETENTION_SIZE'); $settings['release_format'] = $redis->Get('Q_RELEASE_FORMAT'); diff --git a/data/web/lang/lang.de.json b/data/web/lang/lang.de.json index 5c009a62..64ca78fb 100644 --- a/data/web/lang/lang.de.json +++ b/data/web/lang/lang.de.json @@ -226,6 +226,7 @@ "quarantine_exclude_domains": "Domains und Alias-Domains ausschließen", "quarantine_max_age": "Maximales Alter in Tagen
Wert muss größer oder gleich 1 Tag sein.", "quarantine_max_size": "Maximale Größe in MiB (größere Elemente werden verworfen):
0 bedeutet nicht unlimitiert.", + "quarantine_max_score": "Nicht benachrichtigen, wenn der Spam-Score höher ist als der folgende Wert:
Standardwert 9999.0", "quarantine_notification_html": "Benachrichtigungs-E-Mail Inhalt:
Leer lassen, um Standard-Template wiederherzustellen.", "quarantine_notification_sender": "Benachrichtigungs-E-Mail Absender", "quarantine_notification_subject": "Benachrichtigungs-E-Mail Betreff", diff --git a/data/web/lang/lang.en.json b/data/web/lang/lang.en.json index 13f3046e..af7bb2af 100644 --- a/data/web/lang/lang.en.json +++ b/data/web/lang/lang.en.json @@ -226,6 +226,7 @@ "quarantine_exclude_domains": "Exclude domains and alias-domains", "quarantine_max_age": "Maximum age in days
Value must be equal to or greater than 1 day.", "quarantine_max_size": "Maximum size in MiB (larger elements are discarded):
0 does not indicate unlimited.", + "quarantine_max_score": "Discard notification if spam score of a mail is higher than this value:
Defaults to 9999.0", "quarantine_notification_html": "Notification email template:
Leave empty to restore default template.", "quarantine_notification_sender": "Notification email sender", "quarantine_notification_subject": "Notification email subject",