#! /bin/sh
#
# Pine support for muttzilla.
#
# Contributed by Erik Rossen.
#


# Arguments to this script:
#   1  to
#   2  cc
#   3  bcc
#   4  subject
#   5  body file
#   6  org

MZTO=$1
MZCC=$2
MZBCC=$3
MZSUB=$4
MZBOD=$5
MZORG=$6


ARGS=""
ARGS2=""

if [ -n "$MZTO" ] ; then
    ARGS="$MZTO"
else           # Pine cannot properly handle no "TO" option
    ARGS="''"  # so we provide an empty one
fi

if [ -n "$MZSUB" ] ; then
    ARGS2="$ARGS2""Subject: $MZSUB, "
fi

if [ -n "$MZCC" ] ; then
    ARGS2="$ARGS2""Cc:$MZCC, "
fi

if [ -n "$MZBCC" ] ; then
    ARGS2="$ARGS2""Bcc:$MZBCC, "
fi

if [ -n "$MZORG" ] ; then
    ARGS2="$ARGS2""Organization: $MZORG, "
fi

# NOTE: Pine has a small problem with commas in values in the
# -customized-hdrs option since the comma is used as the delimiter
# between header settings.  Everything after (and including) the comma
# gets chopped, up to the next header label.  That's life.
if [ -n "$ARGS2" ] ; then
    ARGS="$ARGS -customized-hdrs='$ARGS2'"
fi

if [ -n "$MZBOD" ] ; then
    ARGS="$ARGS -attach $MZBOD"
fi

# NOTE: The Pine "-attach" option will attach the MZBOD file to the
# message rather than including it in the body of the message.
# Although pine allows redirection of STDIN on the command line, xterm
# (and rxvt?) seems to ignore it.  If it is REALLY necessary to
# include MZBOD in the message body, one could hack the .signature
# file path to point at the MZBOD file.  See below.  Ugly, but it
# works.
#if [ -n "$MZBOD" ] ; then
#    ARGS="$ARGS -signature-file=$MZBOD -feature-list=signature-at-bottom"
#fi

