#!/bin/bash

# NAME
#    NewArticle
# DESCRIPTION
#    See 'skim newarticle'. Don't run this script directly.
# COPYRIGHT
#    Skim - Off-line news reading package optimized for slow lines.
#    Copyright (C) 1995  Rene W.J. Pijlman
#
#    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 2 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, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# VERSION
#    Skim version 0.6.
#    /home/rene/sys/CVS_MasterSourceRepository/skim/NewArticle,v 1.13 1995/08/14 17:06:59 rpijlman Exp

if [ "$IAmSkim" != "1" ]
then
    echo "\
You appear to be running $0 directly. Use 'skim newarticle' instead." \
1>&2
    exit 1
fi

if [ "$SKIMFROM" = "" ]
then
    echo "Environment variable SKIMFROM is not set" 1>&2
    exit 1
fi

if [ $# -eq 0 ]
then
    REPLY=""
    while [ "$REPLY" = "" ]
    do
	echo "Enter the local file name for the article file:"
	read
    done
    Article=${SKIMDIR}/Post/$REPLY

    REPLY=""
    while [ "$REPLY" = "" ]
    do
	echo "Enter a comma-separated list of newsgroups (use '\' for line continuation):"
	read
    done
    NewsGroups="$REPLY"

    REPLY=""
    while [ "$REPLY" = "" ]
    do
	echo "Enter the subject:"
	read
    done
    Subject="$REPLY"
elif [ $# -eq 3 ]
then
    if [ "$1" != "" ]
    then
        Article=${SKIMDIR}/Post/"$1"
    else
        echo "No filename" 1>&2 
        exit 1
    fi

    NewsGroups="$2"
    if [ "$NewsGroups" = "" ]
    then
        echo "No newsgroup" 1>&2 
        exit 1
    fi

    Subject="$3"
    if [ "$Subject" = "" ]
    then
        echo "No subject" 1>&2 
        exit 1
    fi
else
    echo "Usage: NewArticle [FileName NewsGroups Subject]" 1>&2
    exit 1
fi

if [ -f $Article ]
then
    echo "$Article already exists." 1>&2
    exit 1
fi

echo "From: $SKIMFROM" >>$Article

echo "Path: `hostname`" >>$Article

echo "Newsgroups: $NewsGroups" >>$Article

echo "Subject: $Subject" >>$Article

if [ "$SKIMREPLYTO" != "" ]
then
    echo "Reply-To: $SKIMREPLYTO" >>$Article
fi

if [ "$SKIMORGANIZATION" != "" ]
then
    echo "Organization: $SKIMORGANIZATION" >>$Article
fi

echo "X-Newsreader: skim version 0.6" >>$Article

# Add a blank line to separate header and body. Required by RFC-1036.
echo >>$Article

# Add a silly line, to prevent the user from ruining the syntax.
echo "Don't remove the blank line up here." >>$Article

echo >>$Article
if [ -f ~/.signature ]
then
    echo "-- " >>$Article
    cat ~/.signature >>$Article
fi

