#!/bin/csh -f

#@(#)Collect and pack mail v. 5.0 Oct 1994 josdb@xs4all.nl (Jos den Bekker)

set workdir=/tmp/mail.$$
set polldir=~/poll
set date=`date +%d%m`
set nonomatch

if ( -d $workdir ) then
	echo ""
  echo "         ERROR! Working-directory $workdir already exists."
  echo ""
  exit 1
else
  mkdir $workdir
  if ( $status != 0 ) then
    echo ""
    echo "         ERROR! Unable to create Working-directory $workdir"
    echo ""
    exit 1
  endif
endif

( echo 's1-$' $workdir/$user ; echo q ) | /usr/ucb/mail >/dev/null
if ( $status != 0 ) then
  rm -rf $workdir
  exit 1
endif

if ( -e $polldir/mail*.zip.* ) rm $polldir/mail*.zip.*

if ( -e $polldir/mail$date.zip ) mv $polldir/mail$date.zip $polldir/mail$date.zip.$$

zip -mjbq /tmp $polldir/mail$date $workdir/$user
if ( $status != 0) then
  echo ""
  echo "    An error occurred while zipping the mail file."
  echo "    Hopefully it is still in $workdir
  echo ""
  exit 1
endif

rm -rf $workdir

#sz $polldir/mail$date.zip
#if ( $status != 0 ) then
#  exit 1
#else
#  mv $polldir/mail$date.zip $polldir/mail$date.zip.$$
#endif

#if ( -e $polldir/news$date.zip ) then
#	sz $polldir/news$date.zip
#	if ( $status != 0 ) then
#	  exit 1
#	else
#	  mv $polldir/news$date.zip $polldir/news$date.zip.$$
#	endif
#else
#	echo ""
#	echo "     No news file to upload."
#	echo ""
#endif
