[Dovecot] Derive text part in quota/quarantine notification mails from html

master
andryyy 2019-02-05 10:38:28 +01:00
parent 78d0deed94
commit 2a5f6413fa
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
3 changed files with 7 additions and 3 deletions

View File

@ -64,9 +64,10 @@ RUN apt-get update && apt-get -y --no-install-recommends install \
libregexp-common-perl \ libregexp-common-perl \
liburi-perl \ liburi-perl \
lzma-dev \ lzma-dev \
python-redis \ python-html2text \
python-jinja2 \ python-jinja2 \
python-mysql.connector \ python-mysql.connector \
python-redis \
make \ make \
mysql-client \ mysql-client \
procps \ procps \

View File

@ -12,6 +12,7 @@ from jinja2 import Template
import json import json
import redis import redis
import time import time
import html2text
while True: while True:
try: try:
@ -65,6 +66,7 @@ def notify_rcpt(rcpt, msg_count):
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)
text = html2text.html2text(html)
count = 0 count = 0
while count < 15: while count < 15:
try: try:
@ -74,7 +76,6 @@ def notify_rcpt(rcpt, msg_count):
msg['From'] = r.get('Q_SENDER') or "quarantine@localhost" msg['From'] = r.get('Q_SENDER') or "quarantine@localhost"
msg['Subject'] = r.get('Q_SUBJ') or "Spam Quarantine Notification" msg['Subject'] = r.get('Q_SUBJ') or "Spam Quarantine Notification"
msg['Date'] = formatdate(localtime = True) msg['Date'] = formatdate(localtime = True)
text = "You have %d new items" % (msg_count)
text_part = MIMEText(text, 'plain', 'utf-8') text_part = MIMEText(text, 'plain', 'utf-8')
html_part = MIMEText(html, 'html', 'utf-8') html_part = MIMEText(html, 'html', 'utf-8')
msg.attach(text_part) msg.attach(text_part)

View File

@ -10,6 +10,7 @@ from jinja2 import Template
import redis import redis
import time import time
import sys import sys
import html2text
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
if len(sys.argv) > 2: if len(sys.argv) > 2:
@ -41,12 +42,13 @@ else:
template = Template(file_.read()) template = Template(file_.read())
html = template.render(username=username, percent=percent) html = template.render(username=username, percent=percent)
text = html2text.html2text(html)
try: try:
msg = MIMEMultipart('alternative') msg = MIMEMultipart('alternative')
msg['From'] = r.get('QW_SENDER') or "quota-warning@localhost" msg['From'] = r.get('QW_SENDER') or "quota-warning@localhost"
msg['Subject'] = r.get('QW_SUBJ') or "Quota warning" msg['Subject'] = r.get('QW_SUBJ') or "Quota warning"
msg['Date'] = formatdate(localtime = True) msg['Date'] = formatdate(localtime = True)
text = "Your mailbox is almost full, currently %d%% are in use. Please consider deleting old messages." % (percent)
text_part = MIMEText(text, 'plain', 'utf-8') text_part = MIMEText(text, 'plain', 'utf-8')
html_part = MIMEText(html, 'html', 'utf-8') html_part = MIMEText(html, 'html', 'utf-8')
msg.attach(text_part) msg.attach(text_part)