Hacking Gmail

(Grace) #1

Chapter 7 — Gmail Libraries 121


Then you set the setLoginInfomethod, giving the username, password, and


time zone from GMT:


$gm->setLoginInfo($name, $pwd, $tz);


Finally, you tell Gmailer to connect:


$gm->connect();


You need to use setLoginInfoonly once — Gmailer saves your Gmail cookies,
so once you’ve logged in, you only need to use the connect()method to pass


more commands.


Putting that all together, then, you arrive at Listing 7-1, which gets you logged in


to Gmail, ready for some more code.


Listing 7-1:Logging in to Gmail with PHP

<?php


require(“libgmailer.php”);


$gm = new GMailer();
$name = “username”;
$pwd = “password”;
$tz = “0”;
$gm->setLoginInfo($name, $pwd, $tz);


if ($gm->connect()) {

/** THE REST OF YOUR CODE GOES IN HERE **/

}

$gm->disconnect();


?>


The disconnect()method logs you out again.


Parsing the Inbox


Once you are logged in, retrieving a thread is simple and is a good example to


show the deeper functions available from the Gmailer library.

Free download pdf