#!/usr/bin/perl
#	testmail recipient ...
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# This program generates a simple test message and  fires  it  off  to  the #
# recipient(s); the idea is to simplify testing mail paths.  If any options #
# starting with '-' are used, then we will pass them onto smail.  You can't #
# pass  positional params to smail this way at present.  Note that we add a #
# "X-Orig-Addr" header as an attempt to record the address in  a  way  that #
# won't be mangled by mailers.                                              #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#
# Copyright (c) 1992 by John Chambers ...{bu.edu,harvard,mit-eddie}minya.uucp!jc
#
$V = $ENV{"D_testmail"} || $ENV{"V_testmail"} || 0;
$O = '';
$U = $ENV{"USER"} || $ENV{"LOGNAME"} || "postmaster";
$H = $ENV{"HOSTNAME"} || `hostname` || `uuname -l` || `uname -n`;
$H =~ s/\s*$//;
$P = 'smail -v';

for $r (@ARGV) {
	if ($r =~ /^-/){
		$O = "$O $r";
	} else {
		print "To: $r\n" if $V;
		open(M,"| $P $O $r") || die "Can't invoke \"$P\" [$!]\n";
		($sec,$min,$hour,$mday,$mon,$year) = gmtime(time);
		$D = sprintf("%04d/%02d/%02d %02d:%02d:%02d UT",
			1900+$year,1+$mon,$mday,$hour,$min,$sec);
#		print M "From $H!$U\n";
		print M "From: $U@$H\n";
		print M "To: $r\n";
		print M "Subject: Test message\n";
		print M "To: $r\n";
		print M "X-Orig-Addr: $r\n";
		print M " \n";
		print M "This is a test message, sent $D\n";
		print M "  from \"$H!$U\"\n";
		print M "    to \"$r\"\n";
		print M " \n";
		close(M);
		wait;
	}
}
