jgaard
Posts: 9
Joined: Tue Jun 10, 2014 4:48 am

Filtering SPAM, remote IMAP

Thu Feb 21, 2019 3:01 pm

Hi

I have a series of mail addresses. All hosted remotely all IMAP.
I was thinking about using spamassassin on my PI to filter the mail.
But I havn't been able to find a set of instructions on how to do this.

I do not want to run a mail server, I only want to run the filter.

If I can make it work for me, I'll add my family's mails to it too.

regards J;-)

Area30
Posts: 5
Joined: Fri Nov 08, 2013 12:35 pm

Re: Filtering SPAM, remote IMAP

Fri Feb 22, 2019 1:31 pm

Hi J,

please have a look at "IMAP Spam Begone" (isbg).
https://github.com/isbg/isbg

That's all you need.

Regards,
Area30

TinkerDr
Posts: 1
Joined: Sun Mar 03, 2019 11:50 am

Re: Filtering SPAM, remote IMAP

Sun Mar 03, 2019 12:36 pm

Hi All,

Based on this suggestion I checked this out: I find it to work just great!
It is now washing my email every 12 minutes.
When it determines something as Spam, it creates an email with the Spam attached in the Spam folder. ISBG fills the email body with the assessment results and attaches the SPAM to the new email (disarm nasty things like tracking).

Short recap:

Code: Select all

apt-get install spamassassin
And enable it:

Code: Select all

systemctl enable spamassassin.service
sudo systemctl enable spamassassin.service
and check:

Code: Select all

sudo service --status-all
..spamassassin.. should be in that list

In order to mark spam email with *****SPAM***** in the subject, go to the /etc/spamassassin/local.cf
Uncomment the part that does that and make a change to contact and hostname information (system wide setting):
# Add *****SPAM***** to the Subject header of spam e-mails
#
rewrite_header Subject *****SPAM*****
report_contact isbg@SpamPi.net
report_hostname SpamPi.net

Then go to the local pi user directory and find /home/pi/.spamassassin/user_prefs
This helps prevents changes due to upgrades of Spamassassin
You can set the scoring for SPAM a bit more agressive:
# Set the threshold at which a message is considered spam (default: 5.0)
#
required_score 2.8
Als added whitelisting and discovered not to use " or , signs. I gave the example for blacklisting in commented style:
# Whitelist and blacklist addresses are now file-glob-style patterns, so
# "friend@somewhere.com", "*@isp.com", or "*.domain.net" will all work.
# Added note do not use the quotes and comma and multiple lines with keyword are allowed
whitelist_from someone@coldmail.com news@somecompany.com
whitelist_from transactions@notice.somecompany.com
#blacklist_from thebad@badhost.com
Then upwards and onwards.. make sure you have pip3 installed (corresponding with Python3 which we check as well).

Code: Select all

sudo apt-get install python3
sudo apt-get -y install python3-pip
sudo pip3 install isbg
..Almost there.. actually we are done ..try running it:

Code: Select all

isbg --help
Ok, just to get an idea of your IMAP structure run this to get a list (note.. you can append the --savepw to have isbg remember your password in a local obfuscated file.. my Raspberry is not seen from the internet but think twice about your setup here)

Code: Select all

isbg --verbose-mails --imaphost <<Provider IMAP HOSTname>> --imapuser <<USER as you would logon in webmail>>  --imapport <<YourISPKnows>> --imaplist
Since I use email on my mobile device in POP3 mode (I like a mail archive while on the road) and my desktop in POP3 mode, I figured it would be best to have the output written to my Spam folder and create an extra IMAP account of the existing email account on my mobile device. From each email address I now have an IMAP version. That way I can monitor the IMAP 'Spam' folder. If something gets caught as SPAM that should not be there, I can read it, forward it to an unmonitored POP3 email box and also make changes to the settings of SpamAssassin on the Raspberry.

The

Code: Select all

crontab -e
does the rest. Do not forget to mark your script as executable AND include a PATH variable in the Crontab.
So this is my CRONTAB:

Code: Select all

# Set PATH variables in this crontab
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
#
# m  h dom mon dow   command
*/12 * * * * bash /home/pi/isbg/isbg_washer.sh

Also for testing purposes I added a rule in the user_prefs:

Code: Select all

# Added test to provoke a message to become SPAM for testing purposes
body LOCAL_MAKE_SPAM_RULE    /\bThis triggers it\b/i
score LOCAL_MAKE_SPAM_RULE  101.1
describe LOCAL_MAKE_SPAM_RULE     if text is seen then message is SPAM
Also.. I like the SPAMhaus list and think the default scores are a but low. Override them in user_prefs if you like:

Code: Select all

# UPGRADING scores of SPAMHaus listing
score RCVD_IN_PBL 5.0
score RCVD_IN_XBL 5.0
score RCVD_IN_SBL 5.0
score RCVD_IN_CSS 5.0
Final command in my setup:

Code: Select all

#!/bin/bash
#exec &>/home/pi/isbg/cronjob.log    you could uncomment this to look at CRON output if something is not working
isbg --verbose --imaphost <<Provider IMAP HOSTname>> --imapuser <<USER as you would logon in webmail>> --imapport <<YourISPKnows>> --partialrun 10 --spaminbox Spam --delete --expunge
Final remark: You could get rid of the --verbose

I wanted to share this because I think this really fast forwards the installation and helps the Spam to really be gone.
To close this post : A shout of thanks to the great people of ISBG.. super appreciated!

Return to “Advanced users”