public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
[Web, Quarantine] Allow to set the max score of a message up to which a quarantine notification will be sent
6c697f3f
data/Dockerfiles/dovecot/quarantine_notify.py | 16 ++++++++++------
data/web/admin.php | 6 ++++++
data/web/inc/functions.quarantine.inc.php | 8 ++++++++
data/web/lang/lang.de.json | 1 +
data/web/lang/lang.en.json | 1 +
5 files changed, 26 insertions(+), 6 deletions(-)
Diff
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
<input type="number" class="form-control" name="max_size" value="<?=$q_data['max_size'];?>" placeholder="0" required>
</div>
</div>
+ <div class="form-group">
+ <label class="col-sm-4 control-label" for="max_score"><?=$lang['admin']['quarantine_max_score'];?></label>
+ <div class="col-sm-8">
+ <input type="number" class="form-control" name="max_score" value="<?=$q_data['max_score'];?>" placeholder="9999.0">
+ </div>
+ </div>
<div class="form-group">
<label class="col-sm-4 control-label" for="max_age"><?=$lang['admin']['quarantine_max_age'];?></label>
<div class="col-sm-8">
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<br><small>Wert muss größer oder gleich 1 Tag sein.</small>",
"quarantine_max_size": "Maximale Größe in MiB (größere Elemente werden verworfen):<br><small>0 bedeutet <b>nicht</b> unlimitiert.</small>",
+ "quarantine_max_score": "Nicht benachrichtigen, wenn der Spam-Score höher ist als der folgende Wert:<br><small>Standardwert 9999.0</small>",
"quarantine_notification_html": "Benachrichtigungs-E-Mail Inhalt:<br><small>Leer lassen, um Standard-Template wiederherzustellen.</small>",
"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<br><small>Value must be equal to or greater than 1 day.</small>",
"quarantine_max_size": "Maximum size in MiB (larger elements are discarded):<br><small>0 does <b>not</b> indicate unlimited.</small>",
+ "quarantine_max_score": "Discard notification if spam score of a mail is higher than this value:<br><small>Defaults to 9999.0</small>",
"quarantine_notification_html": "Notification email template:<br><small>Leave empty to restore default template.</small>",
"quarantine_notification_sender": "Notification email sender",
"quarantine_notification_subject": "Notification email subject",