#!/bin/sh
# Rewrites RFC2368-style URI's to mutt command-line format
# bruno@postle.net 20-feb-2000

URI=`echo $1 | tr '%20' ' '`

TO=`echo $URI | egrep '^<?mailto:[^@\?&]+@[^@]+' | sed 's;^[^:]*:\([^\?]*\).*;\1;'`

CC=`echo $URI | egrep '[\?&]cc=[^@\?&]+@[^@]+' | sed 's;^.*[\?&]cc=\([^&>]*\).*$;\1;'`

SUBJECT=`echo $URI | egrep '[\?&]subject=[^&]' | sed 's;^.*[\?&]subject=\([^&>]*\).*$;\1;'`

ARGS=""

if [ -n "$TO" ] ; then
       ARGS="$ARGS '$TO'"
fi

if [ -n "$CC" ] ; then
       ARGS="$ARGS -c '$CC'"
fi

if [ -n "$SUBJECT" ] ; then
       ARGS="$ARGS -s '$SUBJECT'"
fi

eval "mutt $ARGS"