Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by jdtoronto (Prior)
on Sep 22, 2006 at 13:38 UTC ( [id://574372]=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re^3: How to parse outlook type attachment from inbox

Replies are listed 'Best First'.
Re^4: How to parse outlook type attachment from inbox
by perlCrazy (Monk) on Sep 22, 2006 at 15:23 UTC
    #!/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

        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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://574372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-24 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found