Re: Getting Postfix to sort spam into different folders
Hi Stan, many thanks for your explanation! This is pretty much exactly what I want so will check the docs for specifics on how to set it all up. Robin Am 03.10.2013 um 05:26 schrieb Stan Hoeppner : > On 10/2/2013 10:17 AM, Robin Kipp wrote: >> Hi all, >> I've been running my own mail server for a while (Postfix as the MTA and >> Dovecot for retrieving mail via IMAP). >> Yesterday, I added amavis-new for content filtering, and so far have >> implemented spam checking using spamassassin and virus filtering using >> clamav. >> All this appears to be working well - if anyone has some time to spare, feel >> free to check the header of this message - if there are any things that >> could be improved, I certainly would appreciate any feedback! :-) >> So, now that spamassassin is flagging junk mail, I really would like a way >> of having said junk sorted into a different folder for each user. I'm aware >> this can also be done on the MUA side, but on some end-user devices (such as >> smartphones), junkmail filtering is often not supported very unfortunately. >> So, I was just wondering… Is there any way I could do this on the server >> side? >> My main problem really is that I'm not sure where I'd best set this up - but >> I'm guessing I'd have to do it in Postfix, as I use the 'virtual' local >> delivery agent to drop incoming mail into the appropriate directories. Also, >> the mailboxes are stored in maildir format if that makes any difference… >> If anyone has anything like this working or could point me in the right >> direction I would greatly appreciate that! >> Many thanks :-) >> Robin > > Dovecot includes the sieve language for sorting. Per user, you'd have a > .dovecot.sieve file in the home directory, containing something like: > > /home/stan/.dovecot.sieve > > require "fileinto"; > > if false {} > > elsif header :contains "X-Spam-Flag" "YES" { >fileinto "Spam"; >stop; > } > ... > > This will move the flagged messages into the user's IMAP folder named > "Spam". > > You must use Dovecot LDA or LMTP for delivery if you want to use sieve. > The advantage of using sieve vs procmail, maildrop, etc, is that > Dovecot LDA/LMTP index the messages during the delivery phase. If you > use procmail/maildrop then Dovecot doesn't index messages until you open > the mailbox, which is slower. > > You can also use Managesieve which allows users to create their own > filter rules. It is also possible to have a global sieve file for all > users, for thing such as spam sorting, and individual user defined sieve > rules simultaneously. > > -- > Stan > > > -- > To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org > with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org > Archive: http://lists.debian.org/524ce3f0.1060...@hardwarefreak.com > -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/d6270a25-4cd5-4b01-8f96-d456e0e82...@robin-kipp.net
Re: Getting Postfix to sort spam into different folders
On 10/2/2013 10:17 AM, Robin Kipp wrote: > Hi all, > I've been running my own mail server for a while (Postfix as the MTA and > Dovecot for retrieving mail via IMAP). > Yesterday, I added amavis-new for content filtering, and so far have > implemented spam checking using spamassassin and virus filtering using clamav. > All this appears to be working well - if anyone has some time to spare, feel > free to check the header of this message - if there are any things that could > be improved, I certainly would appreciate any feedback! :-) > So, now that spamassassin is flagging junk mail, I really would like a way of > having said junk sorted into a different folder for each user. I'm aware this > can also be done on the MUA side, but on some end-user devices (such as > smartphones), junkmail filtering is often not supported very unfortunately. > So, I was just wondering… Is there any way I could do this on the server side? > My main problem really is that I'm not sure where I'd best set this up - but > I'm guessing I'd have to do it in Postfix, as I use the 'virtual' local > delivery agent to drop incoming mail into the appropriate directories. Also, > the mailboxes are stored in maildir format if that makes any difference… > If anyone has anything like this working or could point me in the right > direction I would greatly appreciate that! > Many thanks :-) > Robin Dovecot includes the sieve language for sorting. Per user, you'd have a .dovecot.sieve file in the home directory, containing something like: /home/stan/.dovecot.sieve require "fileinto"; if false {} elsif header :contains "X-Spam-Flag" "YES" { fileinto "Spam"; stop; } ... This will move the flagged messages into the user's IMAP folder named "Spam". You must use Dovecot LDA or LMTP for delivery if you want to use sieve. The advantage of using sieve vs procmail, maildrop, etc, is that Dovecot LDA/LMTP index the messages during the delivery phase. If you use procmail/maildrop then Dovecot doesn't index messages until you open the mailbox, which is slower. You can also use Managesieve which allows users to create their own filter rules. It is also possible to have a global sieve file for all users, for thing such as spam sorting, and individual user defined sieve rules simultaneously. -- Stan -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/524ce3f0.1060...@hardwarefreak.com
Re: Getting Postfix to sort spam into different folders
On Wed, Oct 02, 2013 at 05:17:53PM +0200, Robin Kipp wrote: > So, now that spamassassin is flagging junk mail, I really would like a way of > having said junk sorted into a different folder for each user. I'm aware this > can also be done on the MUA side, but on some end-user devices (such as > smartphones), junkmail filtering is often not supported very unfortunately. > So, I was just wondering… Is there any way I could do this on the server side? > My main problem really is that I'm not sure where I'd best set this up - but > I'm guessing I'd have to do it in Postfix, as I use the 'virtual' local > delivery agent to drop incoming mail into the appropriate directories. Also, > the mailboxes are stored in maildir format if that makes any difference… > If anyone has anything like this working or could point me in the right > direction I would greatly appreciate that! > Many thanks :-) I have what you describe going also using postfix, and maildrop for filtering. The relevent part of my /etc/postfix/main.cf reads: virtual_mailbox_domains = example.com virtual_mailbox_base = /var/mail/vhosts virtual_mailbox_maps = hash:/etc/postfix/vmailbox virtual_minimum_uid = 100 virtual_uid_maps = static:5000 virtual_gid_maps = static:5000 maildrop_destination_recipient_limit = 1 virtual_transport = maildrop virtual_mailbox_limit = 0 In my /etc/postfix/master.cf I have: # maildrop. See the Postfix MAILDROP_README file for details. # Also specify in main.cf: maildrop_destination_recipient_limit=1 # maildrop unix - n n - - pipe flags=DRhu user=vhosts argv=/usr/bin/maildrop # /var/mail/vhosts/maildrop_filters/${domain}/${mailbox} My /etc/postfix/vmailbox reads: i...@example.comna Don't forget to run: postmap vmailbox postfix reload when you're ready to go live with this setup. All of the above so far was configured with the help of /usr/share/doc/postfix with the postfix-doc package installed, and with the help of the postfix man pages. I might also have used /usr/share/doc/postfix-doc/examples, but I don't remember if I actually did or not. Next, I created a user called vhosts and a group called vhosts. Both the uid and gid are 5000. Both the uid and gid must match what you have in /etc/postfix/main.cf. The home directory of vhosts is of course /var/mail/vhosts, which must also match in /etc/postfix/main.cf. Ok. The below is partly from postfix documentation, partly from maildrop documentation, and partly from the web. In /var/mail/vhosts I have the following: example.com, which is a directory (more on that below) maildrop_filters which is a directory (more on that below) spamass_domain_list, which is a text file (more on that below) I'll explain the above one by one. In the directory called example.com I have a typical maildir called info for the user i...@example.com. This maildir has another maildir inside it called .Spam/ which as you might guess is where all the spam mail goes. Let's move on to the maildrop_filters directory. In this directory, I have another directory called example.com. In this example.com directory, I have a file called ... you guessed it ... info. This info file reads: DEFAULT="$HOME/example.com/info/" xfilter "/usr/bin/spamc" if (/^X-Spam-Flag: YES/:h || /^X-Spam-Status: Yes/:h) { to "$DEFAULT/.Spam/" } These are the instructions used by maildrop to put ham in info/, and spam in info/.Spam/ based on the message headers. Finally, the text file spamass_domain_list reads: example.com This file contains all the domains to be checked for ham/spam by the script I'll describe below. In /etc/cron.daily, I have a script called spam_script. I found this script on the web, and modified it as needed. I don't remember where I found it at, but a web search should yield that info probably easily. The script reads: #!/bin/bash # # Script to learn spam using sa-learn. Just edit the default names of #your # spam folder using the variables # below. # SPAM_FOLDER=.Spam # # DOMAIN_LIST=`cat /var/mail/vhosts/spamass_domain_list` SALEARN=`which sa-learn` LEARN_SPAM="$SALEARN --dbpath /var/mail/vhosts/.spamassassin --no-sync --spam" LEARN_HAM="$SALEARN --dbpath /var/mail/vhosts/.spamassassin --no-sync --ham" VPOPMAIL_HOME=/var/mail/vhosts for DOMAIN in $DOMAIN_LIST; do DOMAIN_USERS="`ls /var/mail/vhosts/$DOMAIN/ --ignore=postmaster`" for USER in $DOMAIN_USERS; do $LEARN_SPAM $VPOPMAIL_HOME/$DOMAIN/$USER/$SPAM_FOLDER/cur $LEARN_HAM $VPOPMAIL_HOME/$DOMAIN/$USER/cur done done $SALEARN --dbpath /var/mail/vhosts/.spamassassin --sync /usr/local/sbin/spam_fix I see some of the lines wrapped when I pasted it. So, you'll want to fix those. The spam_fix script was written by me. It fixes ownership which gets changed when salearn is run. The spam_fix script reads: #!/bin/sh # script to fix ownership for spamassassin files chown vhosts ~vhosts/.spa
Re: Getting Postfix to sort spam into different folders
I do this using procmail on my server, with a .procmailrc in each user's folder. I do use virtual accounts but there's at least one UNIX account behind each virtual one (so it's many virtual:one UNIX mapping), so if you don't have real UNIX accounts at the bottom this won't work. Also procmail is horrid, I use exim and could probably move to exim filter language (in ~/.forward) if I could ever be bothered to learn it. I am not aware if postfix has something similar internally but strongly suspect it can be wrangled to support procmail. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20131002160832.GA11338@debian
Getting Postfix to sort spam into different folders
Hi all, I've been running my own mail server for a while (Postfix as the MTA and Dovecot for retrieving mail via IMAP). Yesterday, I added amavis-new for content filtering, and so far have implemented spam checking using spamassassin and virus filtering using clamav. All this appears to be working well - if anyone has some time to spare, feel free to check the header of this message - if there are any things that could be improved, I certainly would appreciate any feedback! :-) So, now that spamassassin is flagging junk mail, I really would like a way of having said junk sorted into a different folder for each user. I'm aware this can also be done on the MUA side, but on some end-user devices (such as smartphones), junkmail filtering is often not supported very unfortunately. So, I was just wondering… Is there any way I could do this on the server side? My main problem really is that I'm not sure where I'd best set this up - but I'm guessing I'd have to do it in Postfix, as I use the 'virtual' local delivery agent to drop incoming mail into the appropriate directories. Also, the mailboxes are stored in maildir format if that makes any difference… If anyone has anything like this working or could point me in the right direction I would greatly appreciate that! Many thanks :-) Robin -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/9ec87fc3-31f2-48bb-ade3-4e7b38d10...@robin-kipp.net