Calling Bash script from Sieve script
4
votes
4
answers
3761
views
I'm not sure if something similar has already been asked.
I'm currently trying to push emails to our spam filter when they are moved to or out of the Junk folder so it can learn them as spam/ham. To do that I followed this guide: https://workaround.org/ispmail/stretch/filtering-out-spam-with-rspamd in the section "Learning from user actions".
The sieve scripts are created following the instructions, they have been processed by sievec and permissions have been granted following the guide. The two shell scripts have also been created accordingly. The only real difference is that we don't have the user or group "vmail". I set it to dovecot:root which should be the counterpart of our system. So the folder looks like this:
drwxr-xr-x 2 dovecot root 4,0K Mai 7 10:52 .
drwxr-xr-x 3 root root 4,0K Jul 29 2019 ..
-rw-r--r-- 1 dovecot root 85 Mai 7 10:47 learn-ham.sieve
-rw-r--r-- 1 root root 246 Mai 7 10:47 learn-ham.svbin
-rw-r--r-- 1 dovecot root 86 Mai 7 10:47 learn-spam.sieve
-rw-r--r-- 1 root root 250 Mai 7 10:47 learn-spam.svbin
-rw-r--r-- 1 dovecot root 509 Mär 16 13:57 mailfilter.sieve
-rw-r--r-- 1 root root 398 Mai 6 18:02 mailfilter.svbin
-rwx------ 1 dovecot root 41 Mai 7 10:52 rspamd-learn-ham.sh
-rwx------ 1 dovecot root 42 Dez 14 10:42 rspamd-learn-spam.sh
When the sieve script executes and is supposed to call the shell scripts, I get the following errors:
Mai 12 17:16:28 mail dovecot: imap(user): Fatal: execvp(/etc/dovecot/sieve/global/rspamd-learn-spam.sh) failed: Permission denied
Mai 12 17:16:28 mail dovecot: imap(user): Error: write(program stdin) failed: Broken pipe
Mai 12 17:16:28 mail dovecot: imap(user): program `/etc/dovecot/sieve/global/rspamd-learn-spam.sh' terminated with non-zero exit code 84
Mai 12 17:16:28 mail dovecot: imap(user): Error: sieve: pipe action: failed to pipe message to program `rspamd-learn-spam.sh': refer to server log for more information. [2020-05-12 17:16:28]
Mai 12 17:16:28 mail dovecot: imap(user): sieve: left message in mailbox 'Junk'
Mai 12 17:16:28 mail dovecot: imap(user): Error: sieve: Execution of script /etc/dovecot/sieve/global/learn-spam.sieve failed
Besides the fact that I have no clue what the "server log" refers to, I just can't figure out what exactly the problem is. Sure it seems like a permission error, but how could it be fixed?
About our system: Debian 10.4 with dovecot 2.3.4.1 and pigeonhole 0.5.4
**EDIT:**
I found one mistake: I had set the sieve_pipe_bin_dir to the wrong folder. It now points to the folder containing the two .sh files, but still I get those errors:
Mai 22 15:40:06 mail dovecot: imap(user): Fatal: execvp(/etc/dovecot/sieve/global/rspamd-learn-spam.sh) failed: Permission denied
Mai 22 15:40:06 mail dovecot: imap(user): Error: write(program stdin) failed: Broken pipe
Mai 22 15:40:06 mail dovecot: imap(user): program `/etc/dovecot/sieve/global/rspamd-learn-spam.sh' terminated with non-zero exit code 84
Mai 22 15:40:06 mail dovecot: imap(user): Error: sieve: pipe action: failed to pipe message to program `rspamd-learn-spam.sh': refer to server log for more information. [2020-05-22 15:40:06]
Mai 22 15:40:06 mail dovecot: imap(user): sieve: left message in mailbox 'Junk'
Mai 22 15:40:06 mail dovecot: imap(user): Error: sieve: Execution of script /etc/dovecot/sieve/global/learn-spam.sieve failed
No matter which owner I set (root:root or dovecot:root, the only other users that are not "human-users" would be something like _apt, bin, nslcd, daemon, dovenull or www-data) Any idea what could cause that?
**EDIT2:**
I now changed my approach by trying to pipe directly to rspamc. Here my learn-spam.sieve script:
require ["vnd.dovecot.pipe", "copy", "imapsieve"];
pipe :copy "rspamc" ["learn_spam"];
Accordingly I changed the 90-plugin.conf to contain
sieve_pipe_bin_dir = /usr/bin/rspamc
where rspamc resides. Now I'm getting the error
Jun 03 09:48:34 mail dovecot: imap(user): Error: sieve: pipe action: failed to pipe message to program: program `rspamc' not found
Jun 03 09:48:34 mail dovecot: imap(user): sieve: left message in mailbox 'Junk'
Jun 03 09:48:34 mail dovecot: imap(user): Error: sieve: Execution of script /etc/dovecot/sieve/global/learn-spam.sieve failed
What went wrong? Or is the pidgeonhole pipe command only able to call shell scripts?
Asked by Richard Rosner
(201 rep)
May 15, 2020, 11:20 AM
Last activity: Apr 29, 2022, 06:10 PM
Last activity: Apr 29, 2022, 06:10 PM