Re: Use LWP to access gmail messages

David Pottage <[email protected]> Sat, 12 May 2018 09:20:19 +0100
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
--------------0AA6940771D34623094CC123
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit

On 11/05/18 21:47, Alicourant KOTE wrote:
>
> Hi everybody,
>
> I am new to perl but think I love it.
>
> How can I use LWP to access the google mail web page, select uread 
> messages and display them directly in the gmail?
>
> I do not want to save them somewhere. Just make gmail display the 
> unread messages.
>
> Here are steps:
>
> 1.Run Google Chrome;
>
> 2.Go to the page http://www.google.com, this will display the page 
> https://www.google.com;
>
> 3.Find and clic on gmail button in this page;
>
> 4.Wait until all the page loads;
>
> 5.Select my account in a displayed form (there is a list of 2 accounts 
> in a that form: one is my wife’s account) and clic on it;
>
> 6.Fill in my password and clic Next
>
> 7.When all messages are completely loaded, display only those unread.
>
> I do not want to use WWW:Mechanize because it does not deal will 
> javascript.
>
> Can hope to be helped?
>

The the usual answer to this would be to use Mechanize or HTML::Tree 
builder, but in either case it will be hard because of JavaScript, and 
because those web pages are designed for human interaction, not to be 
parsed by scripts.

In the case of gmail email, the easiest approach would be to access the 
mailbox using the IMAP protocol. See Mail::IMAPClient. This will avoid 
using a web browser of any sort, and instead use a protocol that is 
designed for use by scripts and other programs.

You may have to adjust the security settings on your gmail account so 
that IMAP access is permitted.

-- 
David Pottage


--------------0AA6940771D34623094CC123
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 11/05/18 21:47, Alicourant KOTE
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:[email protected]">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";
	mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{mso-style-priority:34;
	margin-top:0cm;
	margin-right:0cm;
	margin-bottom:0cm;
	margin-left:36.0pt;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";
	mso-fareast-language:EN-US;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";
	mso-fareast-language:EN-US;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
	{page:WordSection1;}
/* List Definitions */
@list l0
	{mso-list-id:360009153;
	mso-list-type:hybrid;
	mso-list-template-ids:1473643386 67895311 67895321 67895323 67895311 67895321 67895323 67895311 67895321 67895323;}
@list l0:level1
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l0:level2
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l0:level3
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l0:level4
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l0:level5
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l0:level6
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l0:level7
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l0:level8
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l0:level9
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:none;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Hi everybody,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I am new to perl but
            think I love it.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">How can I use LWP to
            access the google mail web page, select uread messages and
            display them directly in the gmail?<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I do not want to save
            them somewhere. Just make gmail display the unread messages.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Here are steps:<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">1.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">Run Google Chrome;<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">2.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">Go to the page <a href="http://www.google.com"
              moz-do-not-send="true">http://www.google.com</a>, this
            will display the page <a class="moz-txt-link-freetext" href="https://www.google.com">https://www.google.com</a>;<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">3.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">Find and clic on gmail button in this page;<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">4.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">Wait until all the page loads;<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">5.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">Select my account in a displayed form (there is
            a list of 2 accounts in a that form: one is my wife’s
            account) and clic on it;<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">6.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">Fill in my password and clic Next<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">7.<span
                style="font:7.0pt &quot;Times New Roman&quot;">      </span></span></span><!--[endif]--><span
            lang="EN-US">When all messages are completely loaded,
            display only those unread.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I do not want to use
            WWW:Mechanize because it does not deal will javascript.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Can hope to be helped?</span></p>
      </div>
    </blockquote>
    <br>
    The the usual answer to this would be to use <span lang="EN-US">Mechanize
      or HTML::Tree builder, but in either case it will be hard because
      of JavaScript, and because those web pages are designed for human
      interaction, not to be parsed by scripts.<br>
      <br>
      In the case of gmail email, the easiest approach would be to
      access the mailbox using the IMAP protocol. See </span><span
      lang="EN-US">Mail::IMAPClient. This will avoid using a web browser
      of any sort, and instead use a protocol that is designed for use
      by scripts and other programs.<br>
      <br>
      You may have to adjust the security settings on your gmail account
      so that IMAP access is permitted.<br>
      <br>
      -- <br>
      David Pottage<br>
      <br>
    </span>
  </body>
</html>

--------------0AA6940771D34623094CC123--