Subject: exit status problem with mail2news solved!

From: Robert Nicholson <[email-masked]>
Date: Fri, 7 Oct 1994 20:19:01 +0100

[NOTE: This is an automatically generated copy of a followup to your article]

Upon reading Randall Swartz's book (How's he doing BTW?") I discovered
that $? acts in the same way wait() works. Therefore a simple fix.

Incidently, this is not my script it's, I believe, the common
mail2news script customized for my own use.  

Now my procmail rules look like.

:0 w
* ^Subject: Daily Usenet
|formail -I Newsgroups | mail2news usenet

    :0 e:
    usenet

-------------------------------------------------------------------------------

#!/usr/local/bin/perl

($program = $0) =~ s%.*/%%;

( $version  ) = $] =~ /(\d+\.\d+).*\nPatch level/;
die "$program: requires at least version 3 of perl\n" 
        if $version < 3;

$inews = "/usr/local/news/inews"; 
$inews = "/usr/local/bin/inews" unless -x $inews;
die "$program: can't find inews\n"  unless -x $inews;
$iopts = "-h -S";

if ($#ARGV < 0) {  
    # $newsgroup = "test";
    # we'll expect the newsgroup line in the body
} elsif ($#ARGV == 0) {  
    $newsgroup = $ARGV[0];
} else {
    die "usage: $program [newsgroup]\n";
} 

# in case inews dumps core or something crazy
$SIG{'PIPE'} = "plumber";
sub plumber { die "$program: \"$inews\" died prematurely!\n"; }

open (INEWS, "| $inews $iopts") ||
    die "$program: can't run $inews\n";

# header munging loop
while (<STDIN>) {
   last if /^$/;  

   # transform real from: line back to icky style
   s/^From:\s+(.*) <(.*)>/From: $2 ($1)/;

   # transform from_ line to path header; also works locally
   s/^From\s+(\S+)@(\S+).*/Path: $2!$1/

     || s/^From\s+(\S+)[^@]*$/Path: $1\n/;

   print INEWS 
       if /^(From|Subject|Date|Path|Newsgroups|Organization|Message-ID):/i;
   $saw_subject |= ( $+ eq 'Subject' );
   $saw_newsgroup |= ( $+ eq 'Newsgroups' );
} 

warn "$program: didn't expect newsgroup in both headers and ARGV\n"
    if $newsgroup && $saw_newsgroup;

die "$program: didn't get newsgroup from either headers or ARGV\n"
    unless $newsgroup || $saw_newsgroup;

printf INEWS "Newsgroups: steffi.%s\n", $newsgroup if $newsgroup;
print  INEWS "Subject: Untitled\n" unless $saw_subject;
print  INEWS "\n";

print INEWS while <STDIN>;   # gobble rest of message

close INEWS;

exit $?>>8;	# right shift 8 bits to get the exit status.