Here is a solution, though it's a bit convoluted:

1. Navigate to the gmail message thread of interest in your browser

2. Run the following JS in the developer console (or better, programmatically with Applescript, if using Safari, or some other browser automation program like WWW::Mechanize::Chrome) to get the "legacy" thread id: document.querySelector('[data-legacy-thread-id]').getAttribute('data-legacy-thread-id')

Once you get the thread id, you then need to convert it to a decimal number. my $dec_num_id = sprintf("%d", hex($thread_id));

3. Now that you have obtained the thread id, you can use the Perl Mail::IMAPClient cpan module to obtain the messages in the thread by searching on the thread id:

use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => 'imap.gmail.com', User => 'me', Password => 'blah', Ssl => 1, Uid => 1, ); my $folders = $imap->select('INBOX'); my $msgs = $imap->search("X-GM-THRID", $dec_num_id); foreach my $msg (@$msgs) { my $msg_st = $imap->message_string($msg); # slice and dice messages with modules listed below }

4. Now you can use cpan modules like Email::MIME and Email::MIME::Attachment::Stripper and Email::MIME::Encodings to parse the emails in $msgs and decode them as necessary.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to Re: Module for fetching body of email from Gmail from msg id? by nysus
in thread Module for fetching body of email from Gmail from msg id? by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.