# HG changeset patch # User Matthias Förste foerste@schlittermann.de # Date 1320242834 -3600 # Node ID 64c0bacc15b0bb36611a8ec4dd6767dcb3672efe # Parent 4fd1c0261e370674874cc07350dd9d46a79c96dd use Mail::IMAPClient instead of Net::IMAP::Client because the latter will unconditionally reconnect in case of connection drops which is *not* always desired diff -r 4fd1c0261e37 -r 64c0bacc15b0 isearch --- a/isearch Wed Nov 02 14:19:50 2011 +0100 +++ b/isearch Wed Nov 02 15:07:14 2011 +0100 @@ -25,12 +25,12 @@ use Getopt::Long; use Pod::Usage; -use Net::IMAP::Client 0.95; +use Mail::IMAPClient; my $opts; my %imapopts = ( - server => 'localhost', - port => 143, + Server => 'localhost', + Port => 143 ); GetOptions( @@ -44,21 +44,21 @@ -noperldoc => ( `perldoc -V 2>/dev/null`, $? != 0 )[-1] ); }, - "password=s" => \$imapopts{pass}, - "p|port=s" => \$imapopts{port}, - "s|server=s" => \$imapopts{server}, - "u|user=s" => \$imapopts{user} + "password=s" => \$imapopts{Password}, + "p|port=s" => \$imapopts{Port}, + "s|server=s" => \$imapopts{Server}, + "u|user=s" => \$imapopts{User} ) or pod2usage(); -defined $opts->{criteria} and defined $imapopts{user} or pod2usage(); +defined $opts->{criteria} and defined $imapopts{User} or pod2usage(); -if ( defined $imapopts{pass} ) { +if ( defined $imapopts{Password} ) { - if ( -r $imapopts{pass} ) { + if ( -r $imapopts{Password} ) { - open P, '<', $imapopts{pass} - or die "Can't open '$imapopts{pass}' for reading: $!\n"; - $imapopts{pass} =
; - chomp $imapopts{pass}; + open P, '<', $imapopts{Password} + or die "Can't open '$imapopts{Password}' for reading: $!\n"; + $imapopts{Password} =
;
+ chomp $imapopts{Password};
}
@@ -68,19 +68,16 @@
use Term::ReadKey;
ReadMode 'noecho';
- $imapopts{pass} = ReadLine 0;
+ $imapopts{Password} = ReadLine 0;
ReadMode 0;
}
-my $imap = Net::IMAP::Client->new(%imapopts)
+my $imap = Mail::IMAPClient->new(%imapopts)
or die "Could not connect to IMAP server\n";
-$imap->login
- or die "Login failed: " . $imap->last_error . "\n";
-
-my @f = ( @ARGV or $imap->folders );
-die "Can't get folderlist: " . $imap->last_error . "\n" unless @f;
+my $f = ( @ARGV or $imap->folders );
+die "Can't get folderlist: " . $imap->LastError . "\n" unless $f;
my $mids;
@@ -90,16 +87,17 @@
next unless /volke.*2011/;
- print "\nExamining $_ ...";
+ print "Examining $_ ...\n";
$imap->examine($_)
- or die "Can't examine: " . $imap->last_error . "\n";
+ or die "Can't examine: " . $imap->LastError . "\n";
print "Searching $_ ...\n";
- my $m = $imap->search( $opts->{criteria}, undef, $opts->{charset} )
- or die "Can't search: " . $imap->last_error . "\n";
+ my $m = $imap->search( $opts->{criteria} )
+ or die "Can't search: " . $imap->LastError . "\n";
$mids->{$_} = $m;
}
+my @headers = qw(subject from to cc bcc date);
for ( sort keys %{$mids} ) {
my $m = $mids->{$_};
@@ -107,13 +105,16 @@
if ( @{$m} ) {
$imap->examine($_)
- or die "Can't examine: " . $imap->last_error . "\n";
- my $s = $imap->get_summaries( $mids->{$_} )
- or die "Can't get summaries: " . $imap->last_error . "\n";
+ or die "Can't examine: " . $imap->LastError . "\n";
+ my $h = $imap->parse_headers( $mids->{$_}, @headers )
+ or die "Can't get summaries: " . $imap->LastError . "\n";
- for ( @{$s} ) {
+ for my $id ( keys %{$h} ) {
- print $_->subject . "\n";
+ print "\n[$id]\n";
+ for my $hn (@headers) {
+ print ucfirst $hn . ": $_\n" for @{$h->{$id}->{$hn}};
+ }
}
@@ -158,10 +159,6 @@
The criteria to search for. See the section about the SEARCH command in the
IMAP RFC (3501 currently) for valid criteria.
-=item B<--charset> I