Re: [Hampshire] Mail filtering on remote IMAP server

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Mail filtering on remote IMAP server

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x582af100.hantslug.org.uk.1960': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Wed Aug 5 11:50:54 2009 BST
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Wed, Jul 22, 2009 at 11:26:57AM +0100, Hugo Mills wrote:
> On Wed, Jul 22, 2009 at 11:16:11AM +0100, Michael-John Turner wrote:
> > On Wed, Jul 22, 2009 at 10:12:04AM +0100, Hugo Mills wrote:
> > >    The *only* access I have to my mail and the system it runs on is
> > > through IMAP. (This is an Exchange-based system, and the exchange
> > > filtering requires me to run IE merely to configure it, and it's
> > > utterly pointless anyway, as it only allows filters on about two
> > > header fields anyway).

> >
> > Have you tried IMAPFilter[1]? It should be able to do what you want,
> > although I'm not sure if the limitations of Exchange's IMAP implementation
> > will cause you problems.
> >
> > I'm also not sure how much of the processing is done server-side - I have a
> > feeling that when content-based filtering is done the message is
> > downloaded, rules applied and then the appropriate server-side activities
> > performed. Without Exchange supporting Sieve, that's probably the best
> > you're going to be able to do, unfortunately.
>
>    Thanks, that looks like exactly the sort of thing I'm after. I was
> expecting the limitations you mention. I don't tend to do content
> filtering anyway, but not being able to filter on List-Id: headers is
> truly painful, for the way that I like to work with my mail.


Just to follow this up, I've now implemented mail filtering on my
work account using imapfilter. I've effectively got two different
inboxes now: the "official" one (INBOX) which receives the mail from
the mail server, and mine (Incoming), which is what I point my mail
client at. I also tell my mail client to check a number of other
mailboxes, which are the ones that mail is filtered into.

The imapfilter config I'm using looks something like this:

---------------
-- Options --
---------------

options.timeout = 120
options.subscribe = true

----------------
-- Accounts --
----------------

-- Connects to "imap1.mail.server", as user "user1" with "secret1" as
-- password.
account1 = IMAP {
    server = 'imap.reading.ac.uk',
    username = 'username',
    password = 'password',
    ssl = 'tls1',
}


------------------------
-- Mailing list rules --
------------------------

-- AMG Discussion group
result = account1.INBOX:contain_field('List-Id', 'acet-middleware-grp.lists.reading.ac.uk')
account1.INBOX:move_messages(account1['amg-discuss'], result)

-- SSE admin groups
result = account1.INBOX:match_field('List-Id', 'sse-.*\.lists\.rdg\.ac\.uk') +
                account1.INBOX:match_field('List-Id', 'sse-.*\.lists\.reading\.ac\.uk')
account1.INBOX:move_messages(account1['sse'], result)


-- SCR membership
result = account1.INBOX:contain_field('Sender', 'scr-member-bounces@???')

-- IT Research Liaison
result = account1.INBOX:contain_field('X-LSV-ListId', 'IT-RESEARCH-LIAISON')
account1.INBOX:move_messages(account1['it-research-liaison'], result)

-- Digital Narratives
result = account1.INBOX:contain_field('List-Id', 'digital-narrative.googlegroups.com')
account1.INBOX:move_messages(account1['dig-narrative'], result)

-- Wireshark
result = account1.INBOX:contain_field('List-Id', 'wireshark-dev.wireshark.org')
del = account1.INBOX:contain_subject('buildbot failure')
account1.INBOX:delete_messages(result * del)
account1.INBOX:move_messages(account1['wireshark'], result - del)

-- Move everything else into Incoming
result = account1.INBOX:select_all()
account1.INBOX:move_messages(account1['Incoming'], result)

Finally, I've got the filter running every three minutes using a
cron job from my desktop, although it could actually run from anywhere
in the world with net access.

Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
     --- The Tao that is seen / Is not the true Tao, until / You ---     
                           bring fresh toner.