Hi,

I am using MIME::Parse to extract the content of the mail.
Code that I am using:

#!/usr/bin/perl -w # Always be safe use strict; use warnings; # Use the module use Mail::IMAPClient; use MIME::Parser; use Data::Dumper; use constant { MULTIPART => "MULTIPART", TEXT => "TEXT" }; my $imap = Mail::IMAPClient->new( Server => "localhost", User => 'pgadekar', password => "pgadekar", Port => 143, Ssl=> 0, Uid=> 1) or die "IMAP Failure: $@"; $imap->select("INBOX") or die "IMAP Select Error: $@"; foreach my $box qw( INBOX ) { # How many msgs are we going to process print "There are ". $imap->message_count($box). " messages in the + $box folder.\n"; # Select the mailbox to get messages from $imap->select($box) or die "IMAP Select Error: $@"; # Store each message as an array element my @msgseqnos = $imap->messages() or die "Couldn't get all message +s $@\n"; # Loop over the messages and store in file foreach my $seqno (@msgseqnos) { my $parser = MIME::Parser->new; my $entity = $parser->parse_data($imap->message_string($seqno) +); my $header = $entity->head; my $from = $header->get_all("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 "From: ". Dumper($from); print "Message-id: $msg_id"; print "To: $to"; print "Date: $date"; print "Subject: $subject"; my $content = get_msg_content($entity); $entity->purge(); print "Content: $content"; } # Expunge and close the folder $imap->expunge($box); $imap->close($box); } # We're all done with IMAP here $imap->logout(); sub split_entity { local $entity = shift; my $num_parts = $entity->parts; # how many mime parts? if ($num_parts) { # we have a multipart mime message foreach (1..$num_parts) { split_entity( $entity->parts($_ - 1) ); # recursive call } } else { # we have a single mime message/part if ($entity->effective_type =~ /^text\/plain$/) { # text messa +ge print "Part Content: " . $entity->bodyhandle->as_string; } else { # no text message print "Attachment Content: ". handle_other($entity->bodyha +ndle->path); } } } sub handle_other() { local $path = shift; }

What should I write in sub handle_other so that I can get the content of the attachment ?


In reply to Extracting Attachments Using MIME::Parse by pgadekar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.