diff --git a/lib/Account.php b/lib/Account.php index fa68bd0d21..1bd89c997f 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -11,7 +11,6 @@ use JsonSerializable; use OCA\Mail\Db\MailAccount; -use OCA\Mail\Service\Quota; use ReturnTypeWillChange; class Account implements JsonSerializable { @@ -62,36 +61,4 @@ public function getUserId() { return $this->account->getUserId(); } - /** - * @return bool - */ - public function getDebug(): bool { - return $this->account->getDebug(); - } - - public function getImipCreate(): bool { - return $this->account->getImipCreate(); - } - - /** - * Set the quota percentage - * @param Quota $quota - * @return void - */ - public function calculateAndSetQuotaPercentage(Quota $quota): void { - if ($quota->getLimit() === 0) { - $this->account->setQuotaPercentage(0); - return; - } - $percentage = (int)round($quota->getUsage() / $quota->getLimit() * 100); - $this->account->setQuotaPercentage($percentage); - } - - public function getQuotaPercentage(): ?int { - return $this->account->getQuotaPercentage(); - } - - public function getClassificationEnabled(): bool { - return $this->account->getClassificationEnabled(); - } } diff --git a/lib/BackgroundJob/QuotaJob.php b/lib/BackgroundJob/QuotaJob.php index c274f7f478..73a40d7094 100644 --- a/lib/BackgroundJob/QuotaJob.php +++ b/lib/BackgroundJob/QuotaJob.php @@ -81,10 +81,15 @@ protected function run($argument): void { $this->logger->debug('Could not get quota information for account <' . $account->getEmail() . '>', ['app' => 'mail']); return; } - $previous = $account->getMailAccount()->getQuotaPercentage(); - $account->calculateAndSetQuotaPercentage($quota); - $this->accountService->update($account->getMailAccount()); - $current = $account->getQuotaPercentage(); + $mailAccount = $account->getMailAccount(); + $previous = $mailAccount->getQuotaPercentage(); + if ($quota->getLimit() === 0) { + $mailAccount->setQuotaPercentage(0); + } else { + $mailAccount->setQuotaPercentage((int)round($quota->getUsage() / $quota->getLimit() * 100)); + } + $this->accountService->update($mailAccount); + $current = $mailAccount->getQuotaPercentage(); // Only notify if we've reached the rising edge if ($previous < $current && $previous <= 90 && $current > 90) { diff --git a/lib/BackgroundJob/TrainImportanceClassifierJob.php b/lib/BackgroundJob/TrainImportanceClassifierJob.php index 2a940d8a38..9a51df6967 100644 --- a/lib/BackgroundJob/TrainImportanceClassifierJob.php +++ b/lib/BackgroundJob/TrainImportanceClassifierJob.php @@ -60,7 +60,7 @@ protected function run($argument) { return; } - if (!$account->getClassificationEnabled()) { + if (!$account->getMailAccount()->getClassificationEnabled()) { $this->logger->debug("classification is turned off for account $accountId"); return; } diff --git a/lib/Command/TrainAccount.php b/lib/Command/TrainAccount.php index ceca1f5c83..3125fbad87 100644 --- a/lib/Command/TrainAccount.php +++ b/lib/Command/TrainAccount.php @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } - if (!$force && !$account->getClassificationEnabled()) { + if (!$force && !$account->getMailAccount()->getClassificationEnabled()) { $output->writeln("classification is turned off for account $accountId"); return 2; } diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php index 93f88d6040..229d09b641 100644 --- a/lib/IMAP/IMAPClientFactory.php +++ b/lib/IMAP/IMAPClientFactory.php @@ -129,7 +129,7 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C 'backend' => $this->hordeCacheFactory->newCache($account), ]; } - if ($account->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) { + if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) { $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-imap.log'; $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; } diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index 00eed8cf3d..0315414a12 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -82,7 +82,7 @@ public function create(Account $account): Horde_Mail_Transport { $decryptedAccessToken, ); } - if ($account->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) { + if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) { $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-smtp.log'; $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; } diff --git a/lib/Service/Classification/NewMessagesClassifier.php b/lib/Service/Classification/NewMessagesClassifier.php index aa88182f92..449157531f 100644 --- a/lib/Service/Classification/NewMessagesClassifier.php +++ b/lib/Service/Classification/NewMessagesClassifier.php @@ -57,7 +57,7 @@ public function classifyNewMessages( Account $account, Tag $importantTag, ): bool { - if (!$account->getClassificationEnabled()) { + if (!$account->getMailAccount()->getClassificationEnabled()) { return false; } diff --git a/lib/Service/IMipService.php b/lib/Service/IMipService.php index 1c8d3f991c..028a2b8a54 100644 --- a/lib/Service/IMipService.php +++ b/lib/Service/IMipService.php @@ -121,7 +121,7 @@ public function process(): void { $userId = $account->getUserId(); $recipient = $account->getEmail(); - $imipCreate = $account->getImipCreate(); + $imipCreate = $account->getMailAccount()->getImipCreate(); $systemVersion = $this->serverVersion->getMajorVersion(); foreach ($filteredMessages as $message) { diff --git a/lib/Sieve/SieveClientFactory.php b/lib/Sieve/SieveClientFactory.php index bd0fb0b4b6..fb9264ae6b 100644 --- a/lib/Sieve/SieveClientFactory.php +++ b/lib/Sieve/SieveClientFactory.php @@ -38,7 +38,7 @@ public function getClient(Account $account): ManageSieve { $password = $account->getMailAccount()->getInboundPassword(); } - if ($account->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) { + if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) { $logFile = $this->config->getSystemValue('datadirectory') . '/mail-' . $account->getUserId() . '-' . $account->getId() . '-sieve.log'; } else { $logFile = null; diff --git a/tests/Unit/BackgroundJob/QuotaJobTest.php b/tests/Unit/BackgroundJob/QuotaJobTest.php index 4b9a98e125..fa91aaa48f 100644 --- a/tests/Unit/BackgroundJob/QuotaJobTest.php +++ b/tests/Unit/BackgroundJob/QuotaJobTest.php @@ -142,12 +142,6 @@ public function testQuotaNoAuthentication(): void { $this->serviceMock->getParameter('mailManager') ->expects(self::never()) ->method('getQuota'); - $account->expects(self::never()) - ->method('calculateAndSetQuotaPercentage') - ->with($quotaDTO); - $account->expects(self::never()) - ->method('getQuotaPercentage') - ->willReturn($newQuota); $this->serviceMock->getParameter('accountService') ->expects(self::never()) ->method('update') @@ -162,12 +156,12 @@ public function testQuotaNoAuthentication(): void { } public function testQuotaTooLow(): void { - $oldQuota = 10; - $newQuota = 20; $quotaDTO = new Quota(20, 100); - $mailAccount = $this->createConfiguredMock(MailAccount::class, [ - 'canAuthenticateImap' => true, - ]); + $mailAccount = new MailAccount(); + $mailAccount->setId(123); + $mailAccount->setUserId('user123'); + $mailAccount->setInboundPassword('password'); + $mailAccount->setQuotaPercentage(10); $account = $this->createConfiguredMock(Account::class, [ 'getId' => 123, 'getUserId' => 'user123', @@ -182,8 +176,6 @@ public function testQuotaTooLow(): void { ->method('findById') ->with(123) ->willReturn($account); - $mailAccount->expects(self::once()) - ->method('canAuthenticateImap'); $this->serviceMock->getParameter('userManager') ->expects(self::once()) ->method('get') @@ -196,15 +188,6 @@ public function testQuotaTooLow(): void { ->expects(self::once()) ->method('getQuota') ->willReturn($quotaDTO); - $account->expects(self::once()) - ->method('calculateAndSetQuotaPercentage') - ->with($quotaDTO); - $account->expects(self::exactly(3)) - ->method('getMailAccount') - ->willReturn($mailAccount); - $account->expects(self::once()) - ->method('getQuotaPercentage') - ->willReturn($newQuota); $this->serviceMock->getParameter('accountService') ->expects(self::once()) ->method('update') @@ -219,12 +202,13 @@ public function testQuotaTooLow(): void { } public function testQuotaWithNotification(): void { - $oldQuota = 85; $newQuota = 95; $quotaDTO = new Quota(95, 100); - $mailAccount = $this->createConfiguredMock(MailAccount::class, [ - 'canAuthenticateImap' => true, - ]); + $mailAccount = new MailAccount(); + $mailAccount->setId(123); + $mailAccount->setUserId('user123'); + $mailAccount->setInboundPassword('password'); + $mailAccount->setQuotaPercentage(85); $account = $this->createConfiguredMock(Account::class, [ 'getId' => 123, 'getUserId' => 'user123', @@ -250,21 +234,6 @@ public function testQuotaWithNotification(): void { ->expects(self::once()) ->method('getQuota') ->willReturn($quotaDTO); - $account->expects(self::once()) - ->method('calculateAndSetQuotaPercentage') - ->with($quotaDTO); - $account->expects(self::exactly(3)) - ->method('getMailAccount') - ->willReturn($mailAccount); - $account->expects(self::once()) - ->method('getQuotaPercentage') - ->willReturn($newQuota); - $account->expects(self::exactly(2)) - ->method('getUserId') - ->willReturn('user123'); - $account->expects(self::exactly(2)) - ->method('getEmail') - ->willReturn('user123@test.com'); $this->serviceMock->getParameter('accountService') ->expects(self::once()) ->method('update') @@ -325,12 +294,12 @@ public function testQuotaWithNotification(): void { } public function testQuotaZero(): void { - $oldQuota = 0; - $newQuota = 0; $quotaDTO = new Quota(0, 0); - $mailAccount = $this->createConfiguredMock(MailAccount::class, [ - 'canAuthenticateImap' => true, - ]); + $mailAccount = new MailAccount(); + $mailAccount->setId(123); + $mailAccount->setUserId('user123'); + $mailAccount->setInboundPassword('password'); + $mailAccount->setQuotaPercentage(0); $account = $this->createConfiguredMock(Account::class, [ 'getId' => 123, 'getUserId' => 'user123', @@ -357,15 +326,6 @@ public function testQuotaZero(): void { ->expects(self::once()) ->method('getQuota') ->willReturn($quotaDTO); - $account->expects(self::once()) - ->method('calculateAndSetQuotaPercentage') - ->with($quotaDTO); - $account->expects(self::exactly(3)) - ->method('getMailAccount') - ->willReturn($mailAccount); - $account->expects(self::once()) - ->method('getQuotaPercentage') - ->willReturn($newQuota); $this->serviceMock->getParameter('accountService') ->expects(self::once()) ->method('update')