Convert VCARDs into Mutt's alias format

The script below reads a vcard file and grabs the FN and EMAIL fields to display them into the alias format.

It's a very simple script that will not deal with wrongly formatted VCARD files. I have used it to convert roundcube's contacts export into an alias file.

$ bash convert_vcard_to_alias.sh ~/contact.vcf 

alias technews ACM TechNews technews@HQ.ACM.ORG
alias rss Contact la sauce contact@lasauceruralsoundsystem.org
...
#!/usr/bin/env bash
#set -x
IFS=$'\n'

tracer=0
nick=""
long=""
mail=""
for line in $(grep -Ev "^$|^#" "$1")
do
    verb=$(echo $line|cut -d ':' -f 1|cut -d ';' -f 1| tr -d '\r')
    case $verb in
    BEGIN)
        tracer=$((tracer + 1))
        ;;
    FN)
        long=$(echo $line|cut -d ':' -f 2| tr -d '\r')
        ;;
    EMAIL)
        mail=$(echo $line|cut -d ':' -f 2| tr -d '\r')
        nick=$(echo $mail|cut -d '@' -f 1| tr -d '\r')
        ;;
    END)
        tracer=$((tracer + 1))
        ;;
    esac

    if [ $tracer -eq 2 ]
    then
        echo "alias $nick $long $mail"
        tracer=0
        nick=""
        long=""
        mail=""
    fi
done
en/ressources/astuces/mutt_alias_vcard.txt · Last modified: 2014/08/06 15:28 (external edit)
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0