Using your Gmail contacts in Mutt

I really enjoy using Mutt as my email client. However, sometimes I have to log
into my Gmail account to view my contacts. Tired of this, I exported my Gmail
contacts and imported them into abook.

Now I can view my Gmail contacts in Mutt.

Here’s how I did it:

(Sorry, no cut and paste instructions.)

* Export your Gmail contacts in the vcard format

* Download the abook source and patch it with the vcard diff (available on the abook website). NOTE: you can also use the vcard2abook.pl script available in the contrib/ dir in the source.

* Import your contacts by invoking abook with the following options: ‘–convert –informat vcard –infile INPUT.vcf –outformat abook –outfile ~/.abook/addressbook’

* Configure your abook (see `man abookrc`). abook has sane defaults so your config file can be very minimal:

set www_command=elinks
set add_email_prevent_duplicates=true

* Next, configure mutt to interact with abook. I added the following lines to my muttrc
set query_command=”abook –mutt-query ‘%s'”
macro index,pager A “abook –add-email-query” “add the sender to the address book”

That’s all :). Press A while in Mutt to add a contact and Q to query the address book.

Advertisements

2 Comments

  1. Peter Shannon
    Posted 5 April, 2010 at 02:32 | Permalink | Reply

    I took a different approach, I wanted to use abook a the master address book.

    I wrote a little ksh script to process two abook address books. One is a white list, the normal abook. The other is a black list, created using abook –datafile ~/.abook/blacklist.

    I created three tags in gmail: white, black and gray (for unknown addresses) and pasted the output of this script into the filter box.

    #!/bin/ksh
    # This script is designed to print the list of people you know based on an
    # abook address book for use with gmail filters as a white list.  This way
    # the email from everybody you know can be labelled as the message arrives.
    #
    # The idea came from here:
    # http://googlesystem.blogspot.com/2006/08/create-email-blacklist-in-gmail.html
    
    
    function extract {
       typeset -l ADDRS
       exec 5$1
       while read -u5 LINE
       do
          if [[ ${LINE/email=*/EMAIL} == EMAIL ]]
          then
             EMAILS=${LINE#email=}
             SAVEDIFS=$IFS
             IFS=,
             for EMAIL in ${EMAILS}
             do
                ADDRS[${#ADDRS[*]}]=${EMAIL#email=}
             done
             IFS=$SAVEDIFS
          fi
       done
       typeset -i IDX=0
       typeset -i ADDR_SIZE=${#ADDRS[*]}
       while [[ IDX -lt $ADDR_SIZE ]]
       do
          if [[ $IDX -eq 0 ]]
          then
             print -n "${ADDRS[$IDX]}"
          else
             print -n " OR ${ADDRS[$IDX]}"
          fi
          (( IDX=IDX + 1 ))
       done
    }
    
    if [[ $1 == '-b' ]]
    then
       # blacklisted filter
       BOOK=~/.abook/blacklist
       extract $BOOK
       print
    elif [[ $1 == '-g' ]]
    then
       # grey-listed filter
       BOOK=~/.abook/blacklist
       print -nR "-("
       extract $BOOK
       print -n ")"
       BOOK=~/.abook/addressbook
       print -n " -("
       extract $BOOK
       print ")"
    else
       # white-listed filter
       BOOK=~/.abook/addressbook
       extract $BOOK
       print -R " -me"
    fi
    
  2. Michal Zuber
    Posted 25 May, 2013 at 02:27 | Permalink | Reply

    If you get the following error “abook: unrecognized arguments on command line” try rewriting the code instead of copy/paste, had issue with the dashes :/

    abook –convert –informat csv –infile /Users/mike/Downloads/gmail_contacts.csv –outformat abook –outfile /Users/mike/.abook/addressbook

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: