#!/usr/local/bin/perl
#
#                 HYPERCRON - Hypermail Cron Job
#                           May 1998
#                       chall@totalsports.net
#
# Update the appropriate directory (i.e. "1998/May") with the baidarka mailbox
# and handle end-of-month processing. Let mailbox grow until the 1st day of the
# new month, then process it into last month and delete it; make a new sub-dir
# for the new month.
#
  $home = "/httpd/htdocs/baidarka";
  $mbox = "/var/spool/mail/baidarka";

  @mon = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
# Today's date.
  @now = localtime(time);
  $month = $mon[$now[4]];
  $year = $now[5] + 1900;

# At start of a new month, create new directory and 
#  send last messages to previous month.

  if (! -e "$home/$year/$month") {
     `mkdir -p "$home/$year/$month"`;
     if ($month eq "Jan") {
        $month = "Dec";
        $year--;
     } else {
        $month = $mon[$now[4]-1];
     }
     $flag = 1;
  }
   
  @lp = `/usr/local/bin/hypermail -m $mbox -d $home/$year/$month -a "/baidarka" 2>&1`;
  print "hypermail -m $mbox -d $home/$year/$month -a /baidarka\n";
  print @lp;
  
# Web Glimpse archiving.
   @lp = `/httpd/htdocs/baidarka/wgreindex -q 2>&1`;
   print "/httpd/htdocs/wgreindex -q\n";
   print @lp;

# Blank out last months accumulated mail.
  if ($flag) {
# Can't unlink because of /var/spool/mail permissions, just open and close.
     open(X,">$mbox") || die "Couldn't open $mbox: $!\n";
     close(X);
  }