#!/bin/sh
#
# $Id: sendnews,v 1.6 2008/01/15 18:10:44 dtynan Exp $
#
# Copyright (c) 2004, Kalopa Media Limited.  All rights reserved.
# Copyright (c) 2005, Kalopa Research Limited.  All rights reserved.
# This 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, or (at your
# option) any later version.
#
# It 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 product; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
# USA.
#
# THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH LIMITED "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KALOPA
# RESEARCH LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
# ABSTRACT
#
# $Log: sendnews,v $
# Revision 1.6  2008/01/15 18:10:44  dtynan
# Changed to use new company name and copyright, also fixed a few old
# files with the wrong license.
#
# Revision 1.5  2006/12/18 08:46:25  dtynan
# Fixed some minor bugs.
#
# Revision 1.4  2005/09/21 18:10:28  dtynan
# Extensive changes prior to first public release, including an
# import/export mechanism.
#
# Revision 1.3  2004/09/08 10:38:47  dtynan
# Removed debug output.
#
# Revision 1.2  2004/08/26 16:33:38  dtynan
# Send emails to appropriate list.
#
# Revision 1.1  2004/08/26 16:15:42  dtynan
# Added new shell script to send a monthly/weekly/whatever newsletter.
#
NEWSDIR=/v/beanie/newsletter

sep="----------------------------------------"

if [ $# -eq 1 ]
then
	date=$1;
else
	date=`date +%Y%M%D`
fi

for d in $NEWSDIR/*
do
	ea=`basename $d`
	if [ -f $d/news.1 ]
	then
		echo "Sending newsletter for $ea on $date"
		ofile=$d/sent/news.`$date`
		echo "" > $ofile
		if [ -f $d/HEADER ]
		then
			cat $d/HEADER >> $ofile
		fi
		for f in $d/news.? news.??
		do
			echo "" >> $ofile
			cat $f >> $ofile
			echo "" >> $ofile
			echo $sep >> $ofile
		done
		if [ -f $d/FOOTER ]
		then
			cat $d/FOOTER >> $ofile
		fi
		Mail -s "Kalopa Newsletter" $ea@kalopa.com < $ofile
		gzip $ofile
	fi
done
exit 0
