Categories
Fedora

Anti-Spam through an IMAP Account

As we are increasingly dealing with an aging population, this adds technological problems. My elderly mother has developed dementia and has lost any technology knowledge that she had other than basic Windows operating system fundamentals. Her primary access to the Internet is via Outlook (the e-mail client) and a web browser. In her diminished capacity of memory and cognitive abilities she will open nearly every single e-mail that she gets. And does she get them. Roughly around 1,000 e-mails a day. With big ISPs (Comcast) allowing willy nilly whatever to come through their mail servers this is a disaster waiting to happen.

Well, why not just install some anti-spam for Outlook application you ask? Ah you mean the 2000’s era software that no longer works or is available? Yeah, that is why. The worthless Anti-Virus software packages ‘Anti-Spam’ has a hit rate of about 0.01%. Super effective isn’t it? It’s great for detecting viruses, not for spam e-mails. Which makes sense. It’s Anti-Virus. Entirely different thing.

Users with disabilities like dementia (again memory loss) is challenging as anything that changes can cause serious issues. I can’t just up and replace the Outlook application she has been using for years with something that may have better built in anti-spam.

Again, I cannot just switch over to a mail server I manage. She’s had her Comcast e-mail address for decades now. That is what she knows. Creating some elaborate forwarding system is just asking for trouble managing that. And yes, this would be the most ideal way of solving the problem. And I highly recommend it. Especially if you are in a position where the person with dementia onset is early and you can move over to an e-mail system that you have control over. The best place for anti-spam is before it’s acceptance and delivery to the user. And this is how most of the solutions migrated to.

Alas I do not have the ability to control what Comcast accepts as e-mail before delivery. But, I have found a middle ground solution that appears to work well. Unfortunately it has some caveats. As I mentioned, this is an old way of dealing with spam e-mail, so the software has been nearly abandoned. But there is still hope.

The solution is relatively simple in a complex system. Logging into the IMAP service, fetching and scanning the e-mail via Spamassassin anti-spam application, marking the e-mails that are detected as spam, moving them to a Spam/Junk folder (and optionally just deleting them). The solution does not require running any software on the users computer itself, although it can be. But I wouldn’t recommend it in this scenario of a dementia patient. It will need to be running on a separate (remote) computer (a VM perhaps hosted somewhere).

The solution I found is just two software applications. A python based application called ISBG (IMAP Spam Begone) and Spamassassin.

For Fedora Linux you will want to install Spamassassin.

$ sudo dnf install spamassassin

Then make sure the python installer pip is installed.

$ sudo dnf install pip

Then install isbg.

$ pip install isbg

Well, that’s it! NOT! Did you think it was going to be that easy? As I mentioned earlier, this way of anti-spam has been pushed as a thing of the past. So, the isbg software was yeeted by the developers years ago. Probably beause only 4 people in the world used it as no one really knew what to use it for. And because the isbg application is written in Python which changes every version release. And don’t get me wrong, Python is super cool and you should learn it.

When writing this article, the current version of isbg is v2.3.1. I have no idea which version of Python it was initially released for, but the current version of Python is v3.12.5. The isbg application will immediately fail with:

$ isbg
Traceback (most recent call last):
File "/home/<yourusername>/.local/bin/isbg", line 5, in <module>
from isbg.__main__ import main
File "/home/<yourusername>/.local/lib/python3.12/site-packages/isbg/__init__.py", line 10, in <module>
from .isbg import ISBG, ISBGError, __version__, __exitcodes__, __license__
File "/home/<yourusername>/.local/lib/python3.12/site-packages/isbg/isbg.py", line 23, in <module>
from isbg import imaputils
File "/home/<yourusername>/.local/lib/python3.12/site-packages/isbg/imaputils.py", line 40, in <module>
Email = TypeVar(email.message.Message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: typevar() argument 'name' must be str, not type

Awesome! Right? Just what you wanted in your journey to hell (if you’ve gotten this far you’ve been there for awhile). But have no fear. This is actually a fairly simple solution. Mind boggling, I know. You just need to edit the file below at line 40. Use whatever text editor you are familiar with.

/home/<yourusername>/.local/lib/python3.12/site-packages/isbg/imaputils.py

Line 40:
Email = TypeVar(email.message.Message)

Change To:
Email = TypeVar(str(email.message.Message))

And now the isbg application will work. It will still have some issues with specific malformed e-mail’s and it does not appear to work with the –spamc option.

You will now need to get the username, password and the IMAP server address for the e-mail account you’ll want to scan. The e-mail account will also need a Spam or some sort of Junk folder to move the spam to already created. isbg will not create the folder. In this example, my moms account already had Junk folder, so that is what I am using. By default it is Spam. If isbg does not detect this, it will exit with an error saying so. This example also uses Comcast as the IMAP. The first run of the isbg command you will want to use the –savepw (Save Password) command, so subsequent commands will not prompt you for the password. Note that the password is saved in plain text. There’s no getting around that. isbg will by default only scan 50 e-mails per run. We’ll keep it at that for the first run.

isbg --verbose --imaphost imap.comcast.net --imapuser <yourmom>@comcast.net --spaminbox Junk --savepw

Again, if you have the default Spam folder for spam e-mails, remove the –spaminbox command. Without any errors it will login, and scan through the messages. It’s a bit on the slow side so many take a couple of minutes.

Now that it has completed you can add the better options I have found. I do not recommend running isbg wide open (meaning scanning all e-mails in a single run). It will crash on specific malformed e-mails and you will lose any sort of progress made. It only does it’s write operations after all e-mails have been scanned. I’ve found a happy medium of 250 e-mails to be acceptable. (And yes we’re talking about someone who gets several hundred to a thousand e-mails per day.) Here is the new command.

isbg --verbose --imaphost imap.comcast.net --imapuser <yourmom>@comcast.net --spaminbox Junk --maxsize 512000 --partialrun 250 --flag

The maxsize is what maximum size e-mail to fetch from the IMAP server. isbg defaults to a considerably low value. Most spam these days are much larger than it. So I put the max e-mail size to 512kbytes. The partialrun command is where you set how many e-mails are processed during this session. 0 means all of them. I do not recommend this. I set this to 250. Enough where I can cover a large group of e-mails but not lose an hour and a half of processing if isbg comes across a malformed e-mail message. (Remember we don’t have control of the delivery.) The flag command tells isbg what to do after the scan is done. Prepend the subject with [SPAM] and the score of it and move it into the Junk folder (the setting from the spaminbox).

That is really it. You can create a crontab to run this command however often. I would not recommend minutes but four times a day. Depends on the volume of e-mail coming into the account.

Anyways, that about wraps it up for this. I wrote this to mainly remember what I changed to make the isbg program to work. This was written by a real person with no AI involved. I will edit this at a later time after publication with attributions.

Welcome to Costco, I love you.

Categories
Fedora Sendmail

Sendmail – Spamassassin – Configuration Errors

This is an entry to remind me of how I corrected some small issues with Spamassassin. I use Fedora, Sendmail, Spamassassin and upon upgrading to latest version I started getting some errors from Spamassassin. This is how I fixed the errors.

Can’t locate MLDBM/Sync.pm error

I got this error even though the MLDBM perl module was installed via the package system. This may be a deprecated configuration, as it appears the solution is something to do with mySQL databases. I went with the cpan, cpanm, then install the MLDBM::Sync module route. Quick and painless. As root:

; Install cpanminus.
#cpan App::cpanminus
; Using cpanm to install the MLDBM:Sync that is missing from package.
#cpanm MLDBM::Sync

FuzzyOcr: Cannot find executable for gifinter

This error is due to the giflibs v5.x no longer has many of the utilities that were in the v4.x releases and FuzzyOcr hasn’t been updated. I suspect this isn’t really used much anymore, but there’s a couple solutions. I used the method of downloading, compiling and copying over the giflib v4.x gifinter program. Just download the latest v4.x version from the sourceforge project. Do the usual ./configure; make. But not make install. Copy the gifinter program to /usr/local/bin. Edit the /etc/mail/spamassassin/fuzzyocr.cf file. Look for the #focr_bin_gifinter line and change it to /usr/local/bin/gifinter. I use /usr/local/bin to keep manually compiled programs separate from package installed programs that are usually in /usr/bin/.

Configuration file requires version 3.004002 of SpamAssassin, but this is code version 3.004003

Was surprised this even occurred. This was simple as running as root;

#sa-update