#!/bin/bash
#
# please change SENDER to yours
#
DESC_LANG=ja
ADDR="pdesc@ddtp.debian.org"
#SENDER="your@email.address"
TYPE="application/octet-stream; name=new"
ENCODING="base64"

#
# print usage
#
print_usage () {
	cmd=`basename $0`
	cat << EOB > /dev/stderr
usage: $cmd [-G (number) [-S (section)] | -P (pkgname) ] [filename]
 $cmd -G 2          get 2 descriptions to be translated.
 $cmd -G 2 -S x11   get 2 descriptions to be translated from x11 section.
 $cmd -P pkgname    get the description of binnary package \`pkgname'
 $cmd filename      send filename
EOB
}

while getopts 'G:S:P:h' opt; do
  case $opt in
    'G') get=$OPTARG ;;
    'S') sec=$OPTARG ;;
    'P') pkg=$OPTARG ;;
    'h') print_usage; exit;;
    '?') print_usage; exit;;
  esac
done
shift `expr $OPTIND - 1`

if [ "X$get" != "X" ]; then
  if [ "X$sec" != "X" ]; then
    SUBJ="GET $get $DESC_LANG SECTION $sec noguide"
  else
    SUBJ="GET $get $DESC_LANG noguide"
  fi
elif [ "X$pkg" != "X" ]; then
  SUBJ="GET $pkg $DESC_LANG noguide"
else
  SUBJ="nothing"
fi

if [ "X$SENDER" = "X" ]; then
  echo "please modify the SENDER macro in the script"
  exit 1
fi
FROM="From: $SENDER"

if [ $# -gt 0 ]; then
  if [ -f $1 ]; then
    mime-construct --header "$FROM" --to $ADDR --cc $SENDER --subject "$SUBJ" \
      --type "text/plain" --encoding 7bit --string 'post to ddtp server' \
      --type "$TYPE" --encoding $ENCODING --file $1
#
# you can apply a pipe command to the file prior to the post, e.g.
#	 --file "nkf -e $1 |"
# (this example is for japanese ddtp guys)
#
  else
    echo "$1 does not exist" > /dev/stderr
  fi
elif [ "$SUBJ" != "nothing" ]; then
  mime-construct --header "$FROM" --to "$ADDR" --cc $SENDER --subject "$SUBJ"
else
  print_usage
fi

