diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2021-01-27 18:54:37 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-02-26 18:36:46 +0300 |
commit | 82ab9d00075bf00d611e819ef9c3a6cc72c12c26 (patch) | |
tree | d59f99e49ebfe0be9c389ae8aee7311c3d9040d8 /lib/Migration | |
parent | 685580fff2859112bc1dd37b3823f0ada0950811 (diff) |
Add Sieve support
* Expose managesieve port
* Add sieve client factory
* Add support for sieve to provisioning
* Refactor test connectivity logic and add sieve.
* Add support for sieve to provisioning
* Add sieve to account form
* Add debug logger for ManageSieve
* Add api to get and update active script
* Add error for managesieve exception
* Add text editor to update existing script
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Migration')
-rw-r--r-- | lib/Migration/AddSieveToProvisioningConfig.php | 85 | ||||
-rw-r--r-- | lib/Migration/Version1090Date20210127160127.php | 56 |
2 files changed, 141 insertions, 0 deletions
diff --git a/lib/Migration/AddSieveToProvisioningConfig.php b/lib/Migration/AddSieveToProvisioningConfig.php new file mode 100644 index 000000000..e871ff1cc --- /dev/null +++ b/lib/Migration/AddSieveToProvisioningConfig.php @@ -0,0 +1,85 @@ +<?php + +declare(strict_types=1); + +/** + * @author Daniel Kesselberg <mail@danielkesselberg.de> + * + * Mail + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\Mail\Migration; + +use OCA\Mail\Service\Provisioning\Config as ProvisioningConfig; +use OCA\Mail\Service\Provisioning\ConfigMapper as ProvisioningConfigMapper; +use OCP\IConfig; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class AddSieveToProvisioningConfig implements IRepairStep { + + /** @var IConfig */ + private $config; + + /** @var ProvisioningConfigMapper */ + private $configMapper; + + public function __construct(IConfig $config, ProvisioningConfigMapper $configMapper) { + $this->config = $config; + $this->configMapper = $configMapper; + } + + public function getName(): string { + return 'Add sieve defaults to provisioning config'; + } + + public function run(IOutput $output) { + if (!$this->shouldRun()) { + return; + } + + $config = $this->configMapper->load(); + if ($config === null) { + return; + } + + $reflectionClass = new \ReflectionClass(ProvisioningConfig::class); + $reflectionProperty = $reflectionClass->getProperty('data'); + + $reflectionProperty->setAccessible(true); + $data = $reflectionProperty->getValue($config); + + if (!isset($data['sieveEnabled'])) { + $data = array_merge($data, [ + 'sieveEnabled' => false, + 'sieveHost' => '', + 'sievePort' => 4190, + 'sieveUser' => '', + 'sieveSslMode' => 'tls', + ]); + } + + $reflectionProperty->setValue($config, $data); + $this->configMapper->save($config); + + $output->info('added sieve defaults to provisioning config'); + } + + protected function shouldRun(): bool { + $appVersion = $this->config->getAppValue('mail', 'installed_version', '0.0.0'); + return version_compare($appVersion, '1.9.0', '<'); + } +} diff --git a/lib/Migration/Version1090Date20210127160127.php b/lib/Migration/Version1090Date20210127160127.php new file mode 100644 index 000000000..8a52ae4fc --- /dev/null +++ b/lib/Migration/Version1090Date20210127160127.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace OCA\Mail\Migration; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version1090Date20210127160127 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('mail_accounts'); + $table->addColumn('sieve_enabled', 'boolean', [ + 'notnull' => true, + 'default' => false, + ]); + $table->addColumn('sieve_host', 'string', [ + 'notnull' => false, + 'length' => 64, + 'default' => null, + ]); + $table->addColumn('sieve_port', 'string', [ + 'notnull' => false, + 'length' => 6, + 'default' => null, + ]); + $table->addColumn('sieve_ssl_mode', 'string', [ + 'notnull' => false, + 'length' => 10, + 'default' => null, + ]); + $table->addColumn('sieve_user', 'string', [ + 'notnull' => false, + 'length' => 64, + 'default' => null, + ]); + $table->addColumn('sieve_password', 'string', [ + 'notnull' => false, + 'length' => 2048, + 'default' => null, + ]); + + return $schema; + } +} |