[imapfilter-devel] Imapfilter and Pipe commands

Cedric Pradalier cedric.pradalier at inrialpes.fr
Thu Apr 1 23:37:37 EEST 2004


Hi all,

	I just started to use imapfilter after using offlineimap. And this seems to
	be exactly the good tool for what I want to do. I first explain my setup
	and I'll come back on pipes later on

	First my setup. I have a always up computer at work with a very big
	connection and a laptop at home with a standard DSL connection and
	sometimes a 56k modem... As anybody I receive spams and I wanted not only
	to indentify them, but also to move them apart, in order to avoid
	downloading them while I'm using a slow connection. To this end, I set up
	imapfilter on my work machine (in a cron job since I was not totally
	convinced by the daemon mode...). Some of my spams are detected by a
	whole site spamassasin, and flagged with a [_SPAM_] in the subject. So no
	problem to move them. 

	To identify other spams, I use spamprobe (a quite efficient bayesian
	filter) and also clamav to check for viruses. So I had to implement the
	external command, in a very similar way (that's coincidence) to what has
	been proposed on this list  :

	filter spam2 and
		unseen
		external all "isspam.sh"
	action move Spam subject,from

	I choose to use only one external command (last one in the filter) which
	can select header,body or all. And if I have complex things to do, I do
	it in the shell script. This seems reasonable since this is not imapfilter
	goals to manage all the complexity I can imagine. isspam.sh looks like
	this : 
	
	#!/bin/sh
	TEMP=`mktemp /tmp/$USER.XXXXXX`
	cat > $TEMP
	if spamprobe -d train $TEMP 2>&1 | grep SPAM >
	then
		rm -f $TEMP
		exit 0; 
	fi  

	if ! clamscan --mbox --stdout --disable-summary -i $TEMP 
	then
		rm -f $TEMP
		exit 0
	fi
	rm -f $TEMP
	exit 1 

	Also, in order to correct misclassification in spamprobe, I have to be
	able to make it read misclassified emails. So to make short, I added a
	pipe action, which permits to pipe selected messages to an external
	program, without taking care of its exit status :

	filter learnspam
		not deleted
	action pipe "learn.sh spam" subject

	
	So this is implemented and currently running. I can extract a patch (w.r.t
	0.9.6) if someone is interested in testing it. I've browsed the archive
	and not found explicit implementation of this, so I propose mine. 
	
	I hope you will not consider this long email a pollution...

-- 
Cedric

"[Of course] I'm French! Why do think I have this outrageous 
accent, you silly king-a?!"  Monty Python and the Holy Grail




More information about the Imapfilter-devel mailing list