Building notes, projects, and occasional rants

Using mairix with

I was reading Sam Tregar post in use.perl regarding mairix and I though: “that would be cool with and my bazillion folders…”. At least until Spotlight gets here…

So after 15 minutes trying to understand how 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, 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):

  1. 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;
  2. Create a Results folder on you Local Mac. It must be created in the Local Mac.
  3. Use my modified .mairixrc and adjust the following variables:
    1. base: the base where all your info is stored, usually /Users/**your_short_name**/Library/Mail;
    2. Comment all the lines starting with maildir and mbox;
    3. mh should be the path of one of your folders in a IMAP account, something like IMAP-**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;
    4. mfolder should be changed to point to your results folder that you created above. If the name is Results, mfolder should point to Mailboxes/Results.mbox/mbox;
    5. Remove the comment in the mformat=mbox line: this specifies the result folder as a mbox-style folder;
    6. Point database to a place in your home directory: mine is /Users/melo/Library/Mail/mairix_database;
  4. run mairix once. It indexes all the folders you specified in step 3;
  5. now query the created database: mairix some_string - it should display the number of messages found. Jump back into, 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.