From 8afb1049f7e7058de2b2d8f8dfe10860e78c79e9 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 29 Oct 2026 14:33:17 +0100 Subject: [PATCH] Add some changes for Nextcloud 34+ #2055 --- .../nextcloud/snappymail/app/include.php | 7 +- .../snappymail/lib/ContentSecurityPolicy.php | 6 +- .../app/libraries/RainLoop/Actions/Themes.php | 9 +- .../v/0.0.0/app/libraries/snappymail/log.php | 3 +- .../app/libraries/snappymail/nextcloud.php | 85 +++++++++++++++++++ 5 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 snappymail/v/0.0.0/app/libraries/snappymail/nextcloud.php diff --git a/integrations/nextcloud/snappymail/app/include.php b/integrations/nextcloud/snappymail/app/include.php index 1326ed6b7..0c80bf719 100644 --- a/integrations/nextcloud/snappymail/app/include.php +++ b/integrations/nextcloud/snappymail/app/include.php @@ -28,7 +28,12 @@ * Custom 'data' folder path */ if (class_exists('OC')) { - define('APP_DATA_FOLDER_PATH', \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/'); + define('APP_DATA_FOLDER_PATH', \rtrim(\trim( + \method_exists(\OC::$server, 'getSystemConfig') + ? \OC::$server->getSystemConfig()->getValue('datadirectory', '') + // Nextcloud 34+ + : \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory', '') + ), '\\/') . '/appdata_snappymail/'); } else { http_response_code(400); header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request', true, 400); diff --git a/integrations/nextcloud/snappymail/lib/ContentSecurityPolicy.php b/integrations/nextcloud/snappymail/lib/ContentSecurityPolicy.php index 27a9c44d1..3f90c3c1a 100644 --- a/integrations/nextcloud/snappymail/lib/ContentSecurityPolicy.php +++ b/integrations/nextcloud/snappymail/lib/ContentSecurityPolicy.php @@ -37,7 +37,11 @@ class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy public function getSnappyMailNonce() { static $sNonce; if (!$sNonce) { - $cspManager = \OC::$server->getContentSecurityPolicyNonceManager(); + $cspManager = (\method_exists(\OC::$server, 'getContentSecurityPolicyNonceManager') + ? \OC::$server->getContentSecurityPolicyNonceManager() + // Nextcloud 34+ + : \OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class) + ); $sNonce = $cspManager->getNonce() ?: \SnappyMail\UUID::generate(); if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) { $this->addAllowedScriptDomain("'nonce-{$sNonce}'"); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php index 9d70fbbbd..d5ec47272 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php @@ -3,6 +3,7 @@ namespace RainLoop\Actions; use RainLoop\Enumerations\Capa; +use SnappyMail\Nextcloud; trait Themes { @@ -71,8 +72,8 @@ trait Themes } if (\class_exists('OC', false)) { - $sDir = \OC::$SERVERROOT . '/themes'; // custom user themes - if (\is_dir($sDir) && ($rDirH = \opendir($sDir))) { + $sDir = Nextcloud::themesDir(); + if ($sDir && ($rDirH = \opendir($sDir))) { while (($sFile = \readdir($rDirH)) !== false) { if ('.' !== $sFile[0] && \is_dir("{$sDir}/{$sFile}") && \file_exists("{$sDir}/{$sFile}/snappymail/style.css")) { $aCache[] = $sFile . '@nextcloud'; @@ -113,8 +114,8 @@ trait Themes $bLess = false; if ('@nextcloud' === \substr($sTheme, -10)) { - $sBase = \OC::$WEBROOT . '/'; - $sThemeCSSFile = \OC::$SERVERROOT . '/themes/' . \str_replace('@nextcloud', '/snappymail/style.css', $sTheme); + $sBase = Nextcloud::webRoot() . '/'; + $sThemeCSSFile = Nextcloud::themesDir() . '/' . \str_replace('@nextcloud', '/snappymail/style.css', $sTheme); } else { $bCustomTheme = '@custom' === \substr($sTheme, -7); if ($bCustomTheme) { diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/log.php b/snappymail/v/0.0.0/app/libraries/snappymail/log.php index a3c4db69f..9f40dcb6f 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/log.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/log.php @@ -63,8 +63,7 @@ abstract class Log } if (\class_exists('OC')) { -// \OCP\Log\logger('snappymail')->log(\intval($level), $msg); - \OCP\Log\logger('snappymail')->{static::$levels[$level]}($msg); + \SnappyMail\Nextcloud::log($level, $msg); } */ } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/nextcloud.php b/snappymail/v/0.0.0/app/libraries/snappymail/nextcloud.php new file mode 100644 index 000000000..e62e99924 --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/snappymail/nextcloud.php @@ -0,0 +1,85 @@ +getConfig() + // Nextcloud 34+ + : \OC::$server->get(\OCP\IAppConfig); + } + + public static function getSystemConfigValue(string $key, mixed $default = null): mixed + { + return \method_exists(\OC::$server, 'getSystemConfig') + ? \OC::$server->getSystemConfig()->getValue($key, $default) + // Nextcloud 34+ + : \OC::$server->get(\OCP\IConfig::class)->getSystemValue($key, $default); + } + + public static function getUserSession(): mixed + { + return \method_exists(\OC::$server, 'getUserSession') + ? \OC::$server->getUserSession() + // Nextcloud 34+ + : \OC::$server->get(\OCP\IUserSession::class); + } + + public static function setUserSessionValue(string $key, mixed $value): void + { + if (\method_exists(\OC::$server, 'getUserSession')) { + \OC::$server->getUserSession()[$key] = $value; + } else { + // Nextcloud 34+ + \OC::$server->get(\OCP\IUserSession::class)->getSession()->set($key, $value); + } + } + + private static + $levels = [ + \LOG_EMERG => 'EMERGENCY', + \LOG_ALERT => 'ALERT', + \LOG_CRIT => 'CRITICAL', + \LOG_ERR => 'ERROR', + \LOG_WARNING => 'WARNING', + \LOG_NOTICE => 'NOTICE', + \LOG_INFO => 'INFO', + \LOG_DEBUG => 'DEBUG', + ]; + + public static function log(int $level, string $msg): void + { + // https://www.php-fig.org/psr/psr-3/#3-psrlogloggerinterface + if (\class_exists('OCP\Log\logger')) { +// \OCP\Log\logger('snappymail')->log($level, $msg); + \OCP\Log\logger('snappymail')->{static::$levels[$level]}($msg); + } + } +}