#!/bin/sh

# Invoke the text client from the Mutt mail client.
#
# Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

DIRNAME=`dirname "$0"`
PROGNAME=`basename "$0"`

if [ "$1" = "--help" ] || [ ! "$1" ]; then
    cat 1>&2 <<EOF
Usage: $PROGNAME <filename> [ <options> ]

Handle the calendar data provided in the file with the given filename.
Additional options are presented to the client program to override any
configuration defaults.

Example:

$PROGNAME message.txt
EOF
    exit 1
fi

# Expect a filename for the calendar data

INFILE="$1"

if [ ! "$INFILE" ] || [ ! -e "$INFILE" ]; then
    cat 1>&2 <<EOF
Need an input file containing a calendar object.
EOF
fi

shift 1

# Invoke the client to show the incoming object details.

"$DIRNAME/imip_text_client.py" -f "$INFILE" --handle-data $@
