Search your email!

Search your email!

One of the features that most of the pretty GUI mailers offer you is the ability to search your email. While this is not a feature I use regularly, it is one which when you need it, you really need it. I have used grepmail (was at in the past, but it slow for me (it scans the mail files every time) and the big thing for me is that is only supports mbox files, and I use maildir since I use offlineimap.

I recently found mairix. While I have not been using it long, so far I am very impressed with it. It uses an index to speed up the search process, and it smartly adds only new or changed files to the index. The first indexing run was only a few seconds on my archive of almost 15,000 mail messages. I have it scheduled to update the index every 15 minutes, and I never notice the load this will put on the system.

To integrated mairix with mutt, I wrote a quick little script to search from within (or without) mutt:

#          FILE:
#         USAGE:  ./
#   DESCRIPTION:  search mail stuff
#       OPTIONS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Don Harper (),
#       COMPANY:  Don Harper
#       VERSION:  1.0
#       CREATED:  05/25/2009 07:03:30 PM CST
#      REVISION:  ---

rm -rf $HOME/Maildir/mfolder
echo "       t::word
              Match word in the To: header.
              Match word in the Cc: header.
              Match word in the From: header.
              Match word in the Subject: header.
              Match word in the Message-ID: header.
              Match word in the message body.
              Match messages with Date: headers lying in the specific range.
              Match  messages  whose size lies in the specified range.
              Match  word  occurring  as the name of an attachment in the mes-
              sage.  Since attachment names  are  usually  long,  this  option
              Match messages with particular  flag  settings.
              s meaning seen,
              r meaning replied
              f meaning flags
              prefixed by a - to negate its sense.

       The a:: search pattern is an abbreviation for tcf:

   Match words
       The word argument to the search strings can take various forms.
              Match messages not containing the word.
              This matches if both the words are matched in the specified message part.
              This matches if either of the words are matched in the specified message part.
              Match any word containing substring as a substring
              Match any word containing substring, allowing up to N errors  in
              the  match.   For example, if N is 1, a single error is allowed,
              where an error can be
       *      a missing letter
       *      an extra letter
       *      a different letter.
              Match any word containing substring as  a  substring,  with  the
              requirement  that  substring  occurs  at  the  beginning  of the
              matched word.
              Specify both start and end explicitly
echo -n "Enter your search string: "
read string
mairix $string
mutt -f=mfolder
rm -rf $HOME/Maildir/mfolder

Then, I bound this to “S'' from within mutt:

 macro index,pager S "!mailsearch\n" 

This will give me a reminder of the search command, run the search, and then give me the search results in a new mutt session.

Don Harper Written by:

Don is a computer guy stumbling through life trying to raise his kids and take some pictures