Log in

View Full Version : libgmailer experience?


MrToast
05-07-2005, 23:27
Hi all,

I'm trying to set up a page on my site to use libgmailer (http://gmail-lite.sourceforge.net/), an open source set of PHP classes for remotely connecting to Gmail.

What I'm trying to do is figure out how many invitations I have left. Unfortunately, nothing's working.

Here's the code of my main "gmail.php" file:
<?php
require_once("libgmailer.php");
$gmail = new GMailer();
$gmail->setLoginInfo("mrtoast@gmail.com","mypassword",0);
$gmail->connect();
$gmail->fetchBox(GM_STANDARD, "inbox", 0);
$info = $gmail->getInfo();
var_dump($info);
$gmail->disconnect();
?>

At first you may think "Oh, well your obvious problem is that there's no such function as "getInfo()". And you're right. Except that I've picked apart the code for Gallina, a gmail-based blogging system (http://ion.gluch.org.mx/files/Hacks/gallina/) and added the getInfo function to libgmailer:
function getInfo() {
$snapshot = $this->getSnapshot(GM_STANDARD);
$info = array();
if ($snapshot) {
$info["quota"]["MB"] = $snapshot->quota_mb;
$info["quota"]["Percentage"] = $snapshot->quota_per;
$info["invitations"] = $snapshot->have_invit;
$info["labels"] = $snapshot->label_list;
$info["total"] = $snapshot->box_total;
}
return $info;
}

Unfortunately, the var_dump is producing nothing but this:
array(4) {
["quota"]=>
array(2) {
["MB"]=>
NULL
["Percentage"]=>
NULL
}
["invitations"]=>
NULL
["labels"]=>
NULL
["total"]=>
NULL
}

If anyone has any experience with this, I'd love for someone to help me figure out where I'm screwing up. Feel free to IM me, email, post here, whatever.

Thanks!

Dave

Mike
05-07-2005, 23:46
function getInfo() {
$snapshot = $this->getSnapshot(GM_STANDARD);
$info = array();
if ($snapshot) {
$info["quota"]["MB"] = $snapshot->quota_mb;
$info["quota"]["Percentage"] = $snapshot->quota_per;
$info["invitations"] = $snapshot->have_invit;
$info["labels"] = $snapshot->label_list;
$info["total"] = $snapshot->box_total;
}
return $info;
}

When you call getSnapshot, your only have the $type parameter set (GM_STANDARD), but in the class GMailSnapshot constructor it also has a $raw parameter. There is an if statement which decides whether or not to set $this->have_invit;

if (isset($raw["i"][1])) $this->have_invit = $raw["i"][1];
But, $raw isn't set. Maybe try something like
function getInfo() {
$raw = array(
"i" => array(TRUE),
"gn" => array(TRUE),
"v" => array(TRUE)
);
$snapshot = $this->getSnapshot(GM_STANDARD);
$info = array();
if ($snapshot) {
$info["quota"]["MB"] = $snapshot->quota_mb;
$info["quota"]["Percentage"] = $snapshot->quota_per;
$info["invitations"] = $snapshot->have_invit;
$info["labels"] = $snapshot->label_list;
$info["total"] = $snapshot->box_total;
}
return $info;
}
That array setup may be fubar, as I've never dealt with multi-dimensional arrays in this sense...

EDIT (Again): Just looked over the code, and $this->have_invit is set from the array put in as a parameter, so I don't think you can get the amount of invites from calling this function =(

Maybe some creative use of sockets (http://us3.php.net/sockets) and regular expression (http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php) functions would let you parse the info out?

MrToast
05-07-2005, 23:58
I think that $raw IS set, because I call:
$gmail->fetchBox(GM_STANDARD, "inbox", 0);

Looking through this, we see it fires:
$this->fetch($q);

And then looking at the fetch function we see the line:
$this->raw = $packets;

So $raw is getting set. But I've just found something interesting...
In this same fetch function, the data returned from GMail is in the $inbox variable. I shot it out to HTML via:
echo "<textarea>".$inbox."</textarea>";
This is what's in the textarea:
<script>top.location="https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%3Fui %3Dhtml%26zy%3Dl";</script>

Any idea what's up with that?

Thanks!

Dave

Mike
06-07-2005, 00:09
Try echo'ing out $this->raw after it's set in fetch()

MrToast
06-07-2005, 00:14
It's an empty array:
array(0) { }

Grrrrr.... time to contact the developer.... :p

Dave

Mike
06-07-2005, 00:21
It's an empty array:
array(0) { }

Grrrrr.... time to contact the developer.... :p

Dave
Yeah, it'd take a while for someone to learn how he structured the code. Odds are it's being set somewhere else as well.