-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a database cache for mailbox data
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
- Loading branch information
1 parent
3cc08ff
commit f40aba3
Showing
18 changed files
with
680 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Mail\Db; | ||
|
||
use OCA\Mail\Folder; | ||
use OCP\AppFramework\Db\Entity; | ||
|
||
/** | ||
* @method string getId() | ||
* @method void setId(string $id) | ||
* @method int getAccountId() | ||
* @method void setAccountId(int $accountId) | ||
* @method string getSyncToken() | ||
* @method void setSyncToken(string $syncToken) | ||
* @method string getAttributes() | ||
* @method void setAttributes(string $attributes) | ||
* @method string getDelimiter() | ||
* @method void setDelimiter(string $delimiter) | ||
* @method int getMessages() | ||
* @method void setMessages(int $messages) | ||
* @method int getUnseen() | ||
* @method void setUnseen(int $unseen) | ||
* @method bool getSelectable() | ||
* @method void setSelectable(bool $selectable) | ||
*/ | ||
class Mailbox extends Entity { | ||
|
||
protected $accountId; | ||
protected $syncToken; | ||
protected $attributes; | ||
protected $delimiter; | ||
protected $messages; | ||
protected $unseen; | ||
protected $selectable; | ||
|
||
public function __construct() { | ||
$this->addType('id', 'string'); | ||
$this->addType('accountId', 'integer'); | ||
$this->addType('messages', 'integer'); | ||
$this->addType('unseen', 'integer'); | ||
$this->addType('selectable', 'boolean'); | ||
} | ||
|
||
public function toFolder(): Folder { | ||
$folder = new Folder( | ||
$this->accountId, | ||
new \Horde_Imap_Client_Mailbox($this->id), | ||
json_decode($this->getAttributes() ?? '[]', true) ?? [], | ||
$this->delimiter | ||
); | ||
$folder->setSyncToken($this->getSyncToken()); | ||
return $folder; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Mail\Db; | ||
|
||
use OCA\Mail\Account; | ||
use OCP\AppFramework\Db\QBMapper; | ||
use OCP\IDBConnection; | ||
|
||
class MailboxMapper extends QBMapper { | ||
|
||
public function __construct(IDBConnection $db) { | ||
parent::__construct($db, 'mail_mailboxes'); | ||
} | ||
|
||
/** | ||
* @param Account $account | ||
* | ||
* @return Mailbox[] | ||
*/ | ||
public function findAll(Account $account): array { | ||
$qb = $this->db->getQueryBuilder(); | ||
|
||
$select = $qb->select('*') | ||
->from($this->getTableName()) | ||
->where($qb->expr()->eq('account_id', $qb->createNamedParameter($account->getId()))); | ||
|
||
return $this->findEntities($select); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.