#!/usr/local/bin/perl


# $Source: /sources/cvsrepos/majordomo/new-list,v $
# $Revision: 1.3.2.1 $
# $Date: 1994/06/09 19:45:12 $
# $Author: rouilj $
# $State: Exp $
#
# $Locker:  $

# set our path explicitly
$ENV{'PATH'} = "/bin:/usr/bin:/usr/ucb";

# What shall we use for temporary files?
$tmp = "/tmp/majordomo.$$";

# Read and execute the .cf file
$cf = $ENV{"MAJORDOMO_CF"} || "/etc/majordomo.cf";
if ($ARGV[0] eq "-C") {
    $cf = $ARGV[1];
    shift(@ARGV); 
    shift(@ARGV); 
}
if (! -r $cf) {
    die("$cf not readable; stopped");
}
eval(`cat $cf`)  || die 'eval of majordomo.cf failed';

chdir($homedir) || die("Can't chdir(\"$homedir\"): $!");
unshift(@INC, $homedir);
require "majordomo.pl";

&ParseMailHeader(STDIN, *hdrs);
$reply_to = &RetMailAddr(*hdrs);
$reply_to = join(", ", &ParseAddrs($reply_to));
$in_reply_to = $hdrs{"message-id"} . ", from " . $hdrs{"from"};
$list = $ARGV[0];

open(MAIL, "|-") || 
    &do_exec_sendmail(split(' ',
	   "/usr/lib/sendmail -f$list-approval -t"));

print MAIL <<"EOM";
To: $reply_to
Cc: $list-approval
From: $list-approval
Subject: Your mail to $list@$whereami
In-Reply-To: $in_reply_to
Reply-To: $list-approval@$whereami

This pre-recorded message is being sent in response to your recent
email to $list@$whereami.

If you were trying to subscribe to the list, please send your request
to $whoami, not to $list@$whereami.

This is a new list.  Your message is being returned unsent, but please
hold on to it.  After a few days, when the flood of subscription
requests has died down somewhat, the owner of the list will announce
that the list is "open for business"; you should resubmit your posting
then.  This way, everybody who joins the list within the first few days
of its existence starts out on an even footing, and we don't end up
with every other message asking "what did I miss?".

Here's your original, unsent message:

EOM

foreach ("From", "To", "Cc", "Subject", "Date", "Message-ID") {
    $tag = $_;
    tr/A-Z/a-z/;
    if (defined($hdrs{$_})) {
	print MAIL $tag, ": ", $hdrs{$_}, "\n";
    }
}

print MAIL "\n";

while (<STDIN>) {
    print MAIL $_;
}

close(MAIL);

exit 0;

sub do_exec_sendmail {
    exec(@_, "");
    die("Failed to exec mailer \"@_\": $!");
}
