From 47d7378db6c6351c01f6f886796c0ed70e0ed3ba Mon Sep 17 00:00:00 2001
From: the-djmaze <>
Date: Fri, 30 Oct 2026 20:45:54 +0100
Subject: [PATCH] Nextcloud 32+ #2055
---
.../nextcloud/snappymail/appinfo/info.xml | 6 ++--
.../snappymail/lib/AppInfo/Application.php | 25 +++++++------
.../snappymail/lib/Command/Settings.php | 4 +--
.../lib/Controller/FetchController.php | 34 ++++++++++--------
.../lib/Controller/PageController.php | 20 ++++++++---
.../snappymail/lib/Migration/InstallStep.php | 32 +++++++++++------
.../snappymail/lib/Settings/AdminSettings.php | 36 ++++++++++++++-----
.../snappymail/lib/Util/SnappyMailHelper.php | 9 ++++-
8 files changed, 112 insertions(+), 54 deletions(-)
diff --git a/integrations/nextcloud/snappymail/appinfo/info.xml b/integrations/nextcloud/snappymail/appinfo/info.xml
index d85ad52ed..5f25f2e54 100644
--- a/integrations/nextcloud/snappymail/appinfo/info.xml
+++ b/integrations/nextcloud/snappymail/appinfo/info.xml
@@ -40,7 +40,7 @@ There, click on the link to go to the SnappyMail admin panel.
https://github.com/the-djmaze/snappymail/tree/master/integrations/nextcloud
https://github.com/the-djmaze/snappymail/issues
-
+
mbstring
zlib
-
+
OCA\SnappyMail\Settings\AdminSettings
diff --git a/integrations/nextcloud/snappymail/lib/AppInfo/Application.php b/integrations/nextcloud/snappymail/lib/AppInfo/Application.php
index a6635f252..ce417562a 100644
--- a/integrations/nextcloud/snappymail/lib/AppInfo/Application.php
+++ b/integrations/nextcloud/snappymail/lib/AppInfo/Application.php
@@ -5,7 +5,6 @@ namespace OCA\SnappyMail\AppInfo;
use OCA\SnappyMail\Util\SnappyMailHelper;
use OCA\SnappyMail\Controller\FetchController;
use OCA\SnappyMail\Controller\PageController;
-use OCA\SnappyMail\Dashboard\UnreadMailWidget;
use OCA\SnappyMail\Search\Provider;
use OCA\SnappyMail\Listeners\AccessTokenUpdatedListener;
@@ -13,12 +12,13 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
-use OCP\IL10N;
-use OCP\IUser;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\BeforeUserLoggedOutEvent;
+
use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent;
+use Psr\Container\ContainerInterface;
+
class Application extends App implements IBootstrap
{
public const APP_ID = 'snappymail';
@@ -30,26 +30,27 @@ class Application extends App implements IBootstrap
public function register(IRegistrationContext $context): void
{
+// SnappyMailHelper::$server = $c->query('ServerContainer');
+
/**
* Controllers
*/
$context->registerService(
- 'PageController', function($c) {
+ 'PageController', function(ContainerInterface $c) {
return new PageController(
$c->query('AppName'),
- $c->query('Request')
+ $c->query('Request'),
+ $c
);
}
);
$context->registerService(
- 'FetchController', function($c) {
+ 'FetchController', function(ContainerInterface $c) {
return new FetchController(
$c->query('AppName'),
$c->query('Request'),
- $c->getServer()->getAppManager(),
- $c->query('ServerContainer')->getConfig(),
- $c->query(IL10N::class)
+ $c
);
}
);
@@ -67,16 +68,18 @@ class Application extends App implements IBootstrap
$context->registerEventListener(AccessTokenUpdatedEvent::class, AccessTokenUpdatedListener::class);
// TODO: Not working yet, needs a Vue UI
-// $context->registerDashboardWidget(UnreadMailWidget::class);
+// $context->registerDashboardWidget(\OCA\SnappyMail\Dashboard\UnreadMailWidget::class);
}
public function boot(IBootContext $context): void
{
+// SnappyMailHelper::$server = $context->getServerContainer();
+
if (!\is_dir(\rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
return;
}
- $dispatcher = $context->getAppContainer()->query('OCP\EventDispatcher\IEventDispatcher');
+ $dispatcher = $context->getAppContainer()->query(\OCP\EventDispatcher\IEventDispatcher::class);
$dispatcher->addListener(PostLoginEvent::class, function (PostLoginEvent $Event) {
/*
// Only store the user's password in the current session if they have
diff --git a/integrations/nextcloud/snappymail/lib/Command/Settings.php b/integrations/nextcloud/snappymail/lib/Command/Settings.php
index 1e6cae25d..2843d9f3b 100644
--- a/integrations/nextcloud/snappymail/lib/Command/Settings.php
+++ b/integrations/nextcloud/snappymail/lib/Command/Settings.php
@@ -3,14 +3,14 @@
namespace OCA\SnappyMail\Command;
use OCA\SnappyMail\Util\SnappyMailHelper;
-use OC\Core\Command\Base;
use OCP\IConfig;
use OCP\IUserManager;
+use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-class Settings extends Base
+class Settings extends Command
{
protected IUserManager $userManager;
protected IConfig $config;
diff --git a/integrations/nextcloud/snappymail/lib/Controller/FetchController.php b/integrations/nextcloud/snappymail/lib/Controller/FetchController.php
index 385710e91..66d3724e9 100644
--- a/integrations/nextcloud/snappymail/lib/Controller/FetchController.php
+++ b/integrations/nextcloud/snappymail/lib/Controller/FetchController.php
@@ -11,26 +11,27 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
-class FetchController extends Controller {
+class FetchController extends Controller
+{
private IConfig $config;
- private IAppManager $appManager;
- private IL10N $l;
+ private IL10N $l10n;
- public function __construct(string $appName, IRequest $request, IAppManager $appManager, IConfig $config, IL10N $l) {
+ public function __construct(string $appName, IRequest $request, \Psr\Container\ContainerInterface $container)
+ {
parent::__construct($appName, $request);
- $this->config = $config;
- $this->appManager = $appManager;
- $this->l = $l;
+ $this->config = $container->query(IConfig::class);
+ $this->l10n = $container->query(IL10N::class);
}
- public function upgrade(): JSONResponse {
+ public function upgrade(): JSONResponse
+ {
$error = 'Upgrade failed';
try {
SnappyMailHelper::loadApp();
if (\SnappyMail\Upgrade::core()) {
return new JSONResponse([
'status' => 'success',
- 'Message' => $this->l->t('Upgraded successfully')
+ 'Message' => $this->l10n->t('Upgraded successfully')
]);
}
} catch (Exception $e) {
@@ -42,7 +43,8 @@ class FetchController extends Controller {
]);
}
- public function setAdmin(): JSONResponse {
+ public function setAdmin(): JSONResponse
+ {
try {
$sUrl = '';
$sPath = '';
@@ -57,7 +59,7 @@ class FetchController extends Controller {
} else {
return new JSONResponse([
'status' => 'error',
- 'Message' => $this->l->t('Invalid argument(s)')
+ 'Message' => $this->l10n->t('Invalid argument(s)')
]);
}
@@ -87,7 +89,7 @@ class FetchController extends Controller {
return new JSONResponse([
'status' => 'success',
- 'Message' => $this->l->t('Saved successfully')
+ 'Message' => $this->l10n->t('Saved successfully')
]);
} catch (Exception $e) {
return new JSONResponse([
@@ -100,11 +102,13 @@ class FetchController extends Controller {
/**
* @NoAdminRequired
*/
- public function setPersonal(): JSONResponse {
+ public function setPersonal(): JSONResponse
+ {
try {
$sEmail = '';
if (isset($_POST['appname'], $_POST['snappymail-password'], $_POST['snappymail-email']) && 'snappymail' === $_POST['appname']) {
$sUser = SnappyMailHelper::getUID();
+// $sUser = $this->userSession->getUser()?->getUID();
if ($sUser) {
$sEmail = $_POST['snappymail-email'];
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
@@ -118,7 +122,7 @@ class FetchController extends Controller {
} else {
return new JSONResponse([
'status' => 'error',
- 'Message' => $this->l->t('Invalid argument(s)'),
+ 'Message' => $this->l10n->t('Invalid argument(s)'),
'Email' => $sEmail
]);
}
@@ -129,7 +133,7 @@ class FetchController extends Controller {
return new JSONResponse([
'status' => 'success',
- 'Message' => $this->l->t('Saved successfully'),
+ 'Message' => $this->l10n->t('Saved successfully'),
'Email' => $sEmail
]);
} catch (Exception $e) {
diff --git a/integrations/nextcloud/snappymail/lib/Controller/PageController.php b/integrations/nextcloud/snappymail/lib/Controller/PageController.php
index 17295860b..e78b3d5fc 100644
--- a/integrations/nextcloud/snappymail/lib/Controller/PageController.php
+++ b/integrations/nextcloud/snappymail/lib/Controller/PageController.php
@@ -8,16 +8,28 @@ use OCA\SnappyMail\ContentSecurityPolicy;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\INavigationManager;
+use OCP\IRequest;
+
class PageController extends Controller
{
+ private IConfig $config;
+ private INavigationManager $navigationManager;
+
+ public function __construct($appName, IRequest $request, \Psr\Container\ContainerInterface $container)
+ {
+ parent::__construct($appName, $request);
+ $this->config = $container->query(IConfig::class);
+ $this->navigationManager = $container->query(INavigationManager::class);
+ }
+
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index()
{
- $nav = SnappyMailHelper::getNavigationManager();
-
$bAdmin = false;
if (!empty($_SERVER['QUERY_STRING'])) {
SnappyMailHelper::loadApp();
@@ -28,7 +40,7 @@ class PageController extends Controller
}
if (!$bAdmin && SnappyMailHelper::getAppConfigValue('snappymail-no-embed')) {
- $nav->setActiveEntry('snappymail');
+ $this->navigationManager->setActiveEntry('snappymail');
\OCP\Util::addScript('snappymail', 'snappymail');
\OCP\Util::addStyle('snappymail', 'style');
SnappyMailHelper::startApp();
@@ -43,7 +55,7 @@ class PageController extends Controller
return $response;
}
- $nav->setActiveEntry('snappymail');
+ $this->navigationManager->setActiveEntry('snappymail');
\OCP\Util::addStyle('snappymail', 'embed');
diff --git a/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php b/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php
index 966ef2352..247d9d405 100644
--- a/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php
+++ b/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php
@@ -3,10 +3,13 @@
namespace OCA\SnappyMail\Migration;
use OCA\SnappyMail\AppInfo\Application;
+
+use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
-use OCP\ILogger;
+
+use Psr\Log\LoggerInterface;
/**
* Note: this is not run at install, but when:
@@ -15,11 +18,24 @@ use OCP\ILogger;
*/
class InstallStep implements IRepairStep
{
- public function getName() {
+ private IAppManager $appManager;
+ private IConfig $config;
+ private LoggerInterface $logger;
+
+ public function __construct(IAppManager $appManager, IConfig $config, LoggerInterface $logger)
+ {
+ $this->appManager = $appManager;
+ $this->config = $config;
+ $this->logger = $logger;
+ }
+
+ public function getName()
+ {
return 'Setup SnappyMail';
}
- public function run(IOutput $output) {
+ public function run(IOutput $output)
+ {
$output->info('clearstatcache');
\clearstatcache();
@@ -53,7 +69,7 @@ class InstallStep implements IRepairStep
if (!$oConfig->Get('webmail', 'app_path')) {
$output->info('Set config [webmail]app_path');
- $oConfig->Set('webmail', 'app_path', \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/');
+ $oConfig->Set('webmail', 'app_path', $this->appManager->getAppWebPath('snappymail') . '/app/');
$oConfig->Set('webmail', 'allow_languages_on_settings', false);
$oConfig->Set('login', 'allow_languages_on_login', false);
$bSave = true;
@@ -116,9 +132,7 @@ class InstallStep implements IRepairStep
// ex: php occ config:app:set snappymail custom_config_file --value="/path/to/config.php"
// https://github.com/the-djmaze/snappymail/pull/1197
try {
- /** @var IConfig $ncConfig */
- $ncConfig = \OC::$server->get(IConfig::class);
- $customConfigFile = $ncConfig->getAppValue(Application::APP_ID, 'custom_config_file');
+ $customConfigFile = $this->config->getAppValue(Application::APP_ID, 'custom_config_file');
if ($customConfigFile) {
$output->info("Load custom config: {$customConfigFile}");
if (!\str_contains($customConfigFile, ':') && \is_readable($customConfigFile)) {
@@ -129,9 +143,7 @@ class InstallStep implements IRepairStep
}
} catch (\Throwable $e) {
$output->warning("custom config error: " . $e->getMessage());
- /** @var \Psr\Log\LoggerInterface $logger */
- $logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
- $logger->error("custom config error: " . $e->getMessage());
+ $this->logger->error("custom config error: " . $e->getMessage());
}
}
}
diff --git a/integrations/nextcloud/snappymail/lib/Settings/AdminSettings.php b/integrations/nextcloud/snappymail/lib/Settings/AdminSettings.php
index 580b9b3c3..eea9f49a8 100644
--- a/integrations/nextcloud/snappymail/lib/Settings/AdminSettings.php
+++ b/integrations/nextcloud/snappymail/lib/Settings/AdminSettings.php
@@ -6,13 +6,32 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;
+use OCP\IUserSession;
+use OCP\IGroupManager;
+use OCP\IURLGenerator;
+use OCP\App\IAppManager;
+use OCP\Util;
+
class AdminSettings implements ISettings
{
- private $config;
+ private IConfig $config;
+ private IUserSession $userSession;
+ private IGroupManager $groupManager;
+ private IURLGenerator $urlGenerator;
+ private IAppManager $appManager;
- public function __construct(IConfig $config)
- {
+ public function __construct(
+ IConfig $config,
+ IUserSession $userSession,
+ IGroupManager $groupManager,
+ IURLGenerator $urlGenerator,
+ IAppManager $appManager
+ ) {
$this->config = $config;
+ $this->userSession = $userSession;
+ $this->groupManager = $groupManager;
+ $this->urlGenerator = $urlGenerator;
+ $this->appManager = $appManager;
}
public function getForm()
@@ -29,12 +48,13 @@ class AdminSettings implements ISettings
foreach ($keys as $k) {
$parameters[$k] = $this->config->getAppValue('snappymail', $k);
}
- $uid = SnappyMailHelper::getUID();
- if (\OC_User::isAdminUser($uid)) {
+
+ $uid = $this->userSession->getUser()?->getUID();
+ if ($uid && $this->groupManager->isAdmin($uid)) {
// $parameters['snappymail-admin-panel-link'] = SnappyMailHelper::getAppUrl().'?admin';
SnappyMailHelper::loadApp();
$parameters['snappymail-admin-panel-link'] =
- \OC::$server->getURLGenerator()->linkToRoute('snappymail.page.index')
+ $this->urlGenerator->linkToRoute('snappymail.page.index')
. '?' . \RainLoop\Api::Config()->Get('security', 'admin_panel_key', 'admin');
}
@@ -48,7 +68,7 @@ class AdminSettings implements ISettings
$parameters['snappymail-admin-password'] = $sPassword;
$parameters['can-import-rainloop'] = $sPassword && \is_dir(
- \rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/')
+ \rtrim(\trim($this->config->getSystemValue('datadirectory', '')), '\\/')
. '/rainloop-storage'
);
@@ -64,7 +84,7 @@ class AdminSettings implements ISettings
// Prevent "Failed loading /nextcloud/snappymail/v/2.N.N/static/js/min/libs.min.js"
$app_path = $oConfig->Get('webmail', 'app_path');
if (!$app_path) {
- $app_path = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/';
+ $app_path = $this->appManager->getAppWebPath('snappymail') . '/app/';
$oConfig->Set('webmail', 'app_path', $app_path);
$oConfig->Set('webmail', 'theme', 'NextcloudV25+');
$oConfig->Save();
diff --git a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php
index bf3339016..43b03a664 100644
--- a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php
+++ b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php
@@ -25,6 +25,13 @@ class SnappyMailResponse extends \OCP\AppFramework\Http\Response
class SnappyMailHelper
{
+ public static $server;
+
+ public static function getServerContainer(): object
+ {
+ return static::$server || \OC::$server;
+ }
+
public static function getConfig(): object
{
return \method_exists(\OC::$server, 'getConfig')
@@ -60,7 +67,7 @@ class SnappyMailHelper
public static function getUID(): mixed
{
- return static::getUser()->getUID();
+ return static::getUser()?->getUID();
}
public static function getUser(): object