Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to parse outlook type attachment from inbox

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


in reply to How to parse outlook type attachment from inbox

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

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

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-25 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found