ecuguru has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use MIME::Parser; use Mail::IMAPClient; use Data::Dumper; use IO::Socket::SSL; # Connect to the IMAP server via SSL my $socket = IO::Socket::SSL->new( PeerAddr => 'imap.gmail.com', PeerPort => 993, ) or die "socket(): $@"; # Build up a client attached to the SSL socket. # Login is automatic as usual when we provide User and Password my $client = Mail::IMAPClient->new( Socket => $socket, User => 'user', Password => 'pass', IgnoreSizeErrors => '1' ) or die "new(): $@"; if ($client->IsAuthenticated()) { my $msgct; my $seqno = 0; $client->select("INBOX"); $msgct = $client->unseen_count||'0'; print "Number of unread Messages: $msgct\n"; my @unread = $client->unseen or warn "Could not find unseen msgs: +$@\n"; foreach $seqno (@unread){ my $parser = MIME::Parser->new; my $entity = $parser->parse_data($client->message_string($seqn +o)); my $header = $entity->head; my $from = $header->get("From"); my $msg_id = $header->get("message-id"); my $to = $header->get_all("To"); my $date = $header->get("date"); my $subject = $header->get("subject"); print "Message-id: $msg_id"; print "From: ". $from; print "To: $to"; print "Date: $date"; print "Subject: $subject"; ###### Attachment Parse Here # my $content = get_msg_content($entity); $entity->purge(); # print "Content: $content"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Attachment Extraction from Imap
by Anonymous Monk on May 14, 2012 at 05:52 UTC | |
by Anonymous Monk on May 14, 2012 at 05:57 UTC |