
# 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.
# Tier remailer -- send only to a remailer. No complaints

# $remail_header = "Remailed-By: remailerowner\nComplaints-To: complaints\n" ;
$newmailer = "SETREMAILERHERE";

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

# Choose the remailer to send to from the list
#open( OUTPUT, ">foo" ) || die "Cannot open 'foo'." ;
open( OUTPUT, "| /usr/lib/sendmail " . $newmailer ) ;
select( OUTPUT ) ;

print "To: $newmailer\n" ;
print "From: nobody\n" ;
print "Anon-To: $addressee\n";
print $subject ;

#
# 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 <>;
