From 4d250838477b612bec7054d6a0433624ea3305fe Mon Sep 17 00:00:00 2001 From: kaiyou Date: Thu, 27 Sep 2018 08:11:26 +0200 Subject: [PATCH] Move sieve script generation to the admin container --- core/admin/mailu/internal/__init__.py | 2 +- .../mailu/internal/templates/default.sieve} | 14 +++++++------- core/admin/mailu/internal/views.py | 2 +- core/dovecot/conf/dovecot.conf | 3 --- core/dovecot/sieve/after.sieve | 0 core/dovecot/sieve/bin/mailtrain | 3 --- core/dovecot/sieve/default.sieve | 0 7 files changed, 9 insertions(+), 15 deletions(-) rename core/{dovecot/sieve/before.sieve => admin/mailu/internal/templates/default.sieve} (55%) delete mode 100644 core/dovecot/sieve/after.sieve delete mode 100755 core/dovecot/sieve/bin/mailtrain delete mode 100644 core/dovecot/sieve/default.sieve diff --git a/core/admin/mailu/internal/__init__.py b/core/admin/mailu/internal/__init__.py index 6419ad10..f929607f 100644 --- a/core/admin/mailu/internal/__init__.py +++ b/core/admin/mailu/internal/__init__.py @@ -6,7 +6,7 @@ import socket import flask -internal = flask.Blueprint('internal', __name__) +internal = flask.Blueprint('internal', __name__, template_folder='templates') @internal.app_errorhandler(RateLimitExceeded) def rate_limit_handler(e): diff --git a/core/dovecot/sieve/before.sieve b/core/admin/mailu/internal/templates/default.sieve similarity index 55% rename from core/dovecot/sieve/before.sieve rename to core/admin/mailu/internal/templates/default.sieve index 6ebc20c5..5a80a181 100644 --- a/core/dovecot/sieve/before.sieve +++ b/core/admin/mailu/internal/templates/default.sieve @@ -8,8 +8,6 @@ require "regex"; require "relational"; require "date"; require "comparator-i;ascii-numeric"; -require "vnd.dovecot.extdata"; -require "vnd.dovecot.execute"; require "spamtestplus"; require "editheader"; require "index"; @@ -20,21 +18,23 @@ if header :index 2 :matches "Received" "from * by * for <*>; *" addheader "Delivered-To" "<${3}>"; } -if allof (string :is "${extdata.spam_enabled}" "1", - spamtest :percent :value "gt" :comparator "i;ascii-numeric" "${extdata.spam_threshold}") +{% if user.spam_enabled %} +if spamtest :percent :value "gt" :comparator "i;ascii-numeric" "{{ user.spam_threshold }}" { setflag "\\seen"; fileinto :create "Junk"; stop; } +{% endif %} if exists "X-Virus" { discard; stop; } -if allof (string :is "${extdata.reply_enabled}" "1", - currentdate :value "le" "date" "${extdata.reply_enddate}") +{% if user.reply_enabled %} +if currentdate :value "le" "date" "{{ user.reply_enddate }}" { - vacation :days 1 :subject "${extdata.reply_subject}" "${extdata.reply_body}"; + vacation :days 1 :subject "{{ user.reply_subject }}" "{{ user.reply_body }}"; } +{% endif %} diff --git a/core/admin/mailu/internal/views.py b/core/admin/mailu/internal/views.py index 83cd4718..3b6163e0 100644 --- a/core/admin/mailu/internal/views.py +++ b/core/admin/mailu/internal/views.py @@ -122,7 +122,7 @@ def dovecot_quota(ns, user_email): def dovecot_sieve(script, user_email): user = models.User.query.get(user_email) or flask.abort(404) if script == "default": - pass + return flask.jsonify(flask.render_template("default.sieve")) else: flask.abort(404) diff --git a/core/dovecot/conf/dovecot.conf b/core/dovecot/conf/dovecot.conf index bd4e2893..4d3302ba 100644 --- a/core/dovecot/conf/dovecot.conf +++ b/core/dovecot/conf/dovecot.conf @@ -139,9 +139,6 @@ plugin { sieve = dict:proxy:/tmp/podop.socket:sieve sieve_plugins = sieve_imapsieve sieve_extprograms sieve_global_extensions = +spamtest +spamtestplus +vnd.dovecot.execute +editheader - sieve_before = /var/lib/dovecot/before.sieve - sieve_default = /var/lib/dovecot/default.sieve - sieve_after = /var/lib/dovecot/after.sieve # Sieve execute sieve_execute_bin_dir = /var/lib/dovecot/bin diff --git a/core/dovecot/sieve/after.sieve b/core/dovecot/sieve/after.sieve deleted file mode 100644 index e69de29b..00000000 diff --git a/core/dovecot/sieve/bin/mailtrain b/core/dovecot/sieve/bin/mailtrain deleted file mode 100755 index cfa36398..00000000 --- a/core/dovecot/sieve/bin/mailtrain +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -rspamc -h antispam:11334 -P mailu "learn_$1" /dev/stdin <&0 diff --git a/core/dovecot/sieve/default.sieve b/core/dovecot/sieve/default.sieve deleted file mode 100644 index e69de29b..00000000