Sadly, there must be a dozen other threads on this but I still can't figure it out. In fact, I'm ripping off
another thread, but they left off the secret sauce I need.
I email myself photos from my phone to my gmail account. I'm trying to setup a script that will run every few minutes, look for new photos, and if found copy the images from the mail message and into a folder. Really straight forward, it will always be an image file (maybe a few in the same message?), nothing too fancy. But I can't figure out mime parsing to save my life.
The part I need help with is at the very bottom, I only put the rest of the code in incase anyone needed the backdrop. Any chance anyone can fill in the missing chunk at the bottom where it says Attachment Parse Here?
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";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.