From 88bfb0d17fe8c47bada7333ebeed2ea5e0566a45 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Fri, 27 Sep 2019 18:57:15 +0000 Subject: [PATCH 1/4] Fix rspamd-learn when moving mail from/to junk folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, the ham/spam scripts got the rspamd-ip/port from the environment. However, when checking the environment of these processes now, it seems cleared. Maybe the new dovecot version now clears environment? — I couldn’t find a hint. In any case, using the common mechanism of injecting the ip/port from where it’s definately known by the already-used jinja2-mechanism seems reasonably safe. --- core/dovecot/conf/bin/ham | 4 ---- core/dovecot/conf/bin/spam | 4 ---- core/dovecot/conf/ham.script | 4 ++++ core/dovecot/conf/spam.script | 4 ++++ core/dovecot/start.py | 10 ++++++++++ towncrier/newsfragments/1177.bug | 1 + 6 files changed, 19 insertions(+), 8 deletions(-) delete mode 100755 core/dovecot/conf/bin/ham delete mode 100755 core/dovecot/conf/bin/spam create mode 100755 core/dovecot/conf/ham.script create mode 100755 core/dovecot/conf/spam.script create mode 100644 towncrier/newsfragments/1177.bug diff --git a/core/dovecot/conf/bin/ham b/core/dovecot/conf/bin/ham deleted file mode 100755 index becc304d..00000000 --- a/core/dovecot/conf/bin/ham +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -tee >(rspamc -h ${ANTISPAM_ADDRESS} -P mailu learn_ham /dev/stdin) \ - | rspamc -h ${ANTISPAM_ADDRESS} -P mailu -f 13 fuzzy_add /dev/stdin diff --git a/core/dovecot/conf/bin/spam b/core/dovecot/conf/bin/spam deleted file mode 100755 index 035706b6..00000000 --- a/core/dovecot/conf/bin/spam +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -tee >(rspamc -h ${ANTISPAM_ADDRESS} -P mailu learn_spam /dev/stdin) \ - >(rspamc -h ${ANTISPAM_ADDRESS} -P mailu -f 11 fuzzy_add /dev/stdin) diff --git a/core/dovecot/conf/ham.script b/core/dovecot/conf/ham.script new file mode 100755 index 00000000..f1dfc409 --- /dev/null +++ b/core/dovecot/conf/ham.script @@ -0,0 +1,4 @@ +#!/bin/bash + +tee >(rspamc -h {{ ANTISPAM_ADDRESS }} -P mailu learn_ham /dev/stdin) \ + | rspamc -h {{ ANTISPAM_ADDRESS }} -P mailu -f 13 fuzzy_add /dev/stdin diff --git a/core/dovecot/conf/spam.script b/core/dovecot/conf/spam.script new file mode 100755 index 00000000..c711be0a --- /dev/null +++ b/core/dovecot/conf/spam.script @@ -0,0 +1,4 @@ +#!/bin/bash + +tee >(rspamc -h {{ ANTISPAM_ADDRESS }} -P mailu learn_spam /dev/stdin) \ + >(rspamc -h {{ ANTISPAM_ADDRESS }} -P mailu -f 11 fuzzy_add /dev/stdin) diff --git a/core/dovecot/start.py b/core/dovecot/start.py index f522cf1e..f782eaf4 100755 --- a/core/dovecot/start.py +++ b/core/dovecot/start.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import os +import stat import glob import multiprocessing import logging as log @@ -32,6 +33,15 @@ if os.environ["WEBMAIL"] != "none": for dovecot_file in glob.glob("/conf/*.conf"): conf.jinja(dovecot_file, os.environ, os.path.join("/etc/dovecot", os.path.basename(dovecot_file))) +try: + os.mkdir("/conf/bin") +except FileExistsError: + pass +for script_file in glob.glob("/conf/*.script"): + out_file = os.path.join("/conf/bin/", os.path.basename(script_file).replace('.script','')) + conf.jinja(script_file, os.environ, out_file) + os.chmod(out_file, stat.S_IRUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) + # Run Podop, then postfix multiprocessing.Process(target=start_podop).start() os.system("chown mail:mail /mail") diff --git a/towncrier/newsfragments/1177.bug b/towncrier/newsfragments/1177.bug new file mode 100644 index 00000000..752543d2 --- /dev/null +++ b/towncrier/newsfragments/1177.bug @@ -0,0 +1 @@ +Fix piping mail into rspamd when moving from/to junk-folder From 18bc2fe78b9033e2d934263e69d551da62bf30c8 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Thu, 3 Oct 2019 08:31:00 +0000 Subject: [PATCH 2/4] Use more readable forms of makedirs and chmod --- core/dovecot/start.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/dovecot/start.py b/core/dovecot/start.py index f782eaf4..3a85f64b 100755 --- a/core/dovecot/start.py +++ b/core/dovecot/start.py @@ -33,14 +33,11 @@ if os.environ["WEBMAIL"] != "none": for dovecot_file in glob.glob("/conf/*.conf"): conf.jinja(dovecot_file, os.environ, os.path.join("/etc/dovecot", os.path.basename(dovecot_file))) -try: - os.mkdir("/conf/bin") -except FileExistsError: - pass +os.makedirs("/conf/bin", exist_ok=True) for script_file in glob.glob("/conf/*.script"): out_file = os.path.join("/conf/bin/", os.path.basename(script_file).replace('.script','')) conf.jinja(script_file, os.environ, out_file) - os.chmod(out_file, stat.S_IRUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) + os.chmod(out_file, 0555) # Run Podop, then postfix multiprocessing.Process(target=start_podop).start() From dc8a798ca13efe0e8fa2b394ab350506c90e4235 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Thu, 3 Oct 2019 08:32:36 +0000 Subject: [PATCH 3/4] Use correct octal notation for python3 --- core/dovecot/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dovecot/start.py b/core/dovecot/start.py index 3a85f64b..d61c40eb 100755 --- a/core/dovecot/start.py +++ b/core/dovecot/start.py @@ -37,7 +37,7 @@ os.makedirs("/conf/bin", exist_ok=True) for script_file in glob.glob("/conf/*.script"): out_file = os.path.join("/conf/bin/", os.path.basename(script_file).replace('.script','')) conf.jinja(script_file, os.environ, out_file) - os.chmod(out_file, 0555) + os.chmod(out_file, 0o555) # Run Podop, then postfix multiprocessing.Process(target=start_podop).start() From de29012d0bf48cf970ad37c62d7db960161f14c0 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Thu, 10 Oct 2019 09:51:52 +0200 Subject: [PATCH 4/4] Remove unused stat import --- core/dovecot/start.py | 1 - 1 file changed, 1 deletion(-) diff --git a/core/dovecot/start.py b/core/dovecot/start.py index d61c40eb..b8ad1699 100755 --- a/core/dovecot/start.py +++ b/core/dovecot/start.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import os -import stat import glob import multiprocessing import logging as log