contact

Loading enum info ...

Search mail on IMAP server

If you are like me and have all your mail on an IMAP server, you will have noticed searching is too slow. That's why this howto was written.
It will discuss setting up mairix on the server and how to create a shortcut in mutt.
It's more a quick collection of things I did to get it working in my setup.

My setup.

- mutt as mail client.
- IMAP server with virtual users
- SSH access to the IMAP server. This account also has to be able to run sudo -u

All the mail on my IMAP server is stored in /home/mail/virtual/domain.tld/user
Those folders are owned by user vmail (id 1004) because of the maildrop filtering. (This will be in some other document soon)

Mairix is an indexing and searching tool for mail stored in maildir, mh or mbox format. My setup is using maildir, because it stores every mail in it's own file. This is easier for backups and doesn't depend on locking for everything to work.

You have to start with creating a config file that can be read by the user vmail.
I choose to make a dir called .mairix in my own dir that is owned by the mairix user:

mkdir /home/michiel/.mairix

I copied the default mairixrc and altered some settings in there (path to maildir)

Next you want to setup a cronjob to run mairix with this config file and without any further parameters. That will keep the mairix index up to date.

crontab -e
@daily mairix -f /home/michiel/.mairix/mairixrc

Now comes the fun part.
I created a very small .sh script because we are going to call this from remote machines (laptops etc). You could put all the command line arguments in the ssh call, but I prefer to keep that as simple as possible. I put 1 line in a shellscript called /home/michiel/bin/mail_search.sh (on the server). The script looks like:

#!/bin/sh
sudo -u vmail mairix -f /home/michiel/.mairix/mairixrc -o /home/mail/virtual/vanbaak.info/michiel/.search $1

This will run mairix in searchmode, taking the first argument as mairix search key and create a maildir in my mailbox called search. I can access this mailbox with my client like every other mailbox. The mails you will see are actually symlinks to the real messages that match the search.

In mutt you can access this by putting the next line in your muttrc:

macro S "ssh server bin/mail_search.sh "

Now in mutt type: S searchkey and it will create/overwrite the search mailbox.

References:
Mutt homepage: http://www.mutt.org
Mairix homepage: http://www.rpcurnow.force9.co.uk/mairix/



 Feedback on this page or article:

This article has no feedback yet

 Give feedback:

To give feedback on this article, click here
Copyright (c) 2006-2008 Michiel van Baak.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU Free Documentation License".
< back | print | text | Search mail on IMAP server