A KDE hack: Faster mail searches in kmail, using mairix
Kmail searches slowly.
I have been a kmail user for a couple of years, since I settled in my own home office with my own computer.
I like the thing.
However, it annoys me that it takes sooooo long to find a message in my mailstore. Hey, it's only 13000 messages!
So, while I wait for KDE4 to bring all its searching goodness, I decided to see if I could hack something quickly.
Enter mairix: a mail indexer/search thing.
Convincing mairix to index all my mail was rather simple (here is my ~/.mairixrc):
base=/home/ralsina/ maildir=Mail/*... maildir=.kde/share/apps/kmail/dimap... omit=Mail/mairix database=~/.mairix_db
What does it do?
It indexes mail stored at ~/Mail and everywhere in my kmail imap folders.
It stores search results in ~/Mail/mairix and ignores its contents when searching. The results are stored as links, so they waste no disk space.
After running mairix so it builds its DB (took about a minute, which is less than most kmail searches) , you can search for things like this:
[ralsina@monty ~]$ time mairix b:bartleblog Matched 6 messages real 0m0.232s user 0m0.012s sys 0m0.204s
And the result can be seen in kmail, in the mairix folder:
However, there is a problem. It will work for the first search, but not for the second one. On the second search, you get the same content listing, but all messages appear empty.
That's because kmail saves an index file of each folder. To work around that, I wrote a little shell wrapper, kmairix:
#!/bin/sh rm ~/Mail/.mairix* -f mairix $*
And you use that instead of calling mairix directly.
But there are still improvements to be done. If your kmail is currently displaying the mairix folder, searching doesn't update the message list.
DCOP to the rescue! We can switch to the inbox, then back to mairix (adjust as needed for yourself):
dcop kmail KMailIface selectFolder /Local/inbox dcop kmail KMailIface selectFolder /Local/mairix
Missing pieces:
-
How about switching to the kmail window? Sadly, the kwin DCOP interface seems incomplete. Maybe assigning kmail a hotkey and work from there? Let me know if you have any ideas.
UPDATE as suggested by Anno Heimburg: just call kmail.
A GUI (of course!) probably with a tray icon...
A way to auto-update the Mairix DB when new mail arrives. I am thinking about doing it with incron but have not done it yet.
So, here is the final version, put it somewhere in your path, and use ALT+F2 to search your mails :-)
#!/bin/sh rm ~/Mail/.mairix* -f mairix $* dcop kmail KMailIface selectFolder /Local/inbox dcop kmail KMailIface selectFolder /Local/mairix kmail
With respect to switching to the kmail window: Why don't you simply call "kmail" in the script? As it is a KUniqueApplication, the running instance will then get the focus instead of starting a new instance.
Brilliant. Will update it as soon as I get home.
Creating simple kommander gui is a matter of 5 minutes of work. And making it hide in system tray is another 1 minute, thanks to kwin magic. I could make one if someone is interested, but I'm not sure its any better than a simple alt+f2.
I can understand if you don't want to use it as it's something of a resource hog, but Beagle will let you search Kmail, and it uses inotify to automatically update its db so there's no need to use cron as it automatically watches your mailboxes. I don't use KDE, but I just googled 'beagle kde' and found a couple of front-ends for it.
Well, I don't use beagle, either, I switched to Tracker, but I think it only indexes Evolution and Thunderbird mails, and not even local maildir's (yet).
I get a segmentatio fault as soon as I try to create the index.
Using strace, it looks like it segfaults as soon as it finds an email with a uuencoded file.
Does anyone know why?
It works great... thank you!
thanks for that tip! works great for me!
although i got the segfault too first, see here my bugreport:
http://bugs.gentoo.org/show...
this is really interesting viewpoint on the subject i might add