User Tools

Site Tools


en:ressources:astuces:mutt_alias_vcard

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: 2024/04/17 10:19 by 127.0.0.1