Mail-IMAPClient
view release on metacpan or search on metacpan
lib/Mail/IMAPClient.pm view on Meta::CPAN
}
else {
# show data if it is not like '"")' or '{123}'
$self->_debug("non-header data between fetch headers: $header")
if ( $header !~ /^(?:\s*\"\"\)|\{\d+\})$CR?$LF$/o );
}
}
# if we asked for one message, just return its hash,
# otherwise, return hash of numbers => header hash
ref $msgspec eq 'ARRAY' ? \%headers : $headers{$msgspec};
}
sub subject { $_[0]->get_header( $_[1], "Subject" ) }
sub date { $_[0]->get_header( $_[1], "Date" ) }
sub rfc822_header { shift->get_header(@_) }
sub get_header {
my ( $self, $msg, $field ) = @_;
my $headers = $self->parse_headers( $msg, $field );
$headers ? $headers->{$field}[0] : undef;
}
sub recent_count {
my ( $self, $folder ) = ( shift, shift );
$self->status( $folder, 'RECENT' )
or return undef;
my $r =
first { s/\*\s+STATUS\s+.*\(RECENT\s+(\d+)\s*\)/$1/ } $self->History;
chomp $r;
$r;
}
sub message_count {
my $self = shift;
my $folder = shift || $self->Folder;
$self->status( $folder, 'MESSAGES' )
or return undef;
foreach my $result ( $self->Results ) {
return $1 if $result =~ /\(MESSAGES\s+(\d+)\s*\)/i;
}
undef;
}
sub recent() { shift->search('recent') }
sub seen() { shift->search('seen') }
sub unseen() { shift->search('unseen') }
sub messages() { shift->search('ALL') }
sub sentbefore($$) { shift->_search_date( sentbefore => @_ ) }
sub sentsince($$) { shift->_search_date( sentsince => @_ ) }
sub senton($$) { shift->_search_date( senton => @_ ) }
sub since($$) { shift->_search_date( since => @_ ) }
sub before($$) { shift->_search_date( before => @_ ) }
sub on($$) { shift->_search_date( on => @_ ) }
sub _search_date($$$) {
my ( $self, $how, $time ) = @_;
my $imapdate;
if ( $time =~ /\d\d-\D\D\D-\d\d\d\d/ ) {
$imapdate = $time;
}
elsif ( $time =~ /^\d+$/ ) {
my @ltime = localtime $time;
$imapdate = sprintf( "%2.2d-%s-%4.4d",
$ltime[3],
$mnt[ $ltime[4] ],
$ltime[5] + 1900 );
}
else {
$self->LastError("Invalid date format supplied for '$how': $time");
return undef;
}
$self->_imap_uid_command( SEARCH => $how, $imapdate )
or return undef;
my @hits;
foreach ( $self->History ) {
chomp;
s/$CR?$LF$//o;
s/^\*\s+SEARCH\s+//i or next;
push @hits, grep /\d/, split;
}
$self->_debug("Hits are: @hits");
return wantarray ? @hits : \@hits;
}
sub or {
my ( $self, @what ) = @_;
if ( @what < 2 ) {
$self->LastError("Invalid number of arguments passed to or()");
return undef;
}
my $or =
"OR " . $self->Quote( shift @what ) . " " . $self->Quote( shift @what );
$or = "OR $or " . $self->Quote($_) for @what;
$self->_imap_uid_command( SEARCH => $or )
or return undef;
my @hits;
foreach ( $self->History ) {
chomp;
s/$CR?$LF$//o;
s/^\*\s+SEARCH\s+//i or next;
push @hits, grep /\d/, split;
}
$self->_debug("Hits are now: @hits");
return wantarray ? @hits : \@hits;
}
( run in 1.721 second using v1.01-cache-2.11-cpan-524268b4103 )