I would like to configure the mail command with procmail in order to filter spam with CRM114 and I cannot seem to find enough information on the subject. I have set up mailx with external mail and installed procmail and crm114. I am not sure I can use procmail with mailx due to the absense of folders yet the important is to get CRM114 to work with mailx and it turns out procmail is needed. Alternately I could use sendmail, yet that might cost many days configuring and learning. I have spent last couple of weeks reading CRM manual and feel stuck because I am used to learning by examples rather than sheer theory.
1 Answer
Procmail is normally installed to process mail as it is delivered to local inboxes by your Mail Transfer Agent (MTA, i.e. like Sendmail or Postfix), not by your mail utility (Mail User Agent, like mailx).
Also, the term mailx is ambiguous: there are several implementations of mailx with varying levels of functionality. The most basic ones will require a classic Unix-style mail setup, with a local MTA and local mail inbox files in /var/mail/<username> or similar - those cannot invoke procmail and will rely on the MTA being configured to do it for you.
More fully-featured mailx implementations might support remote IMAP mailboxes and custom filtering pipelines - for those, you might not need procmail at all, and simply have your feature-rich mailx pipe the mail(s) to crm114 directly. But then, the filtering happens after you start reading mail, not when the mail arrives. You might want this, for interactively training the filter; or you might not.
If you have a remote IMAP or POP mailbox, and want specifically to use procmail, then I would suggest the following (and I think this would be the "typical way" to use it):
1.) Install a MTA (I'd recommend Postfix over Sendmail) and Procmail from your Linux distribution's packages. It's fairly likely they come pre-integrated, so you only have to supply a ~/.procmailrc to start processing incoming email with Procmail. Have the MTA accept incoming connections from localhost only (which is usually the default configuration).
2.) Set up fetchmail to get mail from your remote IMAP or POP mailbox: it will hand them over to your local MTA for delivery to your local inbox, and on the way, the MTA should have Procmail process them if you've supplied a ~/.procmailrc file.
3.) Write a ~/.procmailrc to run crm114 on the emails as they arrive.
4.) Use mailx to read your local inbox, now hopefully spam-free. Optionally add a local IMAP server, if you want your spam-filtered inbox easily accessible from multiple devices.
I want to note that crm114 seems unmaintained upstream since year 2009, so you might want to reconsider using it on new setups. Perhaps use spamassassin with its sa-learn Bayesian classifier feature instead?
Procmail used to be unmaintained since 2014, but it seems that the original author has resumed maintaining it in 2020 and made a new release in 2022.