
# Remailing perl script, based on that of Eric Hughes

# Set this to be what you would like it to go out as.
# slocal.pl sets environment variable USERNAME from the password file.
$remail_header = "Remailed-By: remailerowner\nComplaints-To: complaints\n" ;


while (<>) {
	s/[ \t\r]*$// ;
        last if /^$/ ;
        $subject = $_ if /^Subject:/ ;
        if (/^Request-Remailing-To:/  ||  /^Anon-To:/) {
                chop ;
                s/^.*:// ;
                $addressee = $_ ;
        }
}

#open( OUTPUT, ">foo" ) || die "Cannot open 'foo'." ;
open( OUTPUT, "| /usr/lib/sendmail " . $addressee ) ;
select( OUTPUT ) ;

print "To:" . $addressee . "\n" ;
print "From: nobody\n" ;
print $subject ;
print $remail_header;

#
# check to see if there are header lines in the body to collapse 
#   into the full header.
#

if ( $_ = <> ) {
	s/[ \t\r]*$// ;
        if (/^##$/) {
                # do nothing if the pasting token appears
                # the rest of the body will be directly appended
                # this allows for extra header lines to be added
        } else {
                # normal line
                print "\n" ;
                print $_ ;
        }
} else {
        # empty body
        exit ;
}

print <>;
