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

#!/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

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

      Why are you trying to parse header information from attachments?

      There are 50k emails are lyin in inbox all emails has come from one email address(ex: staff@lastminute.com) and each email
      is coming from end customer as attachment that is
      containing sender address that will be hotmail address. Now all attachmnet it self is a mail that is why i need to p
      arse header so i can get those email address.

      Why are you using proprietary headers rather than standard ones (X-MS-Has-Attach for example)?


      I opened the outlook options and found that all attachment information is like this only,
      that is why i checked that condition. and it is storing all attachment OK. But i need to get the header info from attachment
        #!/usr/bin/perl use strict; use Mail::POP3Client; use MIME::Parser; use MIME::Head; use Mail::Header; #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/msgtxt1"); 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); ### Automatically attempt to RFC-1522- +decode the MIME headers? $parser->decode_headers(1); + ### default is false ### Parse contained "message/rfc822" o +bjects as nested MIME streams? $parser->extract_nested_messages(0); + ### default is true ### Look for uuencode in "text" messag +es, and extract it? $parser->extract_uuencode(1); + ### default is false ### Should we forgive normally-fatal e +rrors? $parser->ignore_errors(0); + ### default is true my $entity = $parser->parse_data($msg) +; } } } # print "\n"; } } close(FH); $pop->Close(); sub usage { print "Usage: $0 <mail_server> <username> <password>\n"; exit; }

        Above code does save all attachment. Now I need to parse those attachment
        One of the attachment will be .msg file that contains header einfo etc.
        I need to extarct those header info and find the sender address.
        Can somebody help me in this.