Bogofilter and offlineimap?
Dominique Orban
dominique.orban at gmail.com
Fri Aug 28 02:34:31 CEST 2015
Hello,
I'd like to ask if anyone out there has a working setup where
bogofilter filters mail sync from an IMAP server by way of offlineimap. It
seems the web doesn't have such an example.
I'm not running a mail server. I have a simple single-user setup where several
distant IMAP accounts are synced locally with offlineimap. When offlineimap
fetches new messages, they end up in ~/Mail/Account1/INBOX/new. In my
~/.offlineimaprc, I set a post-sync hook like so
postsynchook = ~/bin/process-new-mail Account1 ~/Mail/Account1
Here, `process-new-mail` is a bash script that simply runs two functions. The
first function counts the number of new messages and displays a notification.
The second function is supposed to run bogofilter on each message (the server's
spam filter is insufficient and I don't have control over it). This is
where I'm having difficulties. The function looks like this:
check_spam() {
# Protect against paths with white space
SAVEIFS=$IFS
IFS=$(echo -en "\n\b");
new=$(find $2/INBOX/new -type f)
for f in $new
do
bogofilter -u -p -I $f -O $2/INBOX-processed/new/$(basename $f)
ham=$?
syslog -s -l error "bogofilter return value: $ham"
# Here, could filter according to value of `ham`.
done
IFS=$SAVEIFS
}
The function doesn't even separate the spam from the ham. All I'd like at first
is for bogofilter to add the `X-bogosity` field to the e-mail header.
It works when I run ~/bin/process-new-mail by hand. But not when it's run as
offlineimap's post-sync hook. The output file is never created. I tried the
alternative
cat $f | bogofilter -u -p > $2/INBOX-processed/new/$(basename $f)
but in that case the file created is 0 bytes long.
I use mutt to read messages, if that matters at all.
I thought a possible problem might be that offlineimap is multi-threaded. I've
tried to force it to be single-threaded by setting
maxsyncaccounts = 1
Offlineimap is run as a periodic system job (using launchctl, I'm on OSX) with
command-line argument `-1` (to enforce single-threadedness).
All help/hints very much appreciated!
Dominique
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: Digital signature
URL: <http://www.bogofilter.org/pipermail/bogofilter/attachments/20150827/14a722b2/attachment.sig>
More information about the bogofilter
mailing list