Sunday, February 26, 2012

Mutt and auto-complete

Hello all,
I recently switched to imap gmail + mutt to handle my emails. One thing missing is an auto-complete stuff for it. Mutt has a powerful and simple way to do that by setting up query_command in your .muttrc.

Using:
set query_command = "my_script %s" and then pressing Ctrl-T while filling an email address field, this basically calls my_script with the prefix you just enter as an argument.

Mostly and completely inspired by this thread:
http://does-not-exist.org/mail-archives/mutt-dev/msg15046.html
I wrote this quick and very dirty script that basically processes the imap cache and extract addresses from it:

Here it is:

  #!/bin/bash  
cat ~/.mutt/cache/bodies/imaps\:segovia.benjamin\@gmail.com\@imap.gmail.com\:993/INBOX/* |\
grep --regex "<$1.*@.*\?>" |\
perl -pe "s|.*<$1([^@]*?)@(.*?)>.*|$1\1@\2|g"


Small thing needed is to replace the path to the cache by your own path.

Next step would be to combine that with abook to have both an address book and a imap cache parser to get emails.

No comments: