Migrate to Nextcloud 20's bootstrap mechanism
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Родитель
acdf45fbba
Коммит
8ade2cf588
|
@ -30,10 +30,6 @@ matrix:
|
|||
env: "TEST_SUITE=PACKAGE"
|
||||
- php: 7.2
|
||||
env: "PHP_COVERAGE=TRUE"
|
||||
- php: 7.3
|
||||
env: "CORE_BRANCH=stable18"
|
||||
- php: 7.4
|
||||
env: "CORE_BRANCH=stable19"
|
||||
- php: nightly
|
||||
env: "DB=sqlite PATCH_VERSION_CHECK=TRUE"
|
||||
fast_finish: true
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
||||
* @author Thomas Imbreckx <zinks@iozero.be>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* 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/>
|
||||
*
|
||||
*/
|
||||
use OCA\Mail\HordeTranslationHandler;
|
||||
|
||||
if ((@include_once __DIR__ . '/../vendor/autoload.php')===false) {
|
||||
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
|
||||
}
|
||||
|
||||
// bypass Horde Translation system
|
||||
Horde_Translation::setHandler('Horde_Imap_Client', new HordeTranslationHandler());
|
||||
Horde_Translation::setHandler('Horde_Mime', new HordeTranslationHandler());
|
||||
Horde_Translation::setHandler('Horde_Smtp', new HordeTranslationHandler());
|
||||
|
||||
$l = \OC::$server->getL10N('mail');
|
||||
$g = \OC::$server->getURLGenerator();
|
||||
|
||||
\OC::$server->getNavigationManager()->add(
|
||||
[
|
||||
'id' => 'mail',
|
||||
'order' => 3,
|
||||
'href' => $g->linkToRoute('mail.page.index'),
|
||||
'icon' => $g->imagePath('mail', 'mail.svg'),
|
||||
'name' => $l->t('Mail'),
|
||||
]
|
||||
);
|
|
@ -31,7 +31,7 @@
|
|||
<screenshot>https://user-images.githubusercontent.com/1374172/79554966-278e1600-809f-11ea-82ea-7a0d72a2704f.png</screenshot>
|
||||
<dependencies>
|
||||
<php min-version="7.2" max-version="7.4" />
|
||||
<nextcloud min-version="18" max-version="20" />
|
||||
<nextcloud min-version="20" max-version="20" />
|
||||
</dependencies>
|
||||
<repair-steps>
|
||||
<post-migration>
|
||||
|
@ -53,4 +53,12 @@
|
|||
<settings>
|
||||
<admin>OCA\Mail\Settings\AdminSettings</admin>
|
||||
</settings>
|
||||
<navigations>
|
||||
<navigation>
|
||||
<name>Mail</name>
|
||||
<route>mail.page.index</route>
|
||||
<icon>mail.svg</icon>
|
||||
<order>3</order>
|
||||
</navigation>
|
||||
</navigations>
|
||||
</info>
|
||||
|
|
|
@ -24,12 +24,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Mail\AppInfo;
|
||||
|
||||
use Exception;
|
||||
use Horde_Translation;
|
||||
use OCA\Mail\Contracts\IAttachmentService;
|
||||
use OCA\Mail\Contracts\IAvatarService;
|
||||
use OCA\Mail\Contracts\IMailManager;
|
||||
use OCA\Mail\Contracts\IMailSearch;
|
||||
use OCA\Mail\Contracts\IMailTransmission;
|
||||
use OCA\Mail\Contracts\IUserPreferences;
|
||||
use OCA\Mail\Dashboard\MailWidget;
|
||||
use OCA\Mail\Events\BeforeMessageDeletedEvent;
|
||||
use OCA\Mail\Events\DraftSavedEvent;
|
||||
use OCA\Mail\Events\SynchronizationEvent;
|
||||
|
@ -38,10 +41,10 @@ use OCA\Mail\Events\MessageFlaggedEvent;
|
|||
use OCA\Mail\Events\MessageSentEvent;
|
||||
use OCA\Mail\Events\NewMessagesSynchronized;
|
||||
use OCA\Mail\Events\SaveDraftEvent;
|
||||
use OCA\Mail\HordeTranslationHandler;
|
||||
use OCA\Mail\Http\Middleware\ErrorMiddleware;
|
||||
use OCA\Mail\Http\Middleware\ProvisioningMiddleware;
|
||||
use OCA\Mail\Listener\AddressCollectionListener;
|
||||
use OCA\Mail\Listener\DashboardPanelListener;
|
||||
use OCA\Mail\Listener\DeleteDraftListener;
|
||||
use OCA\Mail\Listener\DraftMailboxCreatorListener;
|
||||
use OCA\Mail\Listener\FlagRepliedMessageListener;
|
||||
|
@ -59,64 +62,67 @@ use OCA\Mail\Service\MailTransmission;
|
|||
use OCA\Mail\Service\Search\MailSearch;
|
||||
use OCA\Mail\Service\UserPreferenceSevice;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
use OCP\Dashboard\RegisterWidgetEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\User\Events\UserDeletedEvent;
|
||||
use OCP\Util;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Application extends App {
|
||||
class Application extends App implements IBootstrap {
|
||||
public const APP_ID = 'mail';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
|
||||
$this->initializeAppContainer($this->getContainer());
|
||||
$this->registerEvents($this->getContainer());
|
||||
}
|
||||
|
||||
private function initializeAppContainer(IAppContainer $container): void {
|
||||
$transport = $container->getServer()->getConfig()->getSystemValue('app.mail.transport', 'smtp');
|
||||
$testSmtp = $transport === 'smtp';
|
||||
public function register(IRegistrationContext $context): void {
|
||||
if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
|
||||
throw new Exception('Cannot include autoload. Did you run install dependencies using composer?');
|
||||
}
|
||||
|
||||
$container->registerAlias(IAvatarService::class, AvatarService::class);
|
||||
$container->registerAlias(IAttachmentService::class, AttachmentService::class);
|
||||
$container->registerAlias(IMailManager::class, MailManager::class);
|
||||
$container->registerAlias(IMailSearch::class, MailSearch::class);
|
||||
$container->registerAlias(IMailTransmission::class, MailTransmission::class);
|
||||
$container->registerAlias(IUserPreferences::class, UserPreferenceSevice::class);
|
||||
$context->registerParameter('hostname', Util::getServerHostName());
|
||||
|
||||
$container->registerService("userFolder", function () use ($container) {
|
||||
$user = $container->query("UserId");
|
||||
return $container->getServer()->getUserFolder($user);
|
||||
$context->registerService('userFolder', function (ContainerInterface $c) {
|
||||
$userContainer = $c->get(IServerContainer::class);
|
||||
$uid = $c->get('UserId');
|
||||
|
||||
return $userContainer->getUserFolder($uid);
|
||||
});
|
||||
|
||||
$container->registerParameter('testSmtp', $testSmtp);
|
||||
$container->registerParameter('hostname', Util::getServerHostName());
|
||||
$context->registerServiceAlias(IAvatarService::class, AvatarService::class);
|
||||
$context->registerServiceAlias(IAttachmentService::class, AttachmentService::class);
|
||||
$context->registerServiceAlias(IMailManager::class, MailManager::class);
|
||||
$context->registerServiceAlias(IMailSearch::class, MailSearch::class);
|
||||
$context->registerServiceAlias(IMailTransmission::class, MailTransmission::class);
|
||||
$context->registerServiceAlias(IUserPreferences::class, UserPreferenceSevice::class);
|
||||
|
||||
$container->registerAlias('ErrorMiddleware', ErrorMiddleware::class);
|
||||
$container->registerMiddleWare('ErrorMiddleware');
|
||||
$container->registerAlias('ProvisioningMiddleware', ProvisioningMiddleware::class);
|
||||
$container->registerMiddleWare('ProvisioningMiddleware');
|
||||
$context->registerEventListener(BeforeMessageDeletedEvent::class, TrashMailboxCreatorListener::class);
|
||||
$context->registerEventListener(DraftSavedEvent::class, DeleteDraftListener::class);
|
||||
$context->registerEventListener(MessageFlaggedEvent::class, MessageCacheUpdaterListener::class);
|
||||
$context->registerEventListener(MessageDeletedEvent::class, MessageCacheUpdaterListener::class);
|
||||
$context->registerEventListener(MessageSentEvent::class, AddressCollectionListener::class);
|
||||
$context->registerEventListener(MessageSentEvent::class, DeleteDraftListener::class);
|
||||
$context->registerEventListener(MessageSentEvent::class, FlagRepliedMessageListener::class);
|
||||
$context->registerEventListener(MessageSentEvent::class, InteractionListener::class);
|
||||
$context->registerEventListener(MessageSentEvent::class, SaveSentMessageListener::class);
|
||||
$context->registerEventListener(NewMessagesSynchronized::class, NewMessageClassificationListener::class);
|
||||
$context->registerEventListener(SaveDraftEvent::class, DraftMailboxCreatorListener::class);
|
||||
$context->registerEventListener(SynchronizationEvent::class, AccountSynchronizedThreadUpdaterListener::class);
|
||||
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
|
||||
|
||||
$context->registerMiddleWare(ErrorMiddleware::class);
|
||||
$context->registerMiddleWare(ProvisioningMiddleware::class);
|
||||
|
||||
$context->registerDashboardWidget(MailWidget::class);
|
||||
|
||||
// bypass Horde Translation system
|
||||
Horde_Translation::setHandler('Horde_Imap_Client', new HordeTranslationHandler());
|
||||
Horde_Translation::setHandler('Horde_Mime', new HordeTranslationHandler());
|
||||
Horde_Translation::setHandler('Horde_Smtp', new HordeTranslationHandler());
|
||||
}
|
||||
|
||||
private function registerEvents(IAppContainer $container): void {
|
||||
/** @var IEventDispatcher $dispatcher */
|
||||
$dispatcher = $container->query(IEventDispatcher::class);
|
||||
|
||||
$dispatcher->addServiceListener(BeforeMessageDeletedEvent::class, TrashMailboxCreatorListener::class);
|
||||
$dispatcher->addServiceListener(DraftSavedEvent::class, DeleteDraftListener::class);
|
||||
$dispatcher->addServiceListener(MessageFlaggedEvent::class, MessageCacheUpdaterListener::class);
|
||||
$dispatcher->addServiceListener(MessageDeletedEvent::class, MessageCacheUpdaterListener::class);
|
||||
$dispatcher->addServiceListener(MessageSentEvent::class, AddressCollectionListener::class);
|
||||
$dispatcher->addServiceListener(MessageSentEvent::class, DeleteDraftListener::class);
|
||||
$dispatcher->addServiceListener(MessageSentEvent::class, FlagRepliedMessageListener::class);
|
||||
$dispatcher->addServiceListener(MessageSentEvent::class, InteractionListener::class);
|
||||
$dispatcher->addServiceListener(MessageSentEvent::class, SaveSentMessageListener::class);
|
||||
$dispatcher->addServiceListener(NewMessagesSynchronized::class, NewMessageClassificationListener::class);
|
||||
$dispatcher->addServiceListener(SaveDraftEvent::class, DraftMailboxCreatorListener::class);
|
||||
$dispatcher->addServiceListener(SynchronizationEvent::class, AccountSynchronizedThreadUpdaterListener::class);
|
||||
$dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class);
|
||||
$dispatcher->addServiceListener(RegisterWidgetEvent::class, DashboardPanelListener::class);
|
||||
public function boot(IBootContext $context): void {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace OCA\Mail\Service\AutoConfig;
|
||||
|
||||
use OCA\Mail\Db\MailAccount;
|
||||
use OCA\Mail\SystemConfig;
|
||||
|
||||
class SmtpServerDetector {
|
||||
|
||||
|
@ -33,20 +34,20 @@ class SmtpServerDetector {
|
|||
/** @var SmtpConnectivityTester */
|
||||
private $smtpConnectivityTester;
|
||||
|
||||
/** @var bool */
|
||||
private $testSmtp;
|
||||
/** @var SystemConfig */
|
||||
private $systemConfig;
|
||||
|
||||
/**
|
||||
* @param MxRecord $mxRecord
|
||||
* @param SmtpConnectivityTester $smtpTester
|
||||
* @param bool $testSmtp
|
||||
* @param
|
||||
*/
|
||||
public function __construct(MxRecord $mxRecord,
|
||||
SmtpConnectivityTester $smtpTester,
|
||||
bool $testSmtp) {
|
||||
SystemConfig $systemConfig) {
|
||||
$this->mxRecord = $mxRecord;
|
||||
$this->smtpConnectivityTester = $smtpTester;
|
||||
$this->testSmtp = $testSmtp;
|
||||
$this->systemConfig = $systemConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,7 +59,7 @@ class SmtpServerDetector {
|
|||
public function detect(MailAccount $account,
|
||||
string $email,
|
||||
string $password): bool {
|
||||
if (!$this->testSmtp) {
|
||||
if (!$this->systemConfig->hasWorkingSmtp()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
|
@ -40,8 +42,8 @@ class UserPreferenceSevice implements IUserPreferences {
|
|||
* @param string $UserId
|
||||
*/
|
||||
public function __construct(IConfig $config, $UserId) {
|
||||
$this->UserId = $UserId;
|
||||
$this->config = $config;
|
||||
$this->UserId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
* @author 2020 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;
|
||||
|
||||
use OCP\IConfig;
|
||||
|
||||
class SystemConfig {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function hasWorkingSmtp(): bool {
|
||||
return $this->config->getSystemValue('app.mail.transport', 'smtp') === 'smtp';
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
|
@ -26,16 +28,20 @@ use OCA\Mail\Db\MailAccount;
|
|||
use OCA\Mail\Service\AutoConfig\MxRecord;
|
||||
use OCA\Mail\Service\AutoConfig\SmtpConnectivityTester;
|
||||
use OCA\Mail\Service\AutoConfig\SmtpServerDetector;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use OCA\Mail\SystemConfig;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class SmtpServerDetectorTest extends TestCase {
|
||||
|
||||
/** @var MxRecord|PHPUnit_Framework_MockObject_MockObject */
|
||||
/** @var MxRecord|MockObject */
|
||||
private $mxRecord;
|
||||
|
||||
/** @var SmtpConnectivityTester|PHPUnit_Framework_MockObject_MockObject */
|
||||
/** @var SmtpConnectivityTester|MockObject */
|
||||
private $smtpConnectivityTester;
|
||||
|
||||
/** @var SystemConfig|MockObject */
|
||||
private $systemConfig;
|
||||
|
||||
/** @var SmtpServerDetector */
|
||||
private $detector;
|
||||
|
||||
|
@ -44,14 +50,22 @@ class SmtpServerDetectorTest extends TestCase {
|
|||
|
||||
$this->mxRecord = $this->createMock(MxRecord::class);
|
||||
$this->smtpConnectivityTester = $this->createMock(SmtpConnectivityTester::class);
|
||||
$this->systemConfig = $this->createMock(SystemConfig::class);
|
||||
|
||||
$this->detector = new SmtpServerDetector($this->mxRecord, $this->smtpConnectivityTester, true);
|
||||
$this->detector = new SmtpServerDetector(
|
||||
$this->mxRecord,
|
||||
$this->smtpConnectivityTester,
|
||||
$this->systemConfig
|
||||
);
|
||||
}
|
||||
|
||||
public function testDetectNo() {
|
||||
$account = $this->createMock(MailAccount::class);
|
||||
$email = 'user@domain.tld';
|
||||
$password = 'mypassword';
|
||||
$this->systemConfig->expects($this->once())
|
||||
->method('hasWorkingSmtp')
|
||||
->willReturn(true);
|
||||
$this->mxRecord->expects($this->once())
|
||||
->method('query')
|
||||
->with($this->equalTo('domain.tld'))
|
||||
|
@ -70,6 +84,9 @@ class SmtpServerDetectorTest extends TestCase {
|
|||
$account = $this->createMock(MailAccount::class);
|
||||
$email = 'user@domain.tld';
|
||||
$password = 'mypassword';
|
||||
$this->systemConfig->expects($this->once())
|
||||
->method('hasWorkingSmtp')
|
||||
->willReturn(true);
|
||||
$this->mxRecord->expects($this->once())
|
||||
->method('query')
|
||||
->with($this->equalTo('domain.tld'))
|
||||
|
@ -88,6 +105,9 @@ class SmtpServerDetectorTest extends TestCase {
|
|||
$account = $this->createMock(MailAccount::class);
|
||||
$email = 'user@domain.tld';
|
||||
$password = 'mypassword';
|
||||
$this->systemConfig->expects($this->once())
|
||||
->method('hasWorkingSmtp')
|
||||
->willReturn(true);
|
||||
$this->mxRecord->expects($this->once())
|
||||
->method('query')
|
||||
->with($this->equalTo('domain.tld'))
|
||||
|
|
Загрузка…
Ссылка в новой задаче