#!/usr/local/bin/perl
# $Header: /staff/test/bin/RCS/mail2news.pl,v 1.4 1994/01/11 19:50:02 dimitri Exp $
# copies a mail message on stdin to the newsgroup in the first argument
# $Log: mail2news.pl,v $
# Revision 1.4  1994/01/11  19:50:02  dimitri
# taintperl reassuring
#
# Revision 1.3  1994/01/09  20:55:08  dimitri
# %-tekens verwijderd
#
# Revision 1.2  1994/01/09  20:53:50  dimitri
# Nieuwe versie
#
# Revision 1.1  1993/12/07  10:52:30  dimitri
# Initial revision
#

# reassuring taintperl
$ENV{'PATH'}='/bin:/usr/bin';
$ENV{'SHELL'}='/bin/sh' if $ENV{'SHELL'} ne '';
$ENV{'IFS'}= '' if $ENV{'IFS'} ne '';

# setting up the host for correction of local mails
$host = "dutiws";

# check for argument
if ($#ARGV == -1) {print STDERR "Usage: mail2news newsgroup\n"; exit;}
$newsgroup = $ARGV[0];

$beforesubject = 1;	# we haven't seen the subject

while (<STDIN>)
{
	if ($beforesubject)
	{
		if (/^From: (.*)/)
	   {
		  $from = $1;
			if ($from !~ /@/) 	# local mail
			{
				$from =~ /(.*)( \(.*\))/;	# parse the parens out
				$from = $1 . "@" . $host . $2; # add the hostname 
			}	
		}
		elsif (/^Subject: (.*)/)
		{
			$subject = $1;
			$beforesubject = 0;	# Now, we can post the mail.
			open(NEWS,"|/usr/lib/news/inews -n $newsgroup -f '$from' -t '$subject'");
			# open(NEWS,">NEWSFILE");
			# print NEWS "from = ", $from, "\n";
			# print NEWS "sub = ", $subject, "\n";
		}
	}
	else
	{
		if (!/X-.*/) {print NEWS $_;}
	}
}
