Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The rating depends on the installed text processing backend. See [the rating ove

Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud.com/blog/nextcloud-ethical-ai-rating/).
]]></description>
<version>5.6.0-alpha.3</version>
<version>5.6.0-alpha.4</version>
<licence>agpl</licence>
<author homepage="https://github.com/ChristophWurst">Christoph Wurst</author>
<author homepage="https://github.com/GretaD">GretaD</author>
Expand Down
5 changes: 0 additions & 5 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,6 @@
'url' => '/api/settings/llm',
'verb' => 'PUT'
],
[
'name' => 'settings#setImportanceClassificationEnabledByDefault',
'url' => '/api/settings/importance-classification-default',
'verb' => 'PUT'
],
[
'name' => 'settings#setLayoutMessageView',
'url' => '/api/settings/layout-message-view',
Expand Down
4 changes: 4 additions & 0 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ public function calculateAndSetQuotaPercentage(Quota $quota): void {
public function getQuotaPercentage(): ?int {
return $this->account->getQuotaPercentage();
}

public function getClassificationEnabled(): bool {
return $this->account->getClassificationEnabled();
}
}
8 changes: 2 additions & 6 deletions lib/BackgroundJob/TrainImportanceClassifierJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OCA\Mail\BackgroundJob;

use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\Classification\ClassificationSettingsService;
use OCA\Mail\Service\Classification\ImportanceClassifier;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
Expand All @@ -24,21 +23,18 @@ class TrainImportanceClassifierJob extends TimedJob {
private ImportanceClassifier $classifier;
private IJobList $jobList;
private LoggerInterface $logger;
private ClassificationSettingsService $classificationSettingsService;

public function __construct(ITimeFactory $time,
AccountService $accountService,
ImportanceClassifier $classifier,
IJobList $jobList,
LoggerInterface $logger,
ClassificationSettingsService $classificationSettingsService) {
LoggerInterface $logger) {
parent::__construct($time);

$this->accountService = $accountService;
$this->classifier = $classifier;
$this->jobList = $jobList;
$this->logger = $logger;
$this->classificationSettingsService = $classificationSettingsService;

$this->setInterval(24 * 60 * 60);
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
Expand All @@ -64,7 +60,7 @@ protected function run($argument) {
return;
}

if (!$this->classificationSettingsService->isClassificationEnabled($account->getUserId())) {
if (!$account->getClassificationEnabled()) {
$this->logger->debug("classification is turned off for account $accountId");
return;
}
Expand Down
6 changes: 1 addition & 5 deletions lib/Command/TrainAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OCA\Mail\Command;

use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\Classification\ClassificationSettingsService;
use OCA\Mail\Service\Classification\ImportanceClassifier;
use OCA\Mail\Support\ConsoleLoggerDecorator;
use OCP\AppFramework\Db\DoesNotExistException;
Expand All @@ -30,18 +29,15 @@ final class TrainAccount extends Command {
private AccountService $accountService;
private ImportanceClassifier $classifier;
private LoggerInterface $logger;
private ClassificationSettingsService $classificationSettingsService;

public function __construct(AccountService $service,
ImportanceClassifier $classifier,
ClassificationSettingsService $classificationSettingsService,
LoggerInterface $logger) {
parent::__construct();

$this->accountService = $service;
$this->classifier = $classifier;
$this->logger = $logger;
$this->classificationSettingsService = $classificationSettingsService;
}

protected function configure(): void {
Expand Down Expand Up @@ -76,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (!$force && !$this->classificationSettingsService->isClassificationEnabled($account->getUserId())) {
if (!$force && !$account->getClassificationEnabled()) {
$output->writeln("<info>classification is turned off for account $accountId</info>");
return 2;
}
Expand Down
13 changes: 10 additions & 3 deletions lib/Controller/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function update(int $id,
* @param int|null $archiveMailboxId
* @param int|null $snoozeMailboxId
* @param bool|null $signatureAboveQuote
* @param bool|null $classificationEnabled
*
* @return JSONResponse
*
Expand All @@ -229,7 +230,8 @@ public function patchAccount(int $id,
?bool $signatureAboveQuote = null,
?int $trashRetentionDays = null,
?int $junkMailboxId = null,
?bool $searchBody = null): JSONResponse {
?bool $searchBody = null,
?bool $classificationEnabled = null): JSONResponse {
$account = $this->accountService->find($this->currentUserId, $id);

$dbAccount = $account->getMailAccount();
Expand Down Expand Up @@ -277,6 +279,9 @@ public function patchAccount(int $id,
if ($searchBody !== null) {
$dbAccount->setSearchBody($searchBody);
}
if ($classificationEnabled !== null) {
$dbAccount->setClassificationEnabled($classificationEnabled);
}
return new JSONResponse(
new Account($this->accountService->save($dbAccount))
);
Expand Down Expand Up @@ -330,6 +335,7 @@ public function destroy(int $id): JSONResponse {
* @param string|null $smtpUser
* @param string|null $smtpPassword
* @param string $authMethod
* @param bool|null $classificationEnabled
*
* @return JSONResponse
*/
Expand All @@ -346,7 +352,8 @@ public function create(string $accountName,
?string $smtpSslMode = null,
?string $smtpUser = null,
?string $smtpPassword = null,
string $authMethod = 'password'): JSONResponse {
string $authMethod = 'password',
?bool $classificationEnabled = null): JSONResponse {
if ($this->config->getAppValue(Application::APP_ID, 'allow_new_mail_accounts', 'yes') === 'no') {
$this->logger->info('Creating account disabled by admin.');
return MailJsonResponse::error('Could not create account');
Expand Down Expand Up @@ -378,7 +385,7 @@ public function create(string $accountName,
);
}
try {
$account = $this->setup->createNewAccount($accountName, $emailAddress, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $this->currentUserId, $authMethod);
$account = $this->setup->createNewAccount($accountName, $emailAddress, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $this->currentUserId, $authMethod, null, $classificationEnabled);
} catch (CouldNotConnectException $e) {
$data = [
'error' => $e->getReason(),
Expand Down
5 changes: 0 additions & 5 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\AiIntegrations\AiIntegrationsService;
use OCA\Mail\Service\AliasesService;
use OCA\Mail\Service\Classification\ClassificationSettingsService;
use OCA\Mail\Service\InternalAddressService;
use OCA\Mail\Service\OutboxService;
use OCA\Mail\Service\QuickActionsService;
Expand Down Expand Up @@ -71,7 +70,6 @@ class PageController extends Controller {
private AiIntegrationsService $aiIntegrationsService;
private IUserManager $userManager;
private IAvailabilityCoordinator $availabilityCoordinator;
private ClassificationSettingsService $classificationSettingsService;
private InternalAddressService $internalAddressService;
private QuickActionsService $quickActionsService;

Expand All @@ -95,7 +93,6 @@ public function __construct(
SmimeService $smimeService,
AiIntegrationsService $aiIntegrationsService,
IUserManager $userManager,
ClassificationSettingsService $classificationSettingsService,
InternalAddressService $internalAddressService,
IAvailabilityCoordinator $availabilityCoordinator,
QuickActionsService $quickActionsService,
Expand All @@ -120,7 +117,6 @@ public function __construct(
$this->smimeService = $smimeService;
$this->aiIntegrationsService = $aiIntegrationsService;
$this->userManager = $userManager;
$this->classificationSettingsService = $classificationSettingsService;
$this->internalAddressService = $internalAddressService;
$this->availabilityCoordinator = $availabilityCoordinator;
$this->quickActionsService = $quickActionsService;
Expand Down Expand Up @@ -226,7 +222,6 @@ public function index(): TemplateResponse {
'collect-data' => $this->preferences->getPreference($this->currentUserId, 'collect-data', 'true'),
'search-priority-body' => $this->preferences->getPreference($this->currentUserId, 'search-priority-body', 'false'),
'start-mailbox-id' => $this->preferences->getPreference($this->currentUserId, 'start-mailbox-id'),
'tag-classified-messages' => $this->classificationSettingsService->isClassificationEnabled($this->currentUserId) ? 'true' : 'false',
'follow-up-reminders' => $this->preferences->getPreference($this->currentUserId, 'follow-up-reminders', 'true'),
]);
$this->initialStateService->provideInitialState(
Expand Down
12 changes: 1 addition & 11 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OCA\Mail\Exception\ValidationException;
use OCA\Mail\Http\JsonResponse as HttpJsonResponse;
use OCA\Mail\Service\AntiSpamService;
use OCA\Mail\Service\Classification\ClassificationSettingsService;
use OCA\Mail\Service\Provisioning\Manager as ProvisioningManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\OpenAPI;
Expand All @@ -30,20 +29,17 @@ class SettingsController extends Controller {
private AntiSpamService $antiSpamService;
private ContainerInterface $container;
private IConfig $config;
private ClassificationSettingsService $classificationSettingsService;

public function __construct(IRequest $request,
ProvisioningManager $provisioningManager,
AntiSpamService $antiSpamService,
IConfig $config,
ContainerInterface $container,
ClassificationSettingsService $classificationSettingsService) {
ContainerInterface $container) {
parent::__construct(Application::APP_ID, $request);
$this->provisioningManager = $provisioningManager;
$this->antiSpamService = $antiSpamService;
$this->config = $config;
$this->container = $container;
$this->classificationSettingsService = $classificationSettingsService;
}

public function index(): JSONResponse {
Expand Down Expand Up @@ -118,12 +114,6 @@ public function setEnabledLlmProcessing(bool $enabled): JSONResponse {
$this->config->setAppValue('mail', 'llm_processing', $enabled ? 'yes' : 'no');
return new JSONResponse([]);
}

public function setImportanceClassificationEnabledByDefault(bool $enabledByDefault): JSONResponse {
$this->classificationSettingsService->setClassificationEnabledByDefault($enabledByDefault);
return new JSONResponse([]);
}

public function setLayoutMessageView(string $value): JSONResponse {
$this->config->setAppValue('mail', 'layout_message_view', $value);
return new JSONResponse([]);
Expand Down
8 changes: 8 additions & 0 deletions lib/Db/MailAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
* @method void setOooFollowsSystem(bool $oooFollowsSystem)
* @method bool getDebug()
* @method void setDebug(bool $debug)
* @method bool getClassificationEnabled()
* @method void setClassificationEnabled(bool $classificationEnabled)
*/
class MailAccount extends Entity {
public const SIGNATURE_MODE_PLAIN = 0;
Expand Down Expand Up @@ -186,6 +188,7 @@ class MailAccount extends Entity {
protected $oooFollowsSystem;

protected bool $debug = false;
protected bool $classificationEnabled = true;

/**
* @param array $params
Expand Down Expand Up @@ -247,6 +250,9 @@ public function __construct(array $params = []) {
if (isset($params['debug'])) {
$this->setDebug($params['debug']);
}
if (isset($params['classificationEnabled'])) {
$this->setClassificationEnabled($params['classificationEnabled']);
}

$this->addType('inboundPort', 'integer');
$this->addType('outboundPort', 'integer');
Expand All @@ -271,6 +277,7 @@ public function __construct(array $params = []) {
$this->addType('searchBody', 'boolean');
$this->addType('oooFollowsSystem', 'boolean');
$this->addType('debug', 'boolean');
$this->addType('classificationEnabled', 'boolean');
}

public function getOutOfOfficeFollowsSystem(): bool {
Expand Down Expand Up @@ -319,6 +326,7 @@ public function toJson() {
'searchBody' => $this->getSearchBody(),
'outOfOfficeFollowsSystem' => $this->getOutOfOfficeFollowsSystem(),
'debug' => $this->getDebug(),
'classificationEnabled' => $this->getClassificationEnabled(),
];

if (!is_null($this->getOutboundHost())) {
Expand Down
38 changes: 38 additions & 0 deletions lib/Migration/Version5006Date20251024153423.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version5006Date20251024153423 extends SimpleMigrationStep {


/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
#[Override]

Check failure on line 27 in lib/Migration/Version5006Date20251024153423.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

UndefinedAttributeClass

lib/Migration/Version5006Date20251024153423.php:27:4: UndefinedAttributeClass: Attribute class OCA\Mail\Migration\Override does not exist (see https://psalm.dev/241)

Check failure on line 27 in lib/Migration/Version5006Date20251024153423.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedAttributeClass

lib/Migration/Version5006Date20251024153423.php:27:4: UndefinedAttributeClass: Attribute class OCA\Mail\Migration\Override does not exist (see https://psalm.dev/241)

Check failure on line 27 in lib/Migration/Version5006Date20251024153423.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

UndefinedAttributeClass

lib/Migration/Version5006Date20251024153423.php:27:4: UndefinedAttributeClass: Attribute class OCA\Mail\Migration\Override does not exist (see https://psalm.dev/241)
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();
$accountsTable = $schema->getTable('mail_accounts');
if (!$accountsTable->hasColumn('classification_enabled')) {
$accountsTable->addColumn('classification_enabled', Types::BOOLEAN, [
'default' => true,
]);
}
return $schema;
}
}
63 changes: 0 additions & 63 deletions lib/Service/Classification/ClassificationSettingsService.php

This file was deleted.

Loading
Loading