Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

read gmail and extract cc field

by Anonymous Monk
on Jun 08, 2017 at 07:50 UTC ( [id://1192331]=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks, i have written a small script to check my gmail inbox and report the latest 5 messages. What i cannot figure out i how to extract the cc field from the email header. Hope someone can tell me, thank you.

use Mail::IMAPClient; use IO::Socket::SSL; $sock = IO::Socket::SSL->new( PeerAddr => "imap.gmail.com", PeerPort => 993) or die $@; $client = Mail::IMAPClient->new( Socket => $sock, User => 'anyany@gmail.com', Password => '*****' ); $client->select("INBOX"); @messages = $client->messages; for($x=1;$x<=5;$x++){ $bs = pop(@messages); $from = $client->get_header($bs,"from"); $date = $client->get_header($bs,"date"); $subj = $client->get_header($bs,"subject"); print "From:$from\nDate:$date\nSubject:$subj\n\n"; } $client->logout();

Replies are listed 'Best First'.
Re: read gmail and extract cc field -- Email::Simple
by Discipulus (Canon) on Jun 08, 2017 at 08:31 UTC
    Hello,

    In a recent post i played a little with my gmail account and it seems that Email::Simple just works well.

    If you use the code of the above thread and add print "Cc:\t",$es->header('Cc'),"\n"; where $es is the Email::Simple object, you'll find what you are looking for.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: read gmail and extract cc field
by hippo (Bishop) on Jun 08, 2017 at 08:24 UTC

    Adding this line works fine for me:

    $cc = $client->get_header($bs,"cc");

    At least on an IMAP server I have access to. If that doesn't work for you, I guess it's a gmail-specific thing.

      No, I've tried that.

        I would then inspect whether Gmail IMAP even sends you the Cc header by using the ->parse_headers method.

        Maybe the name of the header is not cc but Cc.

        use Data::Dumper; warn Dumper $client->parse_headers( $msgid );
Re: read gmail and extract cc field
by thanos1983 (Parson) on Jun 08, 2017 at 08:24 UTC

    Hello Anonymous Monk,

    Well you need the extension of the module Mail::IMAPClient::BodyStructure.

    From the documentation:

    This extension will parse the result of an IMAP FETCH BODYSTRUCTURE co +mmand into a perl data structure. It also provides helper methods to +help pull information out of the data structure.

    Sample from the module description Mail::IMAPClient::BodyStructure::Envelope:

    { subject => "subject", inreplyto => "reference_message_id", from => [ addressStruct1 ], messageid => "message_id", bcc => [ addressStruct1, addressStruct2 ], date => "Tue, 09 Jul 2002 14:15:53 -0400", replyto => [ adressStruct1, addressStruct2 ], to => [ adressStruct1, addressStruct2 ], sender => [ adressStruct1 ], cc => [ adressStruct1, addressStruct2 ], }

    Hope this helps.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1192331]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found