mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-10-31 01:23:32 +03:00
Nextcloud 34 changes #2005
This commit is contained in:
parent
8afb1049f7
commit
0d1e2a2cd2
14 changed files with 150 additions and 113 deletions
|
|
@ -29,6 +29,7 @@
|
|||
*/
|
||||
if (class_exists('OC')) {
|
||||
define('APP_DATA_FOLDER_PATH', \rtrim(\trim(
|
||||
// \OCA\SnappyMail\Util\SnappyMailHelper::getSystemConfigValue('datadirectory', '')
|
||||
\method_exists(\OC::$server, 'getSystemConfig')
|
||||
? \OC::$server->getSystemConfig()->getValue('datadirectory', '')
|
||||
// Nextcloud 34+
|
||||
|
|
|
|||
|
|
@ -72,22 +72,21 @@ class Application extends App implements IBootstrap
|
|||
|
||||
public function boot(IBootContext $context): void
|
||||
{
|
||||
if (!\is_dir(\rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
|
||||
if (!\is_dir(\rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dispatcher = $context->getAppContainer()->query('OCP\EventDispatcher\IEventDispatcher');
|
||||
$dispatcher->addListener(PostLoginEvent::class, function (PostLoginEvent $Event) {
|
||||
/*
|
||||
$config = \OC::$server->getConfig();
|
||||
// Only store the user's password in the current session if they have
|
||||
// enabled auto-login using Nextcloud username or email address.
|
||||
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)
|
||||
|| $config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
||||
if (SnappyMailHelper::getAppConfigValue('snappymail-autologin', false)
|
||||
|| SnappyMailHelper::getAppConfigValue('snappymail-autologin-with-email', false)) {
|
||||
*/
|
||||
$sUID = $Event->getUser()->getUID();
|
||||
\OC::$server->getSession()['snappymail-nc-uid'] = $sUID;
|
||||
\OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($Event->getPassword(), $sUID);
|
||||
SnappyMailHelper::setSessionValue('snappymail-nc-uid', $sUID);
|
||||
SnappyMailHelper::setSessionValue('snappymail-passphrase', SnappyMailHelper::encodePassword($Event->getPassword(), $sUID));
|
||||
/*
|
||||
}
|
||||
*/
|
||||
|
|
@ -95,7 +94,7 @@ class Application extends App implements IBootstrap
|
|||
|
||||
$dispatcher->addListener(BeforeUserLoggedOutEvent::class, function (BeforeUserLoggedOutEvent $Event) {
|
||||
// https://github.com/nextcloud/server/issues/36083#issuecomment-1387370634
|
||||
// \OC::$server->getSession()['snappymail-passphrase'] = '';
|
||||
// SnappyMailHelper::setSessionValue('snappymail-passphrase', '');
|
||||
SnappyMailHelper::loadApp();
|
||||
// \RainLoop\Api::Actions()->Logout(true);
|
||||
\RainLoop\Api::Actions()->DoLogout();
|
||||
|
|
@ -106,12 +105,12 @@ class Application extends App implements IBootstrap
|
|||
$class = 'OCA\Impersonate\Events\BeginImpersonateEvent';
|
||||
if (\class_exists($class)) {
|
||||
$dispatcher->addListener($class, function ($Event) {
|
||||
\OC::$server->getSession()['snappymail-passphrase'] = '';
|
||||
SnappyMailHelper::setSessionValue('snappymail-passphrase', '');
|
||||
SnappyMailHelper::loadApp();
|
||||
\RainLoop\Api::Actions()->Logout(true);
|
||||
});
|
||||
$dispatcher->addListener('OCA\Impersonate\Events\EndImpersonateEvent', function ($Event) {
|
||||
\OC::$server->getSession()['snappymail-passphrase'] = '';
|
||||
SnappyMailHelper::setSessionValue('snappymail-passphrase', '');
|
||||
SnappyMailHelper::loadApp();
|
||||
\RainLoop\Api::Actions()->Logout(true);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy
|
|||
$cspManager = (\method_exists(\OC::$server, 'getContentSecurityPolicyNonceManager')
|
||||
? \OC::$server->getContentSecurityPolicyNonceManager()
|
||||
// Nextcloud 34+
|
||||
: \OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class)
|
||||
: \OCP\Server::get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class)
|
||||
);
|
||||
$sNonce = $cspManager->getNonce() ?: \SnappyMail\UUID::generate();
|
||||
if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class FetchController extends Controller {
|
|||
try {
|
||||
$sEmail = '';
|
||||
if (isset($_POST['appname'], $_POST['snappymail-password'], $_POST['snappymail-email']) && 'snappymail' === $_POST['appname']) {
|
||||
$sUser = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$sUser = SnappyMailHelper::getUID();
|
||||
|
||||
$sEmail = $_POST['snappymail-email'];
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ class PageController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
$config = \OC::$server->getConfig();
|
||||
|
||||
$bAdmin = false;
|
||||
if (!empty($_SERVER['QUERY_STRING'])) {
|
||||
SnappyMailHelper::loadApp();
|
||||
|
|
@ -27,7 +25,7 @@ class PageController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
if (!$bAdmin && $config->getAppValue('snappymail', 'snappymail-no-embed')) {
|
||||
if (!$bAdmin && SnappyMailHelper::getAppConfigValue('snappymail-no-embed')) {
|
||||
\OC::$server->getNavigationManager()->setActiveEntry('snappymail');
|
||||
\OCP\Util::addScript('snappymail', 'snappymail');
|
||||
\OCP\Util::addStyle('snappymail', 'style');
|
||||
|
|
|
|||
|
|
@ -91,8 +91,7 @@ class Provider implements IProvider
|
|||
$MessageCollection = $oMailClient->MessageList($oParams);
|
||||
|
||||
$baseURL = $this->urlGenerator->linkToRoute('snappymail.page.index');
|
||||
// $config = \OC::$server->getConfig();
|
||||
// if ($config->getAppValue('snappymail', 'snappymail-no-embed')) {
|
||||
// if (SnappyMailHelper::getAppConfigValue('snappymail-no-embed')) {
|
||||
// $baseURL .= '?target=';
|
||||
// } else {
|
||||
$baseURL .= '#';
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class AdminSettings implements ISettings
|
|||
|
||||
public function getForm()
|
||||
{
|
||||
\OCA\SnappyMail\Util\SnappyMailHelper::loadApp();
|
||||
SnappyMailHelper::loadApp();
|
||||
|
||||
$keys = [
|
||||
'snappymail-autologin',
|
||||
|
|
@ -27,10 +27,9 @@ class AdminSettings implements ISettings
|
|||
];
|
||||
$parameters = [];
|
||||
foreach ($keys as $k) {
|
||||
$v = $this->config->getAppValue('snappymail', $k);
|
||||
$parameters[$k] = $v;
|
||||
$parameters[$k] = $this->config->getAppValue('snappymail', $k);
|
||||
}
|
||||
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$uid = SnappyMailHelper::getUID();
|
||||
if (\OC_User::isAdminUser($uid)) {
|
||||
// $parameters['snappymail-admin-panel-link'] = SnappyMailHelper::getAppUrl().'?admin';
|
||||
SnappyMailHelper::loadApp();
|
||||
|
|
@ -49,7 +48,7 @@ class AdminSettings implements ISettings
|
|||
$parameters['snappymail-admin-password'] = $sPassword;
|
||||
|
||||
$parameters['can-import-rainloop'] = $sPassword && \is_dir(
|
||||
\rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/')
|
||||
\rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/')
|
||||
. '/rainloop-storage'
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace OCA\SnappyMail\Settings;
|
||||
|
||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\Settings\ISettings;
|
||||
|
|
@ -16,7 +17,7 @@ class PersonalSettings implements ISettings
|
|||
|
||||
public function getForm()
|
||||
{
|
||||
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$uid = SnappyMailHelper::getUID();
|
||||
$sEmail = $this->config->getUserValue($uid, 'snappymail', 'snappymail-email');
|
||||
if ($sPass = $this->config->getUserValue($uid, 'snappymail', 'snappymail-password')) {
|
||||
$this->config->deleteUserValue($uid, 'snappymail', 'snappymail-password');
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ class RainLoop
|
|||
* skips: /data/rainloop-storage/INSTALLED
|
||||
* skips: /data/rainloop-storage/index.php
|
||||
*/
|
||||
public static function import() : array
|
||||
public static function import(): array
|
||||
{
|
||||
$dir = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/');
|
||||
$dir = \rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/');
|
||||
$dir_snappy = $dir . '/appdata_snappymail/';
|
||||
$dir_rainloop = $dir . '/rainloop-storage';
|
||||
$result = [];
|
||||
|
|
|
|||
|
|
@ -15,10 +15,85 @@ class SnappyMailResponse extends \OCP\AppFramework\Http\Response
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nextcloud 34+
|
||||
* @CarlSchwan 2026-03-10
|
||||
* refactor: remove long deprecated IServerContainer methods
|
||||
*
|
||||
* https://github.com/nextcloud/server/commit/39c14c383b698467711a2de09870d7c032d92f63
|
||||
*/
|
||||
|
||||
class SnappyMailHelper
|
||||
{
|
||||
public static function getConfig(): object
|
||||
{
|
||||
return \method_exists(\OC::$server, 'getConfig')
|
||||
? \OC::$server->getConfig()
|
||||
// Nextcloud 34+
|
||||
: \OCP\Server::get(\OCP\IConfig::class);
|
||||
}
|
||||
|
||||
public static function loadApp() : void
|
||||
public static function getAppConfigValue(string $key, mixed $default = null): object
|
||||
{
|
||||
return (\method_exists(\OC::$server, 'getConfig')
|
||||
? \OC::$server->getConfig()
|
||||
// Nextcloud 34+
|
||||
: \OCP\Server::get(\OCP\IAppConfig::class)
|
||||
)->getAppValue('snappymail', $key, $default);
|
||||
}
|
||||
|
||||
public static function getSystemConfigValue(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return \method_exists(\OC::$server, 'getSystemConfig')
|
||||
? \OC::$server->getSystemConfig()->getValue($key, $default)
|
||||
// Nextcloud 34+
|
||||
: \OCP\Server::get(\OCP\IConfig::class)->getSystemValue($key, $default);
|
||||
}
|
||||
|
||||
public static function getUID(): mixed
|
||||
{
|
||||
return static::getUser()->getUID();
|
||||
}
|
||||
|
||||
public static function getUser(): object
|
||||
{
|
||||
return static::getUserSession()->getUser();
|
||||
}
|
||||
|
||||
public static function getUserSession(): object
|
||||
{
|
||||
return (\method_exists(\OC::$server, 'getUserSession')
|
||||
? \OC::$server->getUserSession()
|
||||
// Nextcloud 34+
|
||||
: \OCP\Server::get(\OCP\IUserSession::class)
|
||||
);
|
||||
}
|
||||
|
||||
public static function getSession(): object
|
||||
{
|
||||
return (\method_exists(\OC::$server, 'getSession')
|
||||
? \OC::$server->getSession()
|
||||
// Nextcloud 34+
|
||||
: \OCP\Server::get(\OCP\ISession::class)
|
||||
);
|
||||
}
|
||||
|
||||
public static function getSessionValue(string $key): mixed
|
||||
{
|
||||
return static::getSession()->get($key);
|
||||
}
|
||||
|
||||
public static function setSessionValue(string $key, mixed $value): void
|
||||
{
|
||||
if (\method_exists(\OC::$server, 'getSession')) {
|
||||
\OC::$server->getSession()[$key] = $value;
|
||||
} else {
|
||||
// Nextcloud 34+
|
||||
\OCP\Server::get(\OCP\ISession::class)->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadApp(): void
|
||||
{
|
||||
if (\class_exists('RainLoop\\Api')) {
|
||||
return;
|
||||
|
|
@ -37,13 +112,13 @@ class SnappyMailHelper
|
|||
// define('APP_VERSION', '0.0.0');
|
||||
// define('APP_INDEX_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
|
||||
// include APP_INDEX_ROOT_PATH.'snappymail/v/'.APP_VERSION.'/include.php';
|
||||
// define('APP_DATA_FOLDER_PATH', \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/');
|
||||
// define('APP_DATA_FOLDER_PATH', \rtrim(\trim(static::getSystemConfigValue('datadirectory', '')), '\\/').'/appdata_snappymail/');
|
||||
|
||||
$app_dir = \dirname(\dirname(__DIR__)) . '/app';
|
||||
require_once $app_dir . '/index.php';
|
||||
}
|
||||
|
||||
public static function startApp(bool $handle = false)
|
||||
public static function startApp(bool $handle = false): void
|
||||
{
|
||||
static::loadApp();
|
||||
|
||||
|
|
@ -57,7 +132,7 @@ class SnappyMailHelper
|
|||
$oActions = \RainLoop\Api::Actions();
|
||||
if (isset($_GET[$oConfig->Get('security', 'admin_panel_key', 'admin')])) {
|
||||
if ($oConfig->Get('security', 'allow_admin_panel', true)
|
||||
&& \OC_User::isAdminUser(\OC::$server->getUserSession()->getUser()->getUID())
|
||||
&& \OC_User::isAdminUser(static::getUID())
|
||||
&& !$oActions->IsAdminLoggined(false)
|
||||
) {
|
||||
$sRand = \MailSo\Base\Utils::Sha1Rand();
|
||||
|
|
@ -79,7 +154,7 @@ class SnappyMailHelper
|
|||
// file_get_contents(\OC::$SERVERROOT . 'config/config.php');
|
||||
// $CONFIG['version']
|
||||
if (24 < $OC_Version[0]) {
|
||||
$ocSession = \OC::$server->getSession();
|
||||
$ocSession = static::getSession();
|
||||
$ocSession->reopen();
|
||||
if (!$doLogin && $ocSession['snappymail-uid'] && $ocSession['snappymail-uid'] != $aCredentials[0]) {
|
||||
// UID changed, Impersonate plugin probably active
|
||||
|
|
@ -92,7 +167,6 @@ class SnappyMailHelper
|
|||
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
||||
$isOIDC = \str_starts_with($aCredentials[2], 'oidc_login|');
|
||||
try {
|
||||
$ocSession = \OC::$server->getSession();
|
||||
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
|
||||
if (!$isOIDC && $oAccount
|
||||
&& $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn
|
||||
|
|
@ -102,9 +176,9 @@ class SnappyMailHelper
|
|||
} catch (\Throwable $e) {
|
||||
// Login failure, reset password to prevent more attempts
|
||||
if (!$isOIDC) {
|
||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
\OC::$server->getSession()['snappymail-passphrase'] = '';
|
||||
\OC::$server->getConfig()->setUserValue($sUID, 'snappymail', 'passphrase', '');
|
||||
$sUID = static::getUID();
|
||||
static::setSessionValue('snappymail-passphrase', '');
|
||||
static::getConfig()->setUserValue($sUID, 'snappymail', 'passphrase', '');
|
||||
\SnappyMail\Log::error('Nextcloud', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -125,14 +199,13 @@ class SnappyMailHelper
|
|||
|
||||
// Check if OpenID Connect (OIDC) is enabled and used for login
|
||||
// https://apps.nextcloud.com/apps/oidc_login
|
||||
public static function isOIDCLogin() : bool
|
||||
public static function isOIDCLogin(): bool
|
||||
{
|
||||
$config = \OC::$server->getConfig();
|
||||
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
||||
if (static::getAppConfigValue('snappymail-autologin-oidc', false)) {
|
||||
// Check if the OIDC Login app is enabled
|
||||
if (\OC::$server->getAppManager()->isEnabledForUser('oidc_login')) {
|
||||
// Check if session is an OIDC Login
|
||||
$ocSession = \OC::$server->getSession();
|
||||
$ocSession = static::getSession();
|
||||
if ($ocSession->get('is_oidc')) {
|
||||
// IToken->getPassword() ???
|
||||
if ($ocSession->get('oidc_access_token')) {
|
||||
|
|
@ -149,11 +222,11 @@ class SnappyMailHelper
|
|||
return false;
|
||||
}
|
||||
|
||||
private static function getLoginCredentials() : array
|
||||
private static function getLoginCredentials(): array
|
||||
{
|
||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$config = \OC::$server->getConfig();
|
||||
$ocSession = \OC::$server->getSession();
|
||||
$sUID = static::getUID();
|
||||
$config = static::getConfig();
|
||||
$ocSession = static::getSession();
|
||||
|
||||
// If the user has set credentials for SnappyMail in their personal settings,
|
||||
// this has the first priority.
|
||||
|
|
@ -203,12 +276,12 @@ class SnappyMailHelper
|
|||
return [$sUID, '', ''];
|
||||
}
|
||||
|
||||
public static function getAppUrl() : string
|
||||
public static function getAppUrl(): string
|
||||
{
|
||||
return \OC::$server->getURLGenerator()->linkToRoute('snappymail.page.appGet');
|
||||
}
|
||||
|
||||
public static function normalizeUrl(string $sUrl) : string
|
||||
public static function normalizeUrl(string $sUrl): string
|
||||
{
|
||||
$sUrl = \rtrim(\trim($sUrl), '/\\');
|
||||
if ('.php' !== \strtolower(\substr($sUrl, -4))) {
|
||||
|
|
@ -218,13 +291,13 @@ class SnappyMailHelper
|
|||
return $sUrl;
|
||||
}
|
||||
|
||||
public static function encodePassword(string $sPassword, string $sSalt) : string
|
||||
public static function encodePassword(string $sPassword, string $sSalt): string
|
||||
{
|
||||
static::loadApp();
|
||||
return \SnappyMail\Crypt::EncryptUrlSafe($sPassword, $sSalt);
|
||||
}
|
||||
|
||||
public static function decodePassword(string $sPassword, string $sSalt) : ?\SnappyMail\SensitiveString
|
||||
public static function decodePassword(string $sPassword, string $sSalt): ?\SnappyMail\SensitiveString
|
||||
{
|
||||
static::loadApp();
|
||||
$result = \SnappyMail\Crypt::DecryptUrlSafe($sPassword, $sSalt);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||
|
||||
class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
|
|
@ -43,7 +45,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addHook('sieve.before-login', 'beforeLogin');
|
||||
} else {
|
||||
\SnappyMail\Log::debug('Nextcloud', 'NOT integrated');
|
||||
// \OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-no-embed');
|
||||
// SnappyMailHelper::getConfig()->getAppValue('snappymail', 'snappymail-no-embed');
|
||||
$this->addHook('main.content-security-policy', 'ContentSecurityPolicy');
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +69,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
public static function IsLoggedIn()
|
||||
{
|
||||
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
||||
return static::IsIntegrated() && SnappyMailHelper::getUserSession()->isLoggedIn();
|
||||
}
|
||||
|
||||
public function loginCredentials(string &$sEmail, string &$sLogin, ?string &$sPassword = null) : void
|
||||
|
|
@ -77,13 +79,13 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
* When user changes email address, all settings are gone as the new
|
||||
* _data_/_default_/storage/{domain}/{local-part} is used
|
||||
*/
|
||||
// $ocUser = \OC::$server->getUserSession()->getUser();
|
||||
// $ocUser = SnappyMailHelper::getUser();
|
||||
// $sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
||||
}
|
||||
|
||||
public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) : void
|
||||
{
|
||||
$ocUser = \OC::$server->getUserSession()->getUser();
|
||||
$ocUser = SnappyMailHelper::getUser();
|
||||
$sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
||||
}
|
||||
|
||||
|
|
@ -93,12 +95,12 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
// it is enabled in config, the user is currently logged in with OIDC,
|
||||
// the current snappymail account is the OIDC account and no account defined explicitly
|
||||
if ($oAccount instanceof \RainLoop\Model\MainAccount
|
||||
&& \OCA\SnappyMail\Util\SnappyMailHelper::isOIDCLogin()
|
||||
&& SnappyMailHelper::isOIDCLogin()
|
||||
// && $oClient->supportsAuthType('OAUTHBEARER') // v2.28
|
||||
&& \str_starts_with($oSettings->passphrase, 'oidc_login|')
|
||||
) {
|
||||
// $oSettings->passphrase = \OC::$server->getSession()->get('snappymail-passphrase');
|
||||
$oSettings->passphrase = \OC::$server->getSession()->get('oidc_access_token');
|
||||
// $oSettings->passphrase = SnappyMailHelper::getSessionValue('snappymail-passphrase');
|
||||
$oSettings->passphrase = SnappyMailHelper::getSessionValue('oidc_access_token');
|
||||
\array_unshift($oSettings->SASLMechanisms, 'OAUTHBEARER');
|
||||
}
|
||||
}
|
||||
|
|
@ -213,7 +215,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
public function FilterAppData($bAdmin, &$aResult) : void
|
||||
{
|
||||
if (!$bAdmin && \is_array($aResult)) {
|
||||
$ocUser = \OC::$server->getUserSession()->getUser();
|
||||
$ocUser = SnappyMailHelper::getUser();
|
||||
$sUID = $ocUser->getUID();
|
||||
$oUrlGen = \OC::$server->getURLGenerator();
|
||||
$sWebDAV = $oUrlGen->getAbsoluteURL($oUrlGen->linkTo('', 'remote.php') . '/dav');
|
||||
|
|
@ -225,7 +227,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
||||
];
|
||||
if (empty($aResult['Auth'])) {
|
||||
$config = \OC::$server->getConfig();
|
||||
$config = SnappyMailHelper::getConfig();
|
||||
$sEmail = '';
|
||||
// Only store the user's password in the current session if they have
|
||||
// enabled auto-login using Nextcloud username or email address.
|
||||
|
|
@ -248,9 +250,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
/*
|
||||
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
||||
if (\OC::$server->getSession()->get('is_oidc')) {
|
||||
if (SnappyMailHelper::getSessionValue('is_oidc')) {
|
||||
$sEmail = "{$sUID}@nextcloud";
|
||||
$aResult['DevPassword'] = \OC::$server->getSession()->get('oidc_access_token');
|
||||
$aResult['DevPassword'] = SnappyMailHelper::getSessionValue('oidc_access_token');
|
||||
} else {
|
||||
\SnappyMail\Log::debug('Nextcloud', 'Not an OIDC login');
|
||||
}
|
||||
|
|
@ -269,7 +271,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$aResult['ContactsSync']['User'] = $sUID;
|
||||
$bSave = true;
|
||||
}
|
||||
$pass = \OC::$server->getSession()['snappymail-passphrase'];
|
||||
$pass = SnappyMailHelper::getSessionValue('snappymail-passphrase');
|
||||
if ($pass/* && empty($aResult['ContactsSync']['Password'])*/) {
|
||||
$pass = \SnappyMail\Crypt::DecryptUrlSafe($pass, $sUID);
|
||||
if ($pass) {
|
||||
|
|
@ -297,8 +299,8 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
{
|
||||
if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||
$aResultLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
||||
$userId = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$userLang = \OC::$server->getConfig()->getUserValue($userId, 'core', 'lang', 'en');
|
||||
$userId = SnappyMailHelper::getUID();
|
||||
$userLang = SnappyMailHelper::getConfig()->getUserValue($userId, 'core', 'lang', 'en');
|
||||
$userLang = \strtr($userLang, '_', '-');
|
||||
$sLanguage = $this->determineLocale($userLang, $aResultLang);
|
||||
// Check if $sLanguage is null
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class NextcloudStorage extends \RainLoop\Providers\Storage\FileStorage
|
|||
{
|
||||
$sDataPath = parent::GenerateFilePath($mAccount, $iStorageType, $bMkDir);
|
||||
if (StorageType::CONFIG === $iStorageType) {
|
||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$sUID = \OCA\SnappyMail\Util\SnappyMailHelper::getUID();
|
||||
$sDataPath .= ".config/{$sUID}/";
|
||||
if ($bMkDir && !\is_dir($sDataPath) && !\mkdir($sDataPath, 0700, true)) {
|
||||
throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "'.$sDataPath.'"');
|
||||
|
|
|
|||
|
|
@ -72,15 +72,7 @@ trait Themes
|
|||
}
|
||||
|
||||
if (\class_exists('OC', false)) {
|
||||
$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';
|
||||
}
|
||||
}
|
||||
\closedir($rDirH);
|
||||
}
|
||||
$aCache = \array_merge($aCache, Nextcloud::themes());
|
||||
}
|
||||
|
||||
$aCache = \array_unique($aCache);
|
||||
|
|
|
|||
|
|
@ -2,22 +2,29 @@
|
|||
|
||||
namespace SnappyMail;
|
||||
|
||||
/**
|
||||
* Nextcloud 34+
|
||||
* @CarlSchwan 2026-03-10
|
||||
* refactor: remove long deprecated IServerContainer methods
|
||||
*
|
||||
* https://github.com/nextcloud/server/commit/39c14c383b698467711a2de09870d7c032d92f63
|
||||
*/
|
||||
abstract class Nextcloud
|
||||
{
|
||||
public static function themes(): array
|
||||
{
|
||||
$themes = [];
|
||||
$dir = static::themesDir();
|
||||
if ($dir && ($rDirH = \opendir($dir))) {
|
||||
while (($name = \readdir($rDirH)) !== false) {
|
||||
if ('.' !== $name[0] && \is_dir("{$dir}/{$name}") && \file_exists("{$dir}/{$name}/snappymail/style.css")) {
|
||||
$themes[] = $name . '@nextcloud';
|
||||
}
|
||||
}
|
||||
\closedir($rDirH);
|
||||
}
|
||||
return $themes;
|
||||
}
|
||||
|
||||
public static function themesDir(): ?string
|
||||
{
|
||||
if (\class_exists('OC', false)) {
|
||||
$sDir = \OC::$SERVERROOT . '/themes'; // custom user themes
|
||||
if (\is_dir($sDir)) {
|
||||
return $sDir;
|
||||
$dir = \OC::$SERVERROOT . '/themes'; // custom user themes
|
||||
if (\is_dir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -28,40 +35,6 @@ abstract class Nextcloud
|
|||
return \class_exists('OC', false) ? \OC::$WEBROOT : null;
|
||||
}
|
||||
|
||||
public static function getConfig(): object
|
||||
{
|
||||
return \method_exists(\OC::$server, 'getConfig')
|
||||
? \OC::$server->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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue