Sometimes you just wonder would other people like this?

Tuesday, 27 July 2010

Sometimes I write things that are for myself, and later decide to release on the off-chance other people might be interested.

I've hated procmail for a long time, but it is extremely flexible, and for the longest time I figured since I'd got things working the way I wanted there was little point changing.

When it comes to procmail there are few alternatives:

Unfortunately both Exim and Email::Filter suffer from a lack of "pipe" support. To be more specific Exim filters and Email::Filter allow you to pipe an incoming message to an external program - but they regard that as the end of the delivery process.

So, for example, you cannot receive a message (on STDIN), pipe it through crm114, then process that updated message. (i.e. The output of crm114).

Maildrop does allow pipes, but suffers from other problems which makes me "not like it".

My own approach is to have a simple mail-sieve command which is configured thusly:

set maildir=/home/steve/Maildir
set logfile=/home/.trash.d/mail-sieve.log

#
#  Null-senders
#
Return-Path: /<>/        save .Automated.bounces/

#
#  Spam filter
#
filter /usr/bin/crm -u /home/steve/.crm /usr/share/crm114/mailreaver.crm

#
#  Spam?
#
X-CRM114-Status: /SPAM/   save .CRM.Spam/
X-CRM114-Status: /Unsure/ save .CRM.Unsure/


#
#  People / Lists
#
From: /foo@example.com/  save .people.foo/
From: /bar@example.com/  save .people.bar/
..
..

#
#  Domains
#
To: /steve.org.uk$/               save .steve.org.uk/
To: /debian-administration.org$/  save .debian-administration.org.personal/

#
#  All done.
#
save .inbox.unfiled/

On the one hand this is simple, readable, and complete enough for myself. On the other hand if I were going to make it releasable I think I'd probably want to add both conditionals and the ability to match upon multiple header values.

Getting there would probably involve something like this on the ~/.mail-filter side :

if ( ( From: /foo@example.com ) ||
     ( From: /bar@example.com ) )
{
   save .people.example.com/
   exit
}
# ps. remind me how much I hate parsers and lexers?

That starts to look very much like Exim's filter language, at which point I think "why should I bother". Pragmatically the simplest solution would be to add a "Filter" primitive to Email::Filter - and pretend I understood the nasty "Exit" settings.

ObQuote: Andre, we don't use profanity or double negatives here at True Directions. - "But I'm a Cheerleader".

| 5 comments.

 

Comments On This Entry

[gravitar] Paul Wise

Submitted at 10:39:20 on 27 july 2010

You should take a look at notmuchmail.org, it can probably replace all of your uses of the mail-sieve save command.

[gravitar] Simon McVittie

Submitted at 10:44:54 on 27 july 2010

Are you aware of Sieve (RFC 5228), a standardized mail filtering language? As RFC'd it doesn't have any support for external programs, but its syntax is designed to be extensible (most things it does are extensions), so it should be possible to add filtering through arbitrary programs into one of its implementations. I use dovecot's implementation myself.

[gravitar] Ralf

Submitted at 11:05:22 on 27 july 2010

Maybe you want to take a look at fdm (http://fdm.sf.net). It's a alternative for both fetchmail and procmail type tools. It has a rewrite action that allows mails to be filtered through a pipe command. It allows to take mails on stdin as well, if necessary.

[author] Steve Kemp

Submitted at 11:12:46 on 27 july 2010

I test out notmuchmail every few months, but I can't quite bring myself to use it full-time just yet. So for the moment I'm using primarily using mutt.

Having said that I think I'd still want to have some kind of filtering to apply tags to incoming mail based upon sender - e.g. "friend", "work", "cron", or other similar labels.

I've seen Sieve being used in the past for a lot of things, but right now I'm not setup to use it. I ssh into my mailserver and run mutt against ~/Maildir/ - and I have only got exim4 configured to deliver mail locally. So I don't have dovecot/courier to provide me with sieve support.

[author] Steve Kemp

Submitted at 11:23:11 on 27 july 2010

fdm does look interesting - I guess I'd be using it to read from STDIN and just filing locally in my current setup.

The fact that it can work with IMAP/POP3 isn't so useful for me right now, but it might be in the future.

 

Comments are closed on posts which are more than ten days old.

Recent Posts

Recent Tags