in reply to imap problem with gmail
I used the below quick program to access gmail account via IMAP. The module I use is Net::IMAP::Simple and it's docs tell us that the search in IMAP is defined in RFC 5256. The module has the capability to search but a a quick (read: no exhaustive) serach seems to suggest that gmail doesn't support RFC 5256. Anyway I confirm that the only search that runs ok with gmail is $imap->search("ALL")
use strict; use warnings; # required modules use Net::IMAP::Simple; use Email::Simple; use IO::Socket::SSL; use HTML::Strip; use Data::Dump; # fill in your details here my $username = 'my_account_of_gmail@gmail.com'; my $password = $ARGV[0] || die "password as first argument!"; my $mailhost = 'pop.gmail.com'; # Connect my $imap = Net::IMAP::Simple->new( $mailhost, port => 993, use_ssl => 1, ) || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n"; my $hs = HTML::Strip->new(); # Log in if ( !$imap->login( $username, $password ) ) { print STDERR "Login failed: " . $imap->errstr . "\n"; exit(64); } # Look in the the INBOX my $nm = $imap->select('INBOX'); # How many messages are there? my ($unseen, $recent, $num_messages) = $imap->status(); print "unseen: $unseen, recent: $recent, total: $num_messages\n\n"; ## Iterate through unseen messages for ( my $i = 1 ; $i <= $nm ; $i++ ) { #last if $i == 2; if ( $imap->seen($i) ) { next; } else { my $es = Email::Simple->new( join '', @{ $imap->get($i) } ); printf( "[%03d] %s\n", $i, $es->header('From'), $es->header('Subje +ct')); #print "BODY[".$es->body."]\n\n"; print "Cc-------------->", $es->header('Cc'),"\nTo------>",$es->he +ader('To'),"\n"; #dd $es; print $hs->parse( $es->body ); print +('=' x 70),"\n"; } } # Disconnect $imap->quit; exit;
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: imap problem with gmail -- RFC 5256
by morgon (Priest) on Nov 03, 2017 at 11:24 UTC |