Re: creating a custom newsreader

Discussion in 'Perl Misc' started by $Bill, Jan 26, 2014.

  1. $Bill

    $Bill Guest

    On 1/26/2014 00:57, Cal Dershowitz wrote:
    > Howdy newsgroup,
    > I'm a little bit bored and have decided to indulge a hobby project. I have one binary group that I download: alt.binaries.humor.skewed, and it has been a great group over the years, but recently is beset by so much nauseating racism, that I can't look at it anymore. If I didn't go out of my way to disavow it tonight, the arbitrary advanced observer might notice these unwanted images coming to my machine and think that I have some sympathy for them.
    > So it is that I will either write an effective way to avoid these images, or I'll scale back to NIN and avoid the world of usenet binaries altogether. I figure they're not more clever than a well-written regex.
    > So I've started this great thing, downloaded News::NNTPClient, man'ed it a couple times, and I thought I would find a means of authentication in there that would be the analog of ftp'ing, but I haven't:

    <code here>

    > On my machine, the values in %config are all populated, so I thought I would just re-write get_ftp_object with a get_nntp_object , but I don't see the equivalent of a login method.
    > Thanks for your comment, and cheers from the great state of california.

    I stripped some code out of a working script that should help you -
    just fill in the host/user/pass/ip fields and maybe change the loop
    index to something other than 10:

    #!perl --

    use strict;
    use warnings;
    use Net::NNTP;

    my $group = 'alt.test'; # newsgroup
    my $host = ''; # server hostname
    my $user = ''; # username - null skips authorization
    my $pass = ''; # password
    my $ip = ''; # IP addr - I use this just in case DNS is down

    # create news server connection
    print "New NNTP connection to $host\n";
    my $nntp;
    if (not $nntp = Net::NNTP->new($host, Timeout => 15)) {
    warn "Cannot connect to $host: $! ($^E)";
    if (not $nntp = Net::NNTP->new($ip, Timeout => 15)) {
    die "Cannot connect to $ip: $! ($^E)";

    # login
    print "sending auth\n";
    $nntp->authinfo ($user, $pass) or die "nntp->authinfo: $! ($^E)" if $user;

    # set newsgroup
    print "Setting group\n";
    my ($cnt, $first, $last, $grp) = $nntp->group($group) or
    die "group failed: $! ($^E)";
    print "cnt=$cnt, first=$first, last=$last, grp=$grp\n";

    # start at last message
    my $msgnum = $last;
    for (my $ii = 0; $ii < 10; $ii++) {

    # get msg header
    print "get $msgnum head\n";
    my $head = $nntp->head($msgnum) or do {
    warn "nntp->head $msgnum failed: $! ($^E)";
    goto next_msg; # skip message - you could retry

    print "head has ", scalar @$head, " lines\n";

    # filter msg based on header
    # ... <your code here>

    # get msg body
    print "get $msgnum body\n";
    my $bodyref = $nntp->body($msgnum) or do {
    die "nntp->body $msgnum failed: $!\n";
    print "body has ", scalar @$bodyref, " lines\n";
    # go to prior message
    my $msgid;
    unless ($msgid = $nntp->last()) {
    print "nntp->last($ii): $!\n";
    print "last: $msgid\n";

    # get msg number for header request
    $msgnum = $nntp->message();
    chomp $msgnum;
    print "message: $msgnum\n";
    $msgnum =~ s/^\s*(\d+)\s+.*$/$1/;

    $Bill, Jan 26, 2014
    1. Advertising

  2. $Bill

    gamo Guest

    El 27/01/14 14:30, Ben Morrow escribió:
    > Quoth Cal Dershowitz <>:
    >> Q1) My simple question is this. I want to have these messages divided
    >> up into newsgroups, using the message number as a key. Given that I'm
    >> writing this in a newsgroup where we all have dabbled with this, where
    >> it is certain that I'm re-inventing the wheel if I proceed as if it
    >> hadn't been done before: what are my best choices for file architecture?

    > Are you sure you don't just want to install leafnode?
    > Ben

    I agree with Ben. Just in case you want to manage articles localy, it
    was used to store 100 articles per file. One directory per newsgroup.

    gamo, Jan 27, 2014
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. balu
    Dmitriy Lapshin [C# / .NET MVP]
    Nov 18, 2004
  2. balu
    Ben Strackany
    Nov 24, 2004
  3. balu
  4. Nemesis
    Jan 19, 2005
  5. gamo

    Re: creating a custom newsreader

    gamo, Jan 26, 2014, in forum: Perl Misc
    Feb 4, 2014

Share This Page