finalized google free apps support

This commit is contained in:
SJ
2012-09-28 14:15:45 +02:00
parent 14ef68ed98
commit f2dd3b669a
7 changed files with 113 additions and 11 deletions

View File

@ -48,6 +48,7 @@ class ModelGoogleGoogle extends Model {
public function download_users_emails($email, $accessToken) {
$last_msg_id = -1;
$from = 1;
$downloaded = 0;
if(!$email || !$accessToken) { return 0; }
@ -82,11 +83,15 @@ class ModelGoogleGoogle extends Model {
while(list($k, $v) = each($messages)) {
$uuid = $storage->getUniqueId($k);
$tmpname = DIR_TMP . "piler-" . $email . "-" . $k . "-" . $uuid . ".eml";
$f = fopen($tmpname, "w+");
$tmpname = "piler-" . $email . "-" . $k . "-" . $uuid . ".eml";
$f = fopen(DIR_TMP . "/" . $tmpname, "w+");
if($f){
fwrite($f, $v['RFC822.HEADER'] . $v['RFC822.TEXT']);
fclose($f);
rename(DIR_TMP . "/" . $tmpname, DIR_IMAP . "/" . $tmpname);
$downloaded++;
}
//print "k: $k\n";
}
@ -97,7 +102,7 @@ class ModelGoogleGoogle extends Model {
}
syslog(LOG_INFO, "downloaded $downloaded messages for $email");
}
}

View File

@ -80,6 +80,31 @@ class ModelUserGoogle extends Model {
}
public function refresh_access_token($email = '') {
if($email == '') { return ''; }
$query = $this->db->query("SELECT refresh_token FROM " . TABLE_GOOGLE . " WHERE email=?", array($email));
if(!isset($query->row['refresh_token'])) { return ''; }
$client = new apiClient();
$client->setApplicationName(GOOGLE_APPLICATION_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_REDIRECT_URL);
$client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
$client->refreshToken($query->row['refresh_token']);
$s = $client->getAccessToken();
$a = json_decode($s);
if(isset($a->{'access_token'})) { return $a->{'access_token'}; }
return '';
}
}
?>