dslinux/user/perl/lib/Net/demos ftp inetd nntp nntp.mirror pop3 smtp.self time

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 18:00:53 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/lib/Net/demos
In directory antilope:/tmp/cvs-serv17422/lib/Net/demos

Added Files:
	ftp inetd nntp nntp.mirror pop3 smtp.self time 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: ftp ---
#!/usr/local/bin/perl

use blib;
use Net::FTP;
use Getopt::Long;

$opt_debug = undef;
$opt_firewall = undef;

GetOptions(qw(debug firewall=s));

@firewall = defined $opt_firewall ? (Firewall => $opt_firewall) : ();

foreach $host (@ARGV)
 {
  $ftp = Net::FTP->new($host, @firewall, Debug => $opt_debug ? 1 : 0);
  $ftp->login();
  print $ftp->pwd,"\n";
  $ftp->quit;
 }


--- NEW FILE: smtp.self ---
#!/usr/local/bin/perl -w

use blib;
use Net::SMTP;
use Getopt::Long;

=head1 NAME

    smtp.self - mail a message via smtp

=head1 DESCRIPTION

C<smtp.self> will attempt to send a message to a given user

=head1 OPTIONS

=over 4

=item -debug

Enabe the output of dubug information

=item -help

Display this help text and quit

=item -user USERNAME

Send the message to C<USERNAME>

=head1 EXAMPLE

    demos/smtp.self  -user foo.bar

    demos/smtp.self -debug -user Graham.Barr

=back

=cut

$opt_debug = undef;
$opt_user = undef;
$opt_help = undef;
GetOptions(qw(debug user=s help));

exec("pod2text $0")
    if defined $opt_help;

Net::SMTP->debug(1) if $opt_debug;

$smtp = Net::SMTP->new("mailhost");

$user = $opt_user || $ENV{USER} || $ENV{LOGNAME};

$smtp->mail($user) && $smtp->to($user);
$smtp->reset;

if($smtp->mail($user) && $smtp->to($user))
 {
  $smtp->data();

  map { s/-USER-/$user/g } @data=<DATA>;

  $smtp->datasend(@data);
  $smtp->dataend;
 }
else
 {
  warn $smtp->message;
 }

$smtp->quit;

__DATA__
To: <-USER->
Subject: A test message

The message was sent directly via SMTP using Net::SMTP
.
The message was sent directly via SMTP using Net::SMTP

--- NEW FILE: nntp.mirror ---
#!/usr/bin/perl5

### Subject: Re: Fuller example of Net::NNTP?
### Date:  Tue, 4 Feb 1997 10:37:58 -0800
### From: "Paul E. Hoffman" <phoffman at imc.org>
### To: Graham Barr <gbarr at ti.com>
### 
### Thanks for your reply. After looking at the examples, I realized that
### you're not doing what I want, which is to store the messages on the local
### hard disk with the same message number as what was on the remote. So, I
### rolled my own program, although I haven't finished it yet (I have a hook
### for expiring, but haven't done it yet).
### 
### You are welcome to use this in the Net:: distribution if you think it is
### useful.
###
### NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
###
### This script is included as-is, I give no guarantee that it will
### work on every system
###

use Net::NNTP;

$BaseDir = '/usr/usenet';
chdir($BaseDir) or die "Could not cd to $BaseDir\n";

# Format of grouplist is:
#    groupname<tab>expirationdays
# expirationdays is the number of days to leave the articles around;
#    set it to 0 if you want the articles to stay forever
# If the groupname starts with a #, it is skipped
open(GROUPLIST, 'grouplist.txt') or die "Could not open grouplist.txt\n";
while(<GROUPLIST>) {
        $Line = $_; chomp($Line);
        if($Line eq '') { next };  # Skip blank lines
        if(substr($Line, 0, 1) eq '#') { next };  # Skip comments
        push(@Groups, $Line)
}

$NntpPtr = Net::NNTP->new('news.server.com');

foreach $GroupLine (@Groups) {
        ($GroupName, $GroupExp) = split(/\s/, $GroupLine, 2);
        # Process the expiration first (still to be done...)

        # See if this is a new group
        unless(-e "$BaseDir/$GroupName") {
                unless(mkdir("$BaseDir/$GroupName", 0755))
                        { die "Could not make $BaseDir/$GroupName\n" }
        }
        chdir("$BaseDir/$GroupName") or die "Couldn't chdir to $GroupName\n";
        # Find the last article in the directory
        @AllInDir = <*>; @RevSortedAllInDir = reverse(sort(@AllInDir));
        $LenArr = @RevSortedAllInDir;
        if($LenArr > 0) { $NumLastInDir = $RevSortedAllInDir[0] }
        else { $NumLastInDir = 0 }
        ($NumArt, $NumFirst, $NumLast, $XGroupName) =
$NntpPtr->group($GroupName);

        if($NumLast == $NumLastInDir) { next }  # No new articles
        if($NumLast < $NumLastInDir)
                { die "In $GroupName, the last number was $NumLast, but the " .
                        " last number in the directory was $NumLastInDir\n" }
        # Figure out which article to start from
        if($NumLastInDir == 0) { $GetArtNum = $NumFirst }
        else { $GetArtNum = $NumLastInDir + 1 }

        # Now read each of the new articles
        while(1) {  # Loop until "last" is called
                $ArtRef = $NntpPtr->article($GetArtNum);
                @ArtArr = @$ArtRef; $ArtArrLen = @ArtArr;
                if($ArtArrLen > 0 ) {  # Skip article numbers that had 0 len
                        open(OUT, ">$GetArtNum") or
                                die "Could not create $GroupName/$GetArtNum\n";
                        print OUT @$ArtRef; close(OUT);
                }

                # Check if we're at the end
                if($GetArtNum == $NumLast) { last }
                $GetArtNum += 1;  # Increment the article number to get
        }
}

$NntpPtr->quit;
exit;

--- NEW FILE: inetd ---
#!/usr/local/bin/perl

use Net::DummyInetd;
use Net::SMTP;

$p = new Net::DummyInetd qw(/usr/lib/sendmail -ba -bs);

$smtp = Net::SMTP->new('localhost', Port => $p->port, Debug => 7);
$smtp->quit;

--- NEW FILE: pop3 ---
#!/usr/local/bin/perl -w

use blib;
use Net::POP3;
use Getopt::Long;

$opt_debug = 0;
$opt_user = undef;

GetOptions(qw(debug user=s));

$pop = Net::POP3->new('backup3', Debug => $opt_debug ? 6 : 0);

$user = $opt_user || $ENV{USER} || $ENV{LOGNAME};

$count = $pop->login($user);

if($count)
 {
  $m = $pop->get(1);
  print @$m if $m;
 }

$pop->quit;

--- NEW FILE: time ---
#!/usr/local/bin/perl -w

use blib;
use Net::Time qw(inet_time inet_daytime);

print inet_daytime('localhost');
print inet_daytime('localhost','tcp');
print inet_daytime('localhost','udp');

print inet_time('localhost'),"\n";
print inet_time('localhost','tcp'),"\n";
print inet_time('localhost','udp'),"\n";


--- NEW FILE: nntp ---
#!/usr/local/bin/perl

use blib;
use Getopt::Long;
use Net::NNTP;

$opt_debug = undef;

GetOptions(qw(debug));

@groups = @ARGV;

$nntp = Net::NNTP->new('news', Debug => $opt_debug ? 1 : 0);

if($subs = $nntp->newsgroups)
 {
  print join("\n",(keys %$subs)[0 .. 10]),"\n";
 }
 else
 {
  warn $nntp->message;
 }

foreach $group (@groups)
 {
  $new = $nntp->newnews(time - 3600, lc $group);

  if(ref($new) && scalar(@$new))
   {
    print@{$news}[0..3],"\n"
        if $news = $nntp->article($new->[-1]);

    warn $nntp->message
         unless $news;
   }
 }

$nntp->quit;






More information about the dslinux-commit mailing list