mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 19:10:11 +01:00
improved google email download
This commit is contained in:
parent
7ac7c7d98b
commit
d9bfe156a9
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
class ModelGoogleGoogle extends Model {
|
class ModelGoogleGoogle extends Model {
|
||||||
|
|
||||||
|
//Holds the Zend Storage
|
||||||
|
private $storage;
|
||||||
|
|
||||||
private function constructAuthString($email, $accessToken) {
|
private function constructAuthString($email, $accessToken) {
|
||||||
return base64_encode("user=$email\1auth=Bearer $accessToken\1\1");
|
return base64_encode("user=$email\1auth=Bearer $accessToken\1\1");
|
||||||
}
|
}
|
||||||
@ -43,21 +46,13 @@ class ModelGoogleGoogle extends Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save all Messages from selected folder
|
||||||
|
|
||||||
|
private function saveMessages($email) {
|
||||||
public function download_users_emails($email, $accessToken) {
|
|
||||||
$last_msg_id = -1;
|
$last_msg_id = -1;
|
||||||
$from = 1;
|
$from = 1;
|
||||||
$downloaded = 0;
|
$downloaded = 0;
|
||||||
|
$storage = $this->storage;
|
||||||
if(!$email || !$accessToken) { return 0; }
|
|
||||||
|
|
||||||
$imap = $this->try_imap_login($email, $accessToken);
|
|
||||||
|
|
||||||
if($imap) {
|
|
||||||
|
|
||||||
$storage = new Zend_Mail_Storage_Imap($imap);
|
|
||||||
$storage->selectFolder('[Gmail]/All Mail');
|
|
||||||
|
|
||||||
$from = $this->get_last_message_id_by_unique_id($email, $storage) + 1;
|
$from = $this->get_last_message_id_by_unique_id($email, $storage) + 1;
|
||||||
|
|
||||||
@ -103,6 +98,33 @@ class ModelGoogleGoogle extends Model {
|
|||||||
|
|
||||||
|
|
||||||
syslog(LOG_INFO, "downloaded $downloaded messages for $email");
|
syslog(LOG_INFO, "downloaded $downloaded messages for $email");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function download_users_emails($email, $accessToken) {
|
||||||
|
|
||||||
|
|
||||||
|
if(!$email || !$accessToken) { return 0; }
|
||||||
|
|
||||||
|
$imap = $this->try_imap_login($email, $accessToken);
|
||||||
|
|
||||||
|
if($imap) {
|
||||||
|
|
||||||
|
$this->storage = new Zend_Mail_Storage_Imap($imap);
|
||||||
|
|
||||||
|
//$storage->selectFolder('[Gmail]/INBOX');
|
||||||
|
$folders = new RecursiveIteratorIterator($this->storage->getFolders(),
|
||||||
|
RecursiveIteratorIterator::SELF_FIRST);
|
||||||
|
|
||||||
|
foreach ($folders as $localName => $folder) {
|
||||||
|
|
||||||
|
if ($folder->isSelectable()) {
|
||||||
|
$this->storage->selectFolder($folder);
|
||||||
|
$this->saveMessages($email);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user