Using spamassassin on a remote IMAP Host ################################## :date: 2014-04-15 14:20 :tags: spamassassin, mutt,offlineimap,imapfilter I have the fortunate situation that i have hosted mail on a trusted second party (my father) so i do not have to deal with anything mail server related. I have a domain for receiving mails and i use a wildcard address to receive all the mails. Until now --------- ... I had the following setup: 1. Wherever i sign up with a mail address i use something like mailto://@ 2. imapfilter_ pre-sorts mails based on the signup address 3. offlineimap_ retrieves new mails and puts them in my $HOME/Mail 4. mutt_ + msmtp_ to read and send mails Everything worked fine but my imapfilter list for spam grew above the 100 entries because some of my addresses were leaked by the web service i was using. Most spam mails got sorted correctly into my Spam folder but some survived the sorting. Spamassassin to the rescue -------------------------- Everybody seems to be using spamassassin and i always thought it can only be used with procmail and real mail retrieval. Turns out isbg.py_ is what may solve all my spam problems. It logs into the imap host and filters new mails with the help of spamassassin. Installation and preparation: .. code-block:: bash #?/bin/sh # install sa aptitude install spamassassin pyzor # enable SA, activate 'allow-tell' sed -i -e 's#ENABLED=.*#ENABLED=1#' -e 's#OPTIONS=.*#OPTIONS="-4 --create-prefs --max-children 5 --helper-home-dir --allow-tell"#' /etc/default/spamassassin update-rc.d spamassassin enable /etc/init.d/spamassassin start # install IMAP spam begone pip install isbg Configuration and learning: .. code-block:: bash #?/bin/sh # configure SA to your liking cat > $HOME/.spamassassin < --ssl --imapuser --spaminbox INBOX.Spam --spamc --teachonly --learnspambox INBOX.Spam --savepw vim $HOME/.offlineimaprc # change Presynchook = imapfilter to $HOME/bin/filter_mail cat > $HOME/bin/filter_mail < --ssl --imapuser --spaminbox INBOX.Spam --delete --expunge --noninteractive --spamc imapfilter EOF # dont worry, --delete --expurge only deletes the messages from your inbox (and essentially moves them to your Spam folder) # create mutt macro to mark and move spam in your inbox echo 'macro index,pager S "| sa-learn --spam\ns=INBOX.Spam\n\n" "file as Spam"' >> $HOME/.muttrc # optional: disbale the 'press any key to continue' : # echo 'set wait_key = no' >> $HOME/.muttrc After learning my >9000 spam mails in the spam folder the spamassassin bayes filter was trained pretty well. Now i was able to remove all the 'spam' rules from .imapfilter/config.lua, and it felt GREAT.