in reply to Re: How to parse outlook type attachment from inbox
in thread How to parse outlook type attachment from inbox

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
  • Comment on Re^2: How to parse outlook type attachment from inbox

Replies are listed 'Best First'.
Re^3: How to parse outlook type attachment from inbox
by jdtoronto (Prior) on Sep 22, 2006 at 13:38 UTC
    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

      #!/usr/bin/perl use Mail::POP3Client; use MIME::Parser; #usage() unless scalar @ARGV == 3; my $pop = new Mail::POP3Client( HOST => 'server', USER => 'my', PASSWORD => 'pass' ); my $tmp_directory = "/tmp/attach"; my $parser = new MIME::Parser; $parser->output_dir($tmp_directory); $parser->output_prefix("attachment"); $parser->output_to_core(); open (FH,">>/tmp/msgtxt"); for (my $i = 1; $i <= $pop->Count(); $i++){ my $head = $pop->Head($i); if ($head =~ /X-MS-Has-Attach: yes/i){ foreach ( $pop->Head( $i ) ) { if( /^(From|Subject):\s+/i ) { if ( /Vincent/) { my $msg = $pop->HeadAndBody($i); if ($msg =~/^To: /) { print FH " $msg \n"; } my $entity = $parser->parse_data($msg) +; } } } # print "\n"; } } close(FH); $pop->Close(); sub usage { print "Usage: $0 <mail_server> <username> <password>\n"; exit; }
      Above is updated code, it stores almost all attachment according to condition.
      Now I need to parse thos attachment and find the header from that attachment.
      Ex: In all attachment "To" address will be 'hotmail address'.
      Is there any way to get all hotmail addresses from that header inside attachment. Thnks
        OK perlCrazy,

        Time to back up here a little. Two questions:

        • Why are you trying to parse header information from attachments?
        • Why are you using proprietary headers rather than standard ones (X-MS-Has-Attach for example)?
        Maybe if you told us what exactly you are trying to achieve it would make it easier for all of us.

        jdtoronto