C
Camelback Jones
Steve said:What part of "a line with a space in it is not a blank line" is so hard to
grasp?
Probably the same part of "it depends on context" that you don't grasp.
Besides, once I got it to work ( see below ) it appears that in fact it IS
a blank line (either that, or datasend() is smart enough or dumb enough to
strip the leading spaces before sending it...).
Sheesh!
Now a cursory search on Google turned up this page:
http://freebooks.by.ru/view/RedHatLinux6Unleashed/rhl6u320.htm
and this sample (which I take no credit/blame for):
LISTING 31.8 Posting an Article to Usenet
#!/usr/bin/perl
open (POST, "post.file");
@post = <POST>;
close POST;
use Net::NNTP;
$NNTPhost = 'news';
$nntp = Net::NNTP->new($NNTPhost)
or die "Cannot contact $NNTPhost: $!";
# $nntp->debug(1);
$nntp->post()
or die "Could not post article: $!";
$nntp->datasend("Newsgroups: news.announce\n");
$nntp->datasend("Subject: FAQ - Frequently Asked Questions\n");
$nntp->datasend("From: ADMIN <root\@rcbowen.com>\n");
$nntp->datasend("\n\n");
for (@post) {
$nntp->datasend($_);
} # End for
$nntp->quit;
*NOTE* the double new lines with no space between separating
the header and the body.
NOTED! But not necessary. I tried it with these two, then with one (as
well as with eight), and all worked. It just threw the excess lines into
the body.
The above is not production quality, IMHO, as it is not
scoped, does not use warnings nor strict,
nor is it error trapped properly.
Bt it should get the point across....
My reading of RFC 1036 seems to indicate that the required header lines for
date, message-id, and path are missing, so I'm a bit puzzled as to why it
works... but it does, and I don't really care about those one way or the
other, as long as the host adds them (which it apparently does).
Now, here's the part that's really bothering me: I dredged up an example
my @Message = ( "Newsgroups: alt.test\015\012",
"From: nospam\@some-domain.tld\015\012",
"Reply-To: trash\@some-domain.tld\015\012",
"Subject: Teste Net::NNTP\015\012",
"Organisation: Someone\015\012",
"Content-Type: text/plain; charset=ISO-8859-1\015\012",
"Content-Transfer-Encoding: 8bit\015\012",
"X-No-Archive: yes\015\012",
"\015\012", # Leerzeile zwischen Header und Body
"Erste Zeile\015\012",
"Zweite Zeile\015\012"
);
# Das Gefuckel mit \015\012 lässt sich meist in einem Rutsch erledigen
# @message = map { "$_" . "\015\012" } (0..$#message);
my $OK = $server->post(\@Message);
Which seems to be not drastically different from what I was trying to do...
and it DOESN'T WORK (even when I added multiple CR/LF's on the "blank"
line). It finally dawned on me that Net::NNTP has a debug() method, so I
turned it on, and it says, guess what...
441 - Article has no body, just headers.
Huh? The output from debug, right up to that point, looks absolutely the
same as the output from the datasend() example you found, as far as I can
see, and if we change these lines to datasend() calls, it seems to work
just fine.
Boy, I dunno... I'm going to do what I was planning to do but
using the straight datasend() calls, but I still want to know why the
post([@message]) form doesn't work...
And, you know what? All the blather about what constitutes a "blank" line
didn't have diddley-squat to do with it, because I tried every combination
of them I could think of, including the CR/LF that turned out to work...
The only reason I put spaces in was to see if it for some reason just HAD
to have at least one character on the line to declare it a "line" (hey, you
never know until you try... ).
and
either NNTP doesn't effing care about the space, or datasend() strips it,
because I changed
$nntp->datasend("\n\n");
to
$nntp->datasend(" \n");
just for the hell of it... and... IT... WORKS.
So there. ;p
Thanks for the example - I was so intent on finding out why post() wasn't
working that I blew off other datasend() examples several times, looking
for a workiong post() one.
So... we still don't know why post() doesn't work, but at least we have
code that DOES work!
Thanks again!