NobGit
public nobgit read

NobMail

Based on mailcow: dockerized

Languages

Repository composition by tracked source files.

PHP
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

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

2a5f6413
andryyy <[email protected]> 7 years ago
data/Dockerfiles/dovecot/Dockerfile           | 3 ++-
 data/Dockerfiles/dovecot/quarantine_notify.py | 3 ++-
 data/Dockerfiles/dovecot/quota_notify.py      | 4 +++-
 3 files changed, 7 insertions(+), 3 deletions(-)

Diff

diff --git a/data/Dockerfiles/dovecot/Dockerfile b/data/Dockerfiles/dovecot/Dockerfile
index 5e93b503..1320df1f 100644
--- a/data/Dockerfiles/dovecot/Dockerfile
+++ b/data/Dockerfiles/dovecot/Dockerfile
@@ -64,9 +64,10 @@ RUN apt-get update && apt-get -y --no-install-recommends install \
   libregexp-common-perl \
   liburi-perl \
   lzma-dev \
-  python-redis \
+  python-html2text \
   python-jinja2 \
   python-mysql.connector \
+  python-redis \
   make \
   mysql-client \
   procps \
diff --git a/data/Dockerfiles/dovecot/quarantine_notify.py b/data/Dockerfiles/dovecot/quarantine_notify.py
index 64d79dc4..2d466235 100755
--- a/data/Dockerfiles/dovecot/quarantine_notify.py
+++ b/data/Dockerfiles/dovecot/quarantine_notify.py
@@ -12,6 +12,7 @@ from jinja2 import Template
 import json
 import redis
 import time
+import html2text
 
 while True:
   try:
@@ -65,6 +66,7 @@ def notify_rcpt(rcpt, msg_count):
     with open('/templates/quarantine.tpl') as file_:
       template = Template(file_.read())
   html = template.render(meta=meta_query, counter=msg_count)
+  text = html2text.html2text(html)
   count = 0
   while count < 15:
     try:
@@ -74,7 +76,6 @@ def notify_rcpt(rcpt, msg_count):
       msg['From'] = r.get('Q_SENDER') or "quarantine@localhost"
       msg['Subject'] = r.get('Q_SUBJ') or "Spam Quarantine Notification"
       msg['Date'] = formatdate(localtime = True)
-      text = "You have %d new items" % (msg_count)
       text_part = MIMEText(text, 'plain', 'utf-8')
       html_part = MIMEText(html, 'html', 'utf-8')
       msg.attach(text_part)
diff --git a/data/Dockerfiles/dovecot/quota_notify.py b/data/Dockerfiles/dovecot/quota_notify.py
index 20d7abb7..f5df7639 100755
--- a/data/Dockerfiles/dovecot/quota_notify.py
+++ b/data/Dockerfiles/dovecot/quota_notify.py
@@ -10,6 +10,7 @@ from jinja2 import Template
 import redis
 import time
 import sys
+import html2text
 from subprocess import Popen, PIPE, STDOUT
 
 if len(sys.argv) > 2:
@@ -41,12 +42,13 @@ else:
     template = Template(file_.read())
 
 html = template.render(username=username, percent=percent)
+text = html2text.html2text(html)
+
 try:
   msg = MIMEMultipart('alternative')
   msg['From'] = r.get('QW_SENDER') or "quota-warning@localhost"
   msg['Subject'] = r.get('QW_SUBJ') or "Quota warning"
   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')
   html_part = MIMEText(html, 'html', 'utf-8')
   msg.attach(text_part)