mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-06-12 23:17:02 +02:00
finalized google free apps support
This commit is contained in:
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user