U
usr12
The script below can be used to grab binary files (images) from a newsgroup.
#!/usr/bin/perl -w
#####################################################################
# #
# Name: nnbot #
# Version: 2.0.4 #
# Date: Feb 15, 2003 #
# #
# This script will retrieve all messages in a specified set of #
# news groups and uudecode their contents, saving the results #
# in a local file. This can be handy for automatically downloading #
# such things as image files. #
# #
# A file called .nnbotrc is needed in the User's ~/etc directory #
# to list the news groups to process and the associated directory #
# that will be used to stored the uudecoded files. As nnbot #
# processes each message, the .nnbotrc file is updated with the #
# last article number that was processed. The extra overhead in #
# saving this file is gained by being able to stop this script as #
# needed and not having to reprocess messages on a restart. #
# #
# The default news server is "news" and can be overridden on the #
# command line. #
# #
# This script requires #
# #
# At startup, this nnbot looks for the .nnbotrc in the user's #
# ~/etc directory. The layout of this file contains the following #
# fields: #
# #
# 1. News group name #
# 2. Directory to save uudecoded files #
# 3. Starting article number (can default to 0) #
# #
# example: #
# alt.group.1,/home/sampleuser/tmp,0 #
# alt.group.2,/home/sampleuser/tmp,0 #
# #
#####################################################################
require 5.001;
use use Shell qw(rm uudecode);
#####################################################################
# #
# read .nnbotrc #
# #
#####################################################################
$news_server = "netnews.comcast.net";
if ($ARGV[0]) {
$news_server = $ARGV[0];
}
$rcfile = $ENV{HOME} . "/etc/.nnbotrc";
$i = 0;
# Read the Groups from the rc file
open(RCFILE, $rcfile) or die $rcfile." file not found...";
while(<RCFILE>){
chomp($_);
($group_name[$i], $base_dir[$i], $first_article[$i]) = split(/\,/, $_);
$i++;
}
close(RCFILE);
# Process each one
$i = 0;
foreach $group_name (@group_name) {
if ($group_name ne "") {
$base_dir[$i] =~ s/~/$ENV{HOME}/;
chdir $base_dir[$i] or die "Can't chdir to ".$base_dir[$i];
get_group($group_name, $base_dir[$i], $first_article[$i], $rcfile);
}
$i++;
}
#####################################################################
# #
# all done #
# #
#####################################################################
1;
#####################################################################
# #
# get_group #
# #
#####################################################################
sub get_group {
$group_name = $_[0];
$base_directory = $_[1];
$last_read = $_[2];
$rcfile = $_[3];
$connect = new ($first, $last) = ($connect->group($group_name));
$last_read++;
if ($last_read > $first) {
$first = $last_read;
}
for (; $first <= $last; $first++) {
$message_status = $connect->stat($first);
if ($message_status ne "") {
$filename = $base_directory . "/" . $first . ".uu";
open(UUFILE, ">$filename")
or die "UU file error" . $filename;
print UUFILE $connect->body($first);
close(UUFILE);
#decode and delete it
uudecode($filename);
rm($filename);
#update .nnbotrc to reflect the processed message
update_rc($group_name, $first)
}
}
}
#####################################################################
# #
# update .nnbotrc #
# #
#####################################################################
sub update_rc {
$rcfile = $ENV{HOME} . "/etc/.nnbotrc";
$update_name = $_[0];
$update_article = $_[1];
$j = 0;
$k = 0;
# Read the Groups from the rc file
open(OLDRC, $rcfile) or die $rcfile." file not found during update...";
while(<OLDRC>){
chomp($_);
($rc_name[$j], $rc_dir[$j], $rc_article[$j]) = split(/\,/, $_);
$j++;
}
close(OLDRC);
open(NEWRC, ">$rcfile") or die $rcfile." can't be created during update";
foreach $rc_name (@rc_name) {
if ($rc_name eq $update_name) {
$rc_article[$k] = $update_article;
}
print NEWRC ("$rc_name,$rc_dir[$k],$rc_article[$k]\n");
$k++;
}
close(NEWRC);
}
#!/usr/bin/perl -w
#####################################################################
# #
# Name: nnbot #
# Version: 2.0.4 #
# Date: Feb 15, 2003 #
# #
# This script will retrieve all messages in a specified set of #
# news groups and uudecode their contents, saving the results #
# in a local file. This can be handy for automatically downloading #
# such things as image files. #
# #
# A file called .nnbotrc is needed in the User's ~/etc directory #
# to list the news groups to process and the associated directory #
# that will be used to stored the uudecoded files. As nnbot #
# processes each message, the .nnbotrc file is updated with the #
# last article number that was processed. The extra overhead in #
# saving this file is gained by being able to stop this script as #
# needed and not having to reprocess messages on a restart. #
# #
# The default news server is "news" and can be overridden on the #
# command line. #
# #
# This script requires #
# #
# At startup, this nnbot looks for the .nnbotrc in the user's #
# ~/etc directory. The layout of this file contains the following #
# fields: #
# #
# 1. News group name #
# 2. Directory to save uudecoded files #
# 3. Starting article number (can default to 0) #
# #
# example: #
# alt.group.1,/home/sampleuser/tmp,0 #
# alt.group.2,/home/sampleuser/tmp,0 #
# #
#####################################################################
require 5.001;
use use Shell qw(rm uudecode);
#####################################################################
# #
# read .nnbotrc #
# #
#####################################################################
$news_server = "netnews.comcast.net";
if ($ARGV[0]) {
$news_server = $ARGV[0];
}
$rcfile = $ENV{HOME} . "/etc/.nnbotrc";
$i = 0;
# Read the Groups from the rc file
open(RCFILE, $rcfile) or die $rcfile." file not found...";
while(<RCFILE>){
chomp($_);
($group_name[$i], $base_dir[$i], $first_article[$i]) = split(/\,/, $_);
$i++;
}
close(RCFILE);
# Process each one
$i = 0;
foreach $group_name (@group_name) {
if ($group_name ne "") {
$base_dir[$i] =~ s/~/$ENV{HOME}/;
chdir $base_dir[$i] or die "Can't chdir to ".$base_dir[$i];
get_group($group_name, $base_dir[$i], $first_article[$i], $rcfile);
}
$i++;
}
#####################################################################
# #
# all done #
# #
#####################################################################
1;
#####################################################################
# #
# get_group #
# #
#####################################################################
sub get_group {
$group_name = $_[0];
$base_directory = $_[1];
$last_read = $_[2];
$rcfile = $_[3];
$connect = new ($first, $last) = ($connect->group($group_name));
$last_read++;
if ($last_read > $first) {
$first = $last_read;
}
for (; $first <= $last; $first++) {
$message_status = $connect->stat($first);
if ($message_status ne "") {
$filename = $base_directory . "/" . $first . ".uu";
open(UUFILE, ">$filename")
or die "UU file error" . $filename;
print UUFILE $connect->body($first);
close(UUFILE);
#decode and delete it
uudecode($filename);
rm($filename);
#update .nnbotrc to reflect the processed message
update_rc($group_name, $first)
}
}
}
#####################################################################
# #
# update .nnbotrc #
# #
#####################################################################
sub update_rc {
$rcfile = $ENV{HOME} . "/etc/.nnbotrc";
$update_name = $_[0];
$update_article = $_[1];
$j = 0;
$k = 0;
# Read the Groups from the rc file
open(OLDRC, $rcfile) or die $rcfile." file not found during update...";
while(<OLDRC>){
chomp($_);
($rc_name[$j], $rc_dir[$j], $rc_article[$j]) = split(/\,/, $_);
$j++;
}
close(OLDRC);
open(NEWRC, ">$rcfile") or die $rcfile." can't be created during update";
foreach $rc_name (@rc_name) {
if ($rc_name eq $update_name) {
$rc_article[$k] = $update_article;
}
print NEWRC ("$rc_name,$rc_dir[$k],$rc_article[$k]\n");
$k++;
}
close(NEWRC);
}