Alexander Belik <alex(_at_)alex(_dot_)dc(_dot_)ukrtel(_dot_)net> writes:
I recieve mail from my provider via News2email Gateway.
But I use UUCP soft. And so my mail (mow) in my mailbox
/var/spool/mail/alex. I wont to send all mail with string
"Newsgroups:" to my local news server (INND)
...
And as you see I call mail2news:
# Begin-------------------------------------------------------
#!/usr/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/bin/inews";
# $iopts = "-h -o \"mail2news gateway\"";
$inews = "/usr/local/news/bin/rnews";
$iopts = "";
$postinghost = "news.dc.ukrtel.net";
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"; }
Suggestion #1:
Use wait() to get the staus code of the failed process so that you
can see why it died:
sub plumber {
if (wait() != -1) {
$exit = sprintf("with exitcode = %d:%0o", $? >> 8, $? & 0377);
} else {
$exit = "but wait() failed: $!";
}
die "$program: \"$inews\" died prematurely $exit!\n"
}
Consult the perlvar(1) manpage for what the two halves of $? mean.
The above prints the low byte in octal to match what the manpage
describes.
open (INEWS, "| $inews $iopts") ||
die "$program: can't run $inews\n";
Suggestion #2:
Redirect the output of the rnews command somewhere separate to see
if it's saying anything special. Also, remember that if opening a
pipe fails, then it was either the pipe() system call or the fork()
system call, _not_ the exec(). If rnews can't be exec'ed, the perl
script won't know until it either writes to the pipe (and gets a
SIGPIPE, hmmm...) or calls close(). Also, don't forget to include
the value of "$!" in error messages from failed system calls.
open (INEWS, "| $inews $iopts >/tmp/rnews.log 2>&1") ||
die "$program: can't fork: $!";
# header munging loop
while (<STDIN>) {
last if /^$/;
# transform real from: line back to icky style
s/^From:\s+(.*) <(.*)>/From: $2 ($1)/;
s/Message-Id/Message-ID/;
This should not make a difference: header names are case
insensitive. Besides, the canonical form for the Message-Id:
header has the 'd' in lowercase (only capitalize the very first
character and the first character immeadiately following each
hyphen).
...
printf INEWS "Newsgroups: %s\n", $newsgroup if $newsgroup;
It's more efficient to just interpolate the variable:
print INEWS "Newsgroups: $newsgroup\n" if $newsgroup;
# End----------------------------------------------------------
So erroo is:
procmail: Match on "^Newsgroups:"
procmail: Couldn't determine implicit lockfile from "/usr/bin/mail2news"
...
This means you either need to explicitly name a locallockfile in
the ":0" line that starts the recipe, or remove the second colon if
you don't need the locallockfile. Since multiple copies of the
above script could be running concurrently with no problems, you
should just remove the second colon.
Philip Guenther