126 Part II — Getting Inside Gmail
Once you’ve requested the Inbox and created a Snapshot, you can query that
Snapshot for details. To print out the number of threads within the Inbox, you
can say this:
echo “Threads in the inbox:” . $snapshot->box_total;
In order to get the Thread ID of the first thread in the Inbox, you can do this:
$threaded
= $snapshot->box[0][“id”];
As you can see from the code and the preceding tables, it’s really quite a straightforward interface. You’ll be using the interface in later chapters, but to finish,
Listing 7-2 shows PHP code using the Gmailer library to log in and display the
contents of the first message in the first thread in the Inbox.
Listing 7-2: Reading the First Message in the Inbox
require(“libgmailer.php”);
$gm = new GMailer();
$name = “username”;
$pwd = “password”;
$tz = “0”;
$gm->setLoginInfo($name, $pwd, $tz);
if ($gm->connect()) {
$gm->fetchBox(GM_STANDARD, Inbox, 0);
$snapshot = $gm->getSnapshot(GM_STANDARD);
$threaded
= $snapshot->box[0][“id”];
$gm->fetchBox(GM_CONVERSATION, $threaded, 0);
$snapshot = $gm->getSnapshot(GM_CONVERSATION);
echo “The first message reads” . $snapshot>conv[0][“body”];
}
$gm->disconnect();
?>
You return to this library in later chapters.
Once you’ve requested the Inbox and created a Snapshot, you can query that
Snapshot for details. To print out the number of threads within the Inbox, you
can say this:
echo “Threads in the inbox:” . $snapshot->box_total;
In order to get the Thread ID of the first thread in the Inbox, you can do this:
$threaded
= $snapshot->box[0][“id”];
As you can see from the code and the preceding tables, it’s really quite a straightforward interface. You’ll be using the interface in later chapters, but to finish,
Listing 7-2 shows PHP code using the Gmailer library to log in and display the
contents of the first message in the first thread in the Inbox.
Listing 7-2: Reading the First Message in the Inbox
require(“libgmailer.php”);
$gm = new GMailer();
$name = “username”;
$pwd = “password”;
$tz = “0”;
$gm->setLoginInfo($name, $pwd, $tz);
if ($gm->connect()) {
$gm->fetchBox(GM_STANDARD, Inbox, 0);
$snapshot = $gm->getSnapshot(GM_STANDARD);
$threaded
= $snapshot->box[0][“id”];
$gm->fetchBox(GM_CONVERSATION, $threaded, 0);
$snapshot = $gm->getSnapshot(GM_CONVERSATION);
echo “The first message reads” . $snapshot>conv[0][“body”];
}
$gm->disconnect();
?>
You return to this library in later chapters.
