This commit is contained in:
Nick Bebout 2011-03-12 02:45:04 +00:00
parent 3f8607bd96
commit d88bf4b46a
90 changed files with 13227 additions and 504 deletions

54
learn/fetch_with_size Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/perl
use warnings;
use strict;
use English;
use Mail::IMAPClient;
$ARGV[3] or die "usage: $0 host user password folder uid\n";
my $host = $ARGV[0];
my $user = $ARGV[1];
my $password = $ARGV[2];
my $folder = $ARGV[3];
my $uid = $ARGV[4];
my $imap = Mail::IMAPClient->new();
$imap->Debug(0);
$imap->Server($host);
$imap->connect() or die;
$imap->User($user);
$imap->Password($password);
$imap->login() or die;
$imap->Uid(1);
$imap->Peek(1);
$imap->Clear(1);
#print map {"$_\n"} $imap->folders();
$imap->select($folder) or die;
my @msgs = $imap->messages or die "Could not messages: $@\n";
print "@msgs\n";
foreach my $msg (@msgs) {
$imap->fetch($msg, "BODY.PEEK[TEXT]<0.3000>");
my $text = $imap->_transaction_literals;
print '#' x 72, " $msg TEXT = \n$text\n";
my $part = $imap->bodypart_string($msg, '', 3000, 0);
print '#' x 72, " $msg PART = \n$part\n";
}
$imap->close();
package Mail::IMAPClient;
sub _transaction_literals() {
my $self = shift;
my $string = "";
foreach my $result (@{$self->{"History"}{$self->Transaction}}) {
$string .= $result->[DATA]
if defined($result) and $self->_is_literal($result) ;
}
return $string;
}

View file

@ -20,4 +20,4 @@ $imap->login() or die;
$imap->Uid(1);
$imap->Peek(1);
$imap->select($folder) or die;
$imap->close();
$imap->logout();

View file

@ -3,10 +3,15 @@
use warnings;
use strict;
use IO::Socket;
use English ;
use POSIX qw(uname SIGALRM);
use lib ( '../Mail-IMAPClient-3.25/lib' ) ;
use Mail::IMAPClient;
sub last_release {
my $host = shift || 'linux-france.org' ;
my $sock = new IO::Socket::INET (
PeerAddr => 'linux-france.org',
PeerAddr => $host,
PeerPort => '80',
Proto => 'tcp');
return('unknown') if not $sock;
@ -44,5 +49,67 @@ sub not_long {
}
}
print last_release(), "\n";
print not_long('last_release'), "\n";
sub not_long2 {
#print "Entering not_long\n";
my ( $func ) = shift ;
my ( @argv ) = @_ ;
my $val ;
# Doesn't work with gethostbyname (see perlipc)
#local $SIG{ALRM} = sub { die "alarm\n" };
if ('MSWin32' eq $OSNAME) {
local $SIG{ALRM} = sub { die "alarm\n" };
}else{
POSIX::sigaction(SIGALRM,
POSIX::SigAction->new(sub { die "alarm" }))
or warn "Error setting SIGALRM handler: $!\n";
}
eval {
alarm(3);
print "$func @argv", "\n";
{
no strict "refs";
#print "Calling $func\n";
$val = &$func( @argv ) ;
#print "End of $func\n";
}
alarm(0);
};
if ( $@ ) {
#print "$@";
if ($@ =~ /alarm/) {
# timed out
return('timeout');
}else{
alarm(0);
return('unknown'); # propagate unexpected errors
}
}else {
# didn't
return($val);
}
}
sub connect_test {
my $host = 'localhost' ;
my $imap = Mail::IMAPClient->new( ) ;
$imap->Debug( 1 ) ;
$imap->Server( $host ) ;
$imap->connect( ) or die ;
$imap->IsUnconnected( ) ;
$imap->logout( ) ;
}
#print last_release(), "\n" ;
#print not_long('last_release'), "\n" ;
connect_test( ) ;
print not_long2( 'last_release', ), "\n" ;
#print not_long2( 'last_release' ), "\n" ;
connect_test( ) ;

1226
learn/zzz Normal file

File diff suppressed because it is too large Load diff