Dovecot2 Antispam MAILTRAIN backend with SpamAssassin
Hi there,
I've already asked this question on FreeBSD forums without getting any response. So, I thought it's a good idea to ask it again here.
I've setup Dovecote2 (2.2.13) + Postfix + SpamAssassin on my FreeBSD 10 VPS and it works flawlessly. Though, I couldn't setup the Dovecot Antispam plugin to train SpamAssassin when I move mails to the Junk folder.
I installed the plugin from FreeBSD ports and followed the official documentation [1] and the man page [2] without any success.
This is my configuration:
########
# 2.2.13: /usr/local/etc/dovecot/dovecot.conf # OS: FreeBSD 10.0-RELEASE-p6 i386 ufs auth_mechanisms = plain login digest-md5 disable_plaintext_auth = no first_valid_gid = 6 first_valid_uid = 26 last_valid_gid = 6 last_valid_uid = 26 lmtp_save_to_detail_mailbox = yes mail_gid = mail mail_location = mdbox:/mail/%d/%u mail_privileged_group = mail mail_uid = mailnull managesieve_notify_capability = mailto managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date ihave namespace inbox { inbox = yes location = mailbox Archive { auto = no special_use = Archive } mailbox Drafts { auto = subscribe special_use = Drafts } mailbox Flagged { auto = no special_use = Flagged } mailbox Junk { auto = subscribe special_use = Junk } mailbox Sent { auto = subscribe special_use = Sent } mailbox Trash { auto = subscribe special_use = Trash } mailbox virtual/All { auto = no special_use = All } prefix = separator = / } passdb { args = /mail/%d/dovecot_passwd driver = passwd-file } plugin { antispam_backend = MAILTRAIN antispam_mail_notspam = --ham antispam_mail_sendmail = /mail/sa-learn-pipe.sh antispam_mail_spam = --spam antispam_spam = Junk antispam_trash = Trash quota_rule = *:storage=8GB sieve = /mail/%d/%u/dovecot.sieve sieve_dir = /mail/%d/%u sieve_global_dir = /mail/sieve sieve_global_path = /mail/sieve/globalfilter.sieve } protocols = imap pop3 lmtp sieve service auth { unix_listener auth-client { group = mail mode = 0660 user = postfix } unix_listener auth-master { group = mail mode = 0600 user = mailnull } user = root } service imap-login { inet_listener imap { address = * port = 143 } inet_listener imaps { address = * port = 993 } process_limit = 32 process_min_avail = 1 } service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { group = postfix mode = 0660 user = postfix } } service managesieve-login { inet_listener sieve { port = 4190 } process_min_avail = 0 service_count = 1 vsz_limit = 64 M } service managesieve { process_limit = 1024 } service pop3-login { inet_listener pop3 { address = * port = 110 } inet_listener pop3s { address = * port = 995 } process_limit = 32 process_min_avail = 1 } ssl_cert = </etc/ssl/dovecot/cert.pem ssl_key = </etc/ssl/dovecot/key.pem userdb { args = /mail/%d/dovecot_passwd driver = passwd-file } verbose_proctitle = yes protocol lmtp { mail_plugins = " sieve" postmaster_address = postmaster@SomeDomain.com quota_full_tempfail = yes } protocol sieve { mail_max_userip_connections = 10 managesieve_implementation_string = Dovecot Pigeonhole managesieve_logout_format = bytes=%i/%o managesieve_max_line_length = 65536 } protocol imap { imap_client_workarounds = delay-newmail tb-extra-mailbox-sep mail_plugins = " quota imap_quota antispam" } protocol pop3 { mail_plugins = " quota" pop3_client_workarounds = outlook-no-nuls oe-ns-eoh } protocol lda { mail_plugins = " quota sieve" postmaster_address = postmaster@SomeDomain.com sendmail_path = /usr/local/sbin/sendmail }
########
And, this is the script /mail/sa-learn-pipe.sh:
########
echo /usr/local/bin/sa-learn $* /tmp/sendmail-msg-$$.txt echo "$$-start ($*)" >> /tmp/sa-learn-pipe.log
#echo $* > /tmp/sendmail-parms.txt cat<&0 >> /tmp/sendmail-msg-$$.txt
/usr/local/bin/sa-learn $* /tmp/sendmail-msg-$$.txt
rm -f /tmp/sendmail-msg-$$.txt
echo "$$-end" >> /tmp/sa-learn-pipe.log
exit 0
########
I made it excecutable by all users using chmod a+x /mail/sa-learn-pipe.sh
The problem is, there is no log in /var/log/maillog regarding the Antispam plugin, and the script won't get called when I move any message in/out to/from Junk folder.
I'll appreciate any help.
-- "When I give, I give myself." - Walt Whitman
Links:
[1] http://wiki2.dovecot.org/Plugins/Antispam [2] http://hg.dovecot.org/dovecot-antispam-plugin/raw-file/tip/doc/dovecot-antis...
I remember, that I also struggled for quite a while until I figured it out. Here is what I used on my FreeBSD Dovecot installation ...
Remember, that the following code is working on "dovecot --version 1.2.12" ... but it could also be valid for later versions. I simply havn't checked it out yet.
### Dovecot AntiSpam ### # mail signature (used with any backend requiring a signature) #antispam_signature = X-Spam-Status #antispam_signature_missing = move
antispam_mail_sendmail = /usr/local/etc/dovecot/sa-learn-helper.sh
antispam_mail_sendmail_args = --username=%Lu
antispam_mail_spam = --spam
antispam_mail_notspam = --ham
antispam_mail_tmpdir = /tmp
antispam_spam = Spam
#antispam_unsure = Virus
antispam_trash = Trash
echo '#!/usr/local/bin/bash
#/usr/local/bin/sa-learn ${1} ${2} ${3} ${4} &> /var/log/DoveDamnAntiSpam.log /usr/local/bin/sa-learn "${1}" "${2}" "${3}" "${4}" exit 0
' > /usr/local/etc/dovecot/sa-learn-helper.sh chmod 0777 /usr/local/etc/dovecot/sa-learn-helper.sh ; chown root:wheel /usr/local/etc/dovecot/sa-learn-helper.sh ;
Best regards Leander
Am 15.07.14 15:00, schrieb Mohammad S. Babaei:
Hi there,
I've already asked this question on FreeBSD forums without getting any response. So, I thought it's a good idea to ask it again here.
I've setup Dovecote2 (2.2.13) + Postfix + SpamAssassin on my FreeBSD 10 VPS and it works flawlessly. Though, I couldn't setup the Dovecot Antispam plugin to train SpamAssassin when I move mails to the Junk folder.
I installed the plugin from FreeBSD ports and followed the official documentation [1] and the man page [2] without any success.
This is my configuration:
########
# 2.2.13: /usr/local/etc/dovecot/dovecot.conf # OS: FreeBSD 10.0-RELEASE-p6 i386 ufs auth_mechanisms = plain login digest-md5 disable_plaintext_auth = no first_valid_gid = 6 first_valid_uid = 26 last_valid_gid = 6 last_valid_uid = 26 lmtp_save_to_detail_mailbox = yes mail_gid = mail mail_location = mdbox:/mail/%d/%u mail_privileged_group = mail mail_uid = mailnull managesieve_notify_capability = mailto managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date ihave namespace inbox { inbox = yes location = mailbox Archive { auto = no special_use = Archive } mailbox Drafts { auto = subscribe special_use = Drafts } mailbox Flagged { auto = no special_use = Flagged } mailbox Junk { auto = subscribe special_use = Junk } mailbox Sent { auto = subscribe special_use = Sent } mailbox Trash { auto = subscribe special_use = Trash } mailbox virtual/All { auto = no special_use = All } prefix = separator = / } passdb { args = /mail/%d/dovecot_passwd driver = passwd-file } plugin { antispam_backend = MAILTRAIN antispam_mail_notspam = --ham antispam_mail_sendmail = /mail/sa-learn-pipe.sh antispam_mail_spam = --spam antispam_spam = Junk antispam_trash = Trash quota_rule = *:storage=8GB sieve = /mail/%d/%u/dovecot.sieve sieve_dir = /mail/%d/%u sieve_global_dir = /mail/sieve sieve_global_path = /mail/sieve/globalfilter.sieve } protocols = imap pop3 lmtp sieve service auth { unix_listener auth-client { group = mail mode = 0660 user = postfix } unix_listener auth-master { group = mail mode = 0600 user = mailnull } user = root } service imap-login { inet_listener imap { address = * port = 143 } inet_listener imaps { address = * port = 993 } process_limit = 32 process_min_avail = 1 } service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { group = postfix mode = 0660 user = postfix } } service managesieve-login { inet_listener sieve { port = 4190 } process_min_avail = 0 service_count = 1 vsz_limit = 64 M } service managesieve { process_limit = 1024 } service pop3-login { inet_listener pop3 { address = * port = 110 } inet_listener pop3s { address = * port = 995 } process_limit = 32 process_min_avail = 1 } ssl_cert = </etc/ssl/dovecot/cert.pem ssl_key = </etc/ssl/dovecot/key.pem userdb { args = /mail/%d/dovecot_passwd driver = passwd-file } verbose_proctitle = yes protocol lmtp { mail_plugins = " sieve" postmaster_address = postmaster@SomeDomain.com quota_full_tempfail = yes } protocol sieve { mail_max_userip_connections = 10 managesieve_implementation_string = Dovecot Pigeonhole managesieve_logout_format = bytes=%i/%o managesieve_max_line_length = 65536 } protocol imap { imap_client_workarounds = delay-newmail tb-extra-mailbox-sep mail_plugins = " quota imap_quota antispam" } protocol pop3 { mail_plugins = " quota" pop3_client_workarounds = outlook-no-nuls oe-ns-eoh } protocol lda { mail_plugins = " quota sieve" postmaster_address = postmaster@SomeDomain.com sendmail_path = /usr/local/sbin/sendmail }
########
And, this is the script /mail/sa-learn-pipe.sh:
########
echo /usr/local/bin/sa-learn $* /tmp/sendmail-msg-$$.txt echo "$$-start ($*)" >> /tmp/sa-learn-pipe.log
#echo $* > /tmp/sendmail-parms.txt cat<&0 >> /tmp/sendmail-msg-$$.txt
/usr/local/bin/sa-learn $* /tmp/sendmail-msg-$$.txt
rm -f /tmp/sendmail-msg-$$.txt
echo "$$-end" >> /tmp/sa-learn-pipe.log
exit 0
########
I made it excecutable by all users using chmod a+x /mail/sa-learn-pipe.sh
The problem is, there is no log in /var/log/maillog regarding the Antispam plugin, and the script won't get called when I move any message in/out to/from Junk folder.
I'll appreciate any help.
Hello Leander,
Thank you so much for the answer.
But I believe there are two versions of the AntiSpam plugin. One is so called Johannes version for version 1.x and the other Eugene version for 2.x series, which is also based on the Johannes version but it is different and the configurations for version 1.x may not work on 2.x.
Anyway, thanks to you, there are now good news. I've tried you're configuration and script, it seemed that your script was getting called. Then I reverted back to my own configuration and script, and boom, automagically it started working. Probably, I may have made a stupid mistake the first time. Now I see the temp files are being created and I can see SpamAssassin getting called with the right parameters.
Thank you so much.
Regards,
Mohammad S. Babaei
"When I give, I give myself." - Walt Whitman
On 2014-07-15 17:43, Leander Schäfer wrote:
I remember, that I also struggled for quite a while until I figured it out. Here is what I used on my FreeBSD Dovecot installation ...
Remember, that the following code is working on "dovecot --version 1.2.12" ... but it could also be valid for later versions. I simply havn't checked it out yet.
### Dovecot AntiSpam ### # mail signature (used with any backend requiring a signature) #antispam_signature = X-Spam-Status #antispam_signature_missing = move
antispam_mail_sendmail = /usr/local/etc/dovecot/sa-learn-helper.sh antispam_mail_sendmail_args = --username=%Lu antispam_mail_spam = --spam antispam_mail_notspam = --ham antispam_mail_tmpdir = /tmp antispam_spam = Spam #antispam_unsure = Virus antispam_trash = Trash
echo '#!/usr/local/bin/bash
#/usr/local/bin/sa-learn ${1} ${2} ${3} ${4} &> /var/log/DoveDamnAntiSpam.log /usr/local/bin/sa-learn "${1}" "${2}" "${3}" "${4}" exit 0
' > /usr/local/etc/dovecot/sa-learn-helper.sh chmod 0777 /usr/local/etc/dovecot/sa-learn-helper.sh ; chown root:wheel /usr/local/etc/dovecot/sa-learn-helper.sh ;
Best regards Leander
Am 15.07.14 15:00, schrieb Mohammad S. Babaei:
Hi there, I've already asked this question on FreeBSD forums without getting any response. So, I thought it's a good idea to ask it again here. I've setup Dovecote2 (2.2.13) + Postfix + SpamAssassin on my FreeBSD 10 VPS and it works flawlessly. Though, I couldn't setup the Dovecot Antispam plugin to train SpamAssassin when I move mails to the Junk folder. I installed the plugin from FreeBSD ports and followed the official documentation [1] and the man page [2] without any success. This is my configuration: ######## # 2.2.13: /usr/local/etc/dovecot/dovecot.conf # OS: FreeBSD 10.0-RELEASE-p6 i386 ufs auth_mechanisms = plain login digest-md5 disable_plaintext_auth = no first_valid_gid = 6 first_valid_uid = 26 last_valid_gid = 6 last_valid_uid = 26 lmtp_save_to_detail_mailbox = yes mail_gid = mail mail_location = mdbox:/mail/%d/%u mail_privileged_group = mail mail_uid = mailnull managesieve_notify_capability = mailto managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date ihave namespace inbox { inbox = yes location = mailbox Archive { auto = no special_use = Archive } mailbox Drafts { auto = subscribe special_use = Drafts } mailbox Flagged { auto = no special_use = Flagged } mailbox Junk { auto = subscribe special_use = Junk } mailbox Sent { auto = subscribe special_use = Sent } mailbox Trash { auto = subscribe special_use = Trash } mailbox virtual/All { auto = no special_use = All } prefix = separator = / } passdb { args = /mail/%d/dovecot_passwd driver = passwd-file } plugin { antispam_backend = MAILTRAIN antispam_mail_notspam = --ham antispam_mail_sendmail = /mail/sa-learn-pipe.sh antispam_mail_spam = --spam antispam_spam = Junk antispam_trash = Trash quota_rule = *:storage=8GB sieve = /mail/%d/%u/dovecot.sieve sieve_dir = /mail/%d/%u sieve_global_dir = /mail/sieve sieve_global_path = /mail/sieve/globalfilter.sieve } protocols = imap pop3 lmtp sieve service auth { unix_listener auth-client { group = mail mode = 0660 user = postfix } unix_listener auth-master { group = mail mode = 0600 user = mailnull } user = root } service imap-login { inet_listener imap { address = * port = 143 } inet_listener imaps { address = * port = 993 } process_limit = 32 process_min_avail = 1 } service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { group = postfix mode = 0660 user = postfix } } service managesieve-login { inet_listener sieve { port = 4190 } process_min_avail = 0 service_count = 1 vsz_limit = 64 M } service managesieve { process_limit = 1024 } service pop3-login { inet_listener pop3 { address = * port = 110 } inet_listener pop3s { address = * port = 995 } process_limit = 32 process_min_avail = 1 } ssl_cert = </etc/ssl/dovecot/cert.pem ssl_key = </etc/ssl/dovecot/key.pem userdb { args = /mail/%d/dovecot_passwd driver = passwd-file } verbose_proctitle = yes protocol lmtp { mail_plugins = " sieve" postmaster_address = postmaster@SomeDomain.com quota_full_tempfail = yes } protocol sieve { mail_max_userip_connections = 10 managesieve_implementation_string = Dovecot Pigeonhole managesieve_logout_format = bytes=%i/%o managesieve_max_line_length = 65536 } protocol imap { imap_client_workarounds = delay-newmail tb-extra-mailbox-sep mail_plugins = " quota imap_quota antispam" } protocol pop3 { mail_plugins = " quota" pop3_client_workarounds = outlook-no-nuls oe-ns-eoh } protocol lda { mail_plugins = " quota sieve" postmaster_address = postmaster@SomeDomain.com sendmail_path = /usr/local/sbin/sendmail } ######## And, this is the script /mail/sa-learn-pipe.sh: ######## echo /usr/local/bin/sa-learn $* /tmp/sendmail-msg-$$.txt echo "$$-start ($*)" >> /tmp/sa-learn-pipe.log #echo $* > /tmp/sendmail-parms.txt cat<&0 >> /tmp/sendmail-msg-$$.txt /usr/local/bin/sa-learn $* /tmp/sendmail-msg-$$.txt rm -f /tmp/sendmail-msg-$$.txt echo "$$-end" >> /tmp/sa-learn-pipe.log exit 0 ######## I made it excecutable by all users using chmod a+x /mail/sa-learn-pipe.sh The problem is, there is no log in /var/log/maillog regarding the Antispam plugin, and the script won't get called when I move any message in/out to/from Junk folder. I'll appreciate any help.
participants (2)
-
Leander Schäfer
-
Mohammad S. Babaei