
sub sendmessage {

# Send a message to the user, via e-mail and to STDOUT.
# The message sent will be in the strings $_[1], $_[2], ...
# The prefix string is contained in $_[0].

# November 27, 2007.  Remove Nancy Copley from receiving
#	message as this is for BCO-DMO use.  Rename sendmessage.
#	Add values for $error and $warning.  rcg
# April 30, 2007. Add -c option to mail and send carbon copy to
#	Nancy Copley.  Fix spelling of problem.  Handle
#	any number of output lines.  From program sendmessage.
#	rcg
# June 25, 2003.  Change call to mail to be just mail so can export
# routine to other systems without changes.
# April 1, 2003.  On Solaris, mail is located at /usr/bin/mail
# not /bin/mail.  RCG

my ( @args, $i, $mailfile, $message0, $message1, $prefix, $who);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);

my $error = '&x';
my $warning = '#';

$prefix=$_[0];
unless (defined $prefix) {
	$prefix = "&x";
}

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
if ($year >= 100 and $year <= 1000) {$year = $year + 1900}
if ($year < 1900) { $year = $year + 2000; }
$mon++;
if ($mon < 10) { $mon = "0" . $mon; }
if ($mday < 10) {$mday = "0" . $mday; }
if ($hour < 10) { $hour = "0" . $hour; }
if ($min < 10) { $min = "0" . $min; }
if ($sec < 10) { $sec = "0" . $sec; }
undef $wday;
undef $isdst;
$mailfile="> /tmp/sendmess" . $year . $yday . $hour . $min . $sec . ".tmp";

if ( open TEMPFILE, $mailfile) {
	print TEMPFILE ("Message from $0\n");
	if ( exists $ENV{'REMOTE_HOST'} ) {$who=$ENV{'REMOTE_HOST'} ; }
	elsif (exists $ENV{'REMOTE_ADDR'} ) {$who=$ENV{'REMOTE_ADDR'} ; }
	else {$who="not available"; }
	print TEMPFILE (" Date of message: $year/$mon/$mday $hour:$min\n");
	print TEMPFILE (" From: $who\n");
	for ($i=1; $i<=$#_; $i++) {
		print TEMPFILE ($_[$i], "\n");
	}
	close TEMPFILE;
	`mail -s "Problem with $0" dmo\@whoi.edu <$mailfile`;
	unlink $mailfile;
}

for ($i=1; $i<=$#_; $i++) {
	print STDOUT ($_[$i], "\n");
}
print STDOUT ($prefix," Above message from $0\n");
print STDOUT ($prefix," Date of message: $year/$mon/$mday $hour:$min\n");

}
1;
