need a routine on IS7 (Perl 5.14.2 built for MSWin32-x64 and win32-x86)

1- download emails from pop3 server one by one,

2- examine contents an attachments

3- selectively save attachment files to a folder (keep original name)

4- delete the entry from pop server:

Here is the sample code I have but extracting attachments have been a challenge can anyone help. Thanks


#!perl # #Open Pop3 (Cell2email) Receives all Emails #Checks if they are destined for a cell phone Number #Saves the text in Send folder /waiting for Sm-SndRm.pl to #send via ftp to Cel phone for processing by Talk.pk #
use Mail::POP3Client; use Mail::Audit qw(Attach); use Email::MIME; require "tstLib.pl"; require "tstMain.pl"; SetVars(); # $ErrMsg =''; # ReadSetUp(); # ReadPopPar(); # my $line=''; $PopID ='xxxx'; $PopPWD='xxxx'; $PopSrvr='xxxxx'; $!=''; $pop = new Mail::POP3Client( USER => $PopID, PASSWORD => $PopPWD, HOST => $PopSrvr, , AUTH_MODE => 'PASS' ); for ($i = 1; $i <= $pop->Count(); $i++) { print "Message $i: -------------------------\n"; my $headerid = 1; my $From =''; my $FrmEM=''; my $To =''; my $Subj =''; my $mDate =''; my $iMail = $pop->Retrieve($i); my $mailRef= \@iMail ; my $rMail = Mail::Audit->new (data=>$mailRef); foreach ( $pop->Head( $i ) ) { #if ($_ =~ /^Date:.*([0-9]{1,2}\s[a-zA-Z]{3}\s[0-9]{2,4})/) { if ($_ =~ /^From:/ ) { $From =ltrim(substr($_,index($_,'From:')+5)) ; $FrmEM =substr($From,index($From,'<')+1,rindex($From,'>')-index($F +rom,'<')-1 ); $From =~ s/<|>// ; }; if ($_ =~ /^To:/i ) { $To =ltrim(substr($_,index($_,'To:')+3)) ; }; if ($_ =~ /^Date:.*([0-9]{1,2}\s[a-zA-Z]{3}\s[0-9]{2,4})/) { $mDate =ltrim(substr($_,index($_,'Date:')+5)) ; } if ($_ =~ /^Subject:/i ) { print "subj.: $_\n"; $Subj =ltrim(substr($_,index($_,'Subject:')+8)) ; }; }; my $BodyCoded= $pop->Retrieve( $i); my $Parsed = Email::MIME->new($BodyCoded); my $Text = handle_parts($Parsed); $Text=~s/\r//g ; $Text=~s/\n\n/\n/g ; my $mem = "From:$From\n\r To:$To\n\rDate:$mDate \n\rBody:$Text\n"; print $mem; SaveFl("temp/Eml/$i-text\.txt" , $mem); $headerid ++; } $pop->Close; exit; # sub handle_parts { my $part = shift; my $content_type = $part->content_type; print "** Cont-Type: $content_type \n"; # debug my $body = $part->body; if ($content_type =~ m#text/plain#) { $body; }elsif ($content_type =~ m#text/html#) { html2text($body); }elsif ($content_type =~ m#multipart/#) { for my $subpart ($part->parts) { my $text = handle_parts($subpart); # return $text if defined $text; } } $body} sub html2text { my $html = shift; # my $text = ... (left as an exercise) # return $text; return $html; }

In reply to Email Attachment stripper by bGhassemlou

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.