perlCrazy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I want to read mail inbox and parse the all attachment that is outlook type.
I wrote below code :
#!/usr/bin/perl use Mail::POP3Client; use Mail::MboxParser::Mail; my $pop = new Mail::POP3Client ('my','password','server'); for my $i (1 .. $pop->Count) { my $msg = Mail::MboxParser::Mail->new( [ $pop->Head($i) ], [ $pop->Body($i) ] ); $msg->store_all_attachments( path => '/tmp' ); }
Above code stores all attachment and that is OK, but here all attachments are outlook message type and I need to parse all attachment and find the FROM email addresses.
I am working on Linux box and able to store all attachment but not able to parse the attachment that is outlook message type
Pls. help me in this.

Replies are listed 'Best First'.
Re: How to parse outlook type attachment from inbox
by jdtoronto (Prior) on Sep 22, 2006 at 11:24 UTC
    perlCrazy,

    The attachments, I assume, are the body part attachments which are probably HTML. To get the From address you should take it from the headers, like this:

    use Mail::Header; my $header = $pop->Head($i); my $parsedhead = Mail::Header->new($header); chomp( my $subject = $parsedhead->get('Subject') ); print "Subject: $subject\n"; chomp( my $from = $parsedhead->get('From') ); print "From: $from\n";
    jdtoronto
      The attachment it self is a oulook message, and i am able to store those attachment in my directory,
      but to get read all attachment and find the email addresses who has sent.
      By using above code I am able to read only INBOX, can I read any folder ? Thnks
        You are using POP3 client code to get the emails from the server. So you can get the sender information from teh headers. The attachments may or may not include the full header information and are, therefore, an unreliable source of information. Amongst the attachments you get that way will also be any non-message attachments such as images and other documents - so trying to parse the attachments assumes you also can determine what the attachments are.

        POP3 does not embrace the concept of folders. That is something that belongs to the world of IMAP and Microsoft Outlook. If you are truly needing to work with IMAP then maybe you should be using something like IMAP::Client or Email::Folder::IMAP - neither of which I have used.

        jdtoronto