-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a cache for IMAP message in the database
Co-authored-by: Roeland Jago Douma <roeland@famdouma.nl> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
- Loading branch information
1 parent
31f89d7
commit c287787
Showing
60 changed files
with
2,398 additions
and
830 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
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,78 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @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\BackgroundJob; | ||
|
||
use OCA\Mail\Service\AccountService; | ||
use OCA\Mail\Service\SyncService; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\BackgroundJob\IJobList; | ||
use OCP\BackgroundJob\TimedJob; | ||
use OCP\ILogger; | ||
|
||
class SyncJob extends TimedJob { | ||
|
||
/** @var AccountService */ | ||
private $accountService; | ||
/** @var SyncService */ | ||
private $syncService; | ||
/** @var ILogger */ | ||
private $logger; | ||
/** @var IJobList */ | ||
private $jobList; | ||
|
||
public function __construct(ITimeFactory $time, | ||
AccountService $accountService, | ||
SyncService $syncService, | ||
ILogger $logger, | ||
IJobList $jobList) { | ||
parent::__construct($time); | ||
|
||
$this->accountService = $accountService; | ||
$this->syncService = $syncService; | ||
$this->logger = $logger; | ||
|
||
$this->setInterval(3600); | ||
$this->jobList = $jobList; | ||
} | ||
|
||
protected function run($argument) { | ||
$accountId = (int)$argument['accountId']; | ||
|
||
try { | ||
$account = $this->accountService->findById($accountId); | ||
} catch (DoesNotExistException $e) { | ||
$this->logger->debug('Could not find account <' . $accountId . '> removing from jobs'); | ||
$this->jobList->remove(self::class, $argument); | ||
return; | ||
} | ||
|
||
try { | ||
$this->syncService->syncAccount($account); | ||
} catch (\Exception $e) { | ||
$this->logger->logException($e); | ||
} | ||
} | ||
|
||
} |
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,73 @@ | ||
<?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\Command; | ||
|
||
use OCA\Mail\Db\MailboxMapper; | ||
use OCA\Mail\Service\AccountService; | ||
use OCA\Mail\Service\SyncService; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class SyncAccount extends Command { | ||
|
||
const ARGUMENT_ACCOUNT_ID = 'account-id'; | ||
const OPTION_FORCE = 'force'; | ||
|
||
/** @var AccountService */ | ||
private $accountService; | ||
|
||
/** @var MailboxMapper */ | ||
private $mailboxMapper; | ||
|
||
/** @var SyncService */ | ||
private $syncService; | ||
|
||
public function __construct(AccountService $service, | ||
MailboxMapper $mailboxMapper, | ||
SyncService $syncService) { | ||
parent::__construct(); | ||
|
||
$this->accountService = $service; | ||
$this->mailboxMapper = $mailboxMapper; | ||
$this->syncService = $syncService; | ||
} | ||
|
||
protected function configure() { | ||
$this->setName('mail:account:sync'); | ||
$this->setDescription('Synchronize an IMAP account'); | ||
$this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED); | ||
$this->addOption(self::OPTION_FORCE, 'f', InputOption::VALUE_NONE); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); | ||
$force = $input->getOption(self::OPTION_FORCE); | ||
|
||
$account = $this->accountService->findById($accountId); | ||
$this->syncService->syncAccount($account, $force); | ||
} | ||
} |
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
Oops, something went wrong.