#!/bin/sh
# $Id: do-text,v 1.1 2001/04/25 18:48:39 rbasch Exp $

. /mit/mimeutils/share/scripts/utils.sh

subtype=plain

usage() {
  echo "Usage: do-text [-s subtype] [-t content-type] <file>" 1>&2
  exit 1
}

while getopts s:t: opt; do
  case "$opt" in
    s)
      subtype=`echo "$OPTARG" | tr 'A-Z' 'a-z'`
      ;;
    t)
      subtype=`echo "$OPTARG" | awk -F/ '{ print $2; }' | tr 'A-Z' 'a-z'`
      ;;
    \?)
      usage
      ;;
  esac
done
shift `expr "$OPTIND" - 1`

if [ $# -ne 1 ]; then
  usage
fi

case "$subtype" in
  plain)
    exec cat "$1"
    ;;

  richtext)
    exec richtext "$1"
    ;;

  enriched)
    exec richtext -e "$1"
    ;;

  html)
    eval `/bin/athena/attach -Padd -b -f -q -a -h -n infoagents`
    case "$MU_HTML" in
      html)
	prompt "view HTML in a web browser"
	exec htmlview "$1"
	;;
      *)
	exec lynx -force_html -underscore -dump "$1"
	;;
    esac

    ;;
esac

echo ""
