Using mairix with Mail.app
I was reading Sam Tregar post in use.perl regarding mairix and I though: “that would be cool with Mail.app and my bazillion folders…”. At least until Spotlight gets here…
So after 15 minutes trying to understand how Mail.app stores the IMAP messages locally (it stores them in a mh folder, at least similar enough for mairix), I did a small .mairixc
, set the output as mbox into a newly created folder, and pointed mairix to a incoming IMAP folder.
Run it once without parameters to index all the stuff, and run it again with a string to query the database.
Matched 82 messages
Whoa! Already? :) Jump back into Mail.app, look at the folder created and lo and behold, they where there.
Very cool!
So, the steps you need to take (this is a beta how-to, ok? the steps will get better):
- Download and install mairix: it compiles cleanly in my Mac, but the install failed for some reason, just copy the binary to someplace in your $PATH;
- Create a
Results
folder on you Local Mac. It must be created in the Local Mac. - Use my modified
.mairixrc
and adjust the following variables:base
: the base where all your Mail.app info is stored, usually/Users/**your_short_name**/Library/Mail
;- Comment all the lines starting with
maildir
andmbox
; mh
should be the path of one of your folders in a IMAP account, something likeIMAP-**name_of_account**/INBOX/Sent.imapmbox/CachedMessages
. One way to find this out is to run this command (find ~/Library/Mail -type d -name CachedMessages
) from the terminal. You can put as many lines as you want;mfolder
should be changed to point to your results folder that you created above. If the name isResults
,mfolder
should point toMailboxes/Results.mbox/mbox
;- Remove the comment in the
mformat=mbox
line: this specifies the result folder as a mbox-style folder; - Point
database
to a place in your home directory: mine is/Users/melo/Library/Mail/mairix_database
;
- run
mairix
once. It indexes all the folders you specified in step 3; - now query the created database:
mairix some_string
- it should display the number of messages found. Jump back into Mail.app, check the Results folder and they should be in there.
Don’t forget to run mairix
from time to time to update the database. Use Cronix or edit a crontab maybe.
Next steps: I only indexed one folder as you can see from the example .mairixrc
. I need to write a small perl script to generate my .mairixrc
file with all my mailboxes, and do a AppleScript to call the mairix command with the query.