[Dovecot] Extend quarantine template: add score and release/delete buttons - depending on acl
parent
243389a9d5
commit
c438411a3d
|
@ -13,6 +13,7 @@ import json
|
||||||
import redis
|
import redis
|
||||||
import time
|
import time
|
||||||
import html2text
|
import html2text
|
||||||
|
import socket
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -29,7 +30,7 @@ time_now = int(time.time())
|
||||||
def query_mysql(query, headers = True, update = False):
|
def query_mysql(query, headers = True, update = False):
|
||||||
while True:
|
while True:
|
||||||
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='mailcow', passwd='9S6jd31ijEytZE9lQ8sWOxK34tg5', database='mailcow', charset="utf8")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print '%s - trying again...' % (ex)
|
print '%s - trying again...' % (ex)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
@ -53,8 +54,8 @@ def query_mysql(query, headers = True, update = False):
|
||||||
cur.close()
|
cur.close()
|
||||||
cnx.close()
|
cnx.close()
|
||||||
|
|
||||||
def notify_rcpt(rcpt, msg_count):
|
def notify_rcpt(rcpt, msg_count, quarantine_acl):
|
||||||
meta_query = query_mysql('SELECT id, subject, 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"' % (rcpt))
|
||||||
if r.get('Q_HTML'):
|
if r.get('Q_HTML'):
|
||||||
try:
|
try:
|
||||||
template = Template(r.get('Q_HTML'))
|
template = Template(r.get('Q_HTML'))
|
||||||
|
@ -65,7 +66,7 @@ def notify_rcpt(rcpt, msg_count):
|
||||||
else:
|
else:
|
||||||
with open('/templates/quarantine.tpl') as file_:
|
with open('/templates/quarantine.tpl') as file_:
|
||||||
template = Template(file_.read())
|
template = Template(file_.read())
|
||||||
html = template.render(meta=meta_query, counter=msg_count)
|
html = template.render(meta=meta_query, counter=msg_count, hostname=socket.gethostname(), quarantine_acl=quarantine_acl)
|
||||||
text = html2text.html2text(html)
|
text = html2text.html2text(html)
|
||||||
count = 0
|
count = 0
|
||||||
while count < 15:
|
while count < 15:
|
||||||
|
@ -92,7 +93,7 @@ def notify_rcpt(rcpt, msg_count):
|
||||||
print '%s' % (ex)
|
print '%s' % (ex)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
records = query_mysql('SELECT count(id) AS counter, rcpt FROM quarantine WHERE notified = 0 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')
|
||||||
|
|
||||||
for record in records:
|
for record in records:
|
||||||
attrs = ''
|
attrs = ''
|
||||||
|
@ -113,14 +114,14 @@ for record in records:
|
||||||
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 %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
print "Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
||||||
notify_rcpt(record['rcpt'], record['counter'])
|
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 %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
print "Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
||||||
notify_rcpt(record['rcpt'], record['counter'])
|
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 %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
print "Notifying %s about %d new items in quarantine" % (record['rcpt'], record['counter'])
|
||||||
notify_rcpt(record['rcpt'], record['counter'])
|
notify_rcpt(record['rcpt'], record['counter'], record['quarantine_acl'])
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<head>
|
<head>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: sans-serif;
|
font-family: Helvetica, Arial, Sans-Serif;
|
||||||
}
|
}
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
|
@ -15,18 +15,28 @@
|
||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
th {
|
||||||
|
background-color: #56B04C;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
tr:nth-child(even){background-color: #f2f2f2}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>Hi!<br>
|
<p>Hi!<br>
|
||||||
There are {{counter}} new messages waiting in quarantine:<br>
|
There are {{counter}} new messages waiting in quarantine:<br>
|
||||||
<table>
|
<table>
|
||||||
<tr><th>Subject</th><th>Sender</th><th>Arrived on</th></tr>
|
<tr><th>Subject</th><th>Sender</th><th>Score</th><th>Arrived on</th>{% if quarantine_acl == 1 %}<th>Actions</th>{% endif %}</tr>
|
||||||
{% for line in meta %}
|
{% for line in meta %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ line.subject|e }}</td>
|
<td>{{ line.subject|e }}</td>
|
||||||
<td>{{ line.sender|e }}</td>
|
<td>{{ line.sender|e }}</td>
|
||||||
|
<td>{{ line.score }}</td>
|
||||||
<td>{{ line.created }}</td>
|
<td>{{ line.created }}</td>
|
||||||
|
{% if quarantine_acl == 1 %}
|
||||||
|
<td><a href="https://{{ hostname }}/qhandler/release/{{ line.qhash }}">release</a> | <a href="https://{{ hostname }}/qhandler/delete/{{ line.qhash }}">delete</a></td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue