[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] get-news.plx



This is a fun script I wrote today.  Many newsreaders do not allow you to
search the contents of posts in a group.  This perl script will take two
arguments (a search term and a group) and search for bodies matching the
search term (case-insensitively).  Once it gets all the messages that
match, it opens each in your newsreader (assuming the newsreader recognizes
IC and URLs in the form news:msg-id).

And of course, Mac::Apps::PBar is used to show progress, as this can take a
loooong time for large newsgroups.

#!perl -l
# get_news.plx by pudge@pobox.com
use strict;
use Net::NNTP;
use Mac::Apps::PBar;
use Mac::InternetConfig;
my($nntp, $msg, @msgs, $srch, $grp, @grp, $pbar, $cnt, $ic);

$srch = MacPerl::Ask('Search Term?') or die "Need search term.\n";
$grp  = MacPerl::Ask('Newsgroup?') or die "Need newsgroup.\n";

$nntp = Net::NNTP->new() or die "Cannot connect: $!\n";
        # assuming IC is configured

@grp = $nntp->group($grp);

$pbar = Mac::Apps::PBar->new('Usenet search', '100,50');
$pbar->data({
  Cap1=>"Searching for $srch",
  Cap2=>"in $grp",
  MinV=>0,
  MaxV=>$grp[0],
});

while ($msg = $nntp->next()) {
  push(@msgs, $msg) if (grep(/\Q$srch\E/i, @{$nntp->body($msg)}));
  $pbar->data({Valu=>$cnt}) if (++$cnt =~ /[16]$/);
}
$pbar->data({Valu=>$grp[0]});

if (@msgs) {
  $ic = ICStart();
  ICGeneralFindConfigFile($ic);
  foreach $msg (@msgs) {
    $msg =~ s/^<(.*)>$/$1/;
    ICLaunchURL($ic, 0, "news:$msg");
    print "news:$msg";
  }
  $pbar->close_window();
  undef $pbar;
  ICStop($ic);
} else {
  MacPerl::Answer("No messages matching $srch found in $grp.");
}

END {$pbar->close_window() if $pbar}

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch