diff --git a/integrations/nextcloud/snappymail/lib/Controller/FetchController.php b/integrations/nextcloud/snappymail/lib/Controller/FetchController.php index a12716091..f712b344a 100644 --- a/integrations/nextcloud/snappymail/lib/Controller/FetchController.php +++ b/integrations/nextcloud/snappymail/lib/Controller/FetchController.php @@ -65,11 +65,11 @@ class FetchController extends Controller { $this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sPostEmail); $sPass = $_POST['snappymail-password']; - if ('******' !== $sPass && '' !== $sPass) { + if ('******' !== $sPass) { require_once $this->appManager->getAppPath('snappymail').'/lib/Util/SnappyMailHelper.php'; $this->config->setUserValue($sUser, 'snappymail', 'snappymail-password', - SnappyMailHelper::encodePassword($sPass, \md5($sPostEmail))); + $sPass ? SnappyMailHelper::encodePassword($sPass, \md5($sPostEmail)) : ''); } $sEmail = $this->config->getUserValue($sUser, 'snappymail', 'snappymail-email', ''); diff --git a/integrations/nextcloud/snappymail/lib/Search/Provider.php b/integrations/nextcloud/snappymail/lib/Search/Provider.php index 9888ff25e..64efd875b 100644 --- a/integrations/nextcloud/snappymail/lib/Search/Provider.php +++ b/integrations/nextcloud/snappymail/lib/Search/Provider.php @@ -45,8 +45,8 @@ class Provider implements IProvider $result = []; SnappyMailHelper::startApp(); $oActions = \RainLoop\Api::Actions(); - $oAccount = $oActions->getMainAccountFromToken(false); -// $oAccount = $oActions->getAccountFromToken(false); +// $oAccount = $oActions->getMainAccountFromToken(false); // Issue: when account switched, wrong email is shown + $oAccount = $oActions->getAccountFromToken(false); $iCursor = (int) $query->getCursor(); $iLimit = $query->getLimit(); if ($oAccount) { diff --git a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php index 089ecb05a..938a6ec40 100644 --- a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php +++ b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php @@ -61,9 +61,9 @@ class SnappyMailHelper public static function getLoginCredentials() : array { - $config = \OC::$server->getConfig(); $sEmail = ''; $sPassword = ''; + $config = \OC::$server->getConfig(); $sUID = \OC::$server->getUserSession()->getUser()->getUID(); // Only store the user's password in the current session if they have // enabled auto-login using Nextcloud username or email address. @@ -76,8 +76,9 @@ class SnappyMailHelper } // If the user has set credentials for SnappyMail in their personal // settings, override everything before and use those instead. - $sEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', ''); - if ($sEmail) { + $sCustomEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', ''); + if ($sCustomEmail) { + $sEmail = $sCustomEmail; $sPassword = $config->getUserValue($sUID, 'snappymail', 'snappymail-password', ''); } return [$sEmail, $sPassword ? SnappyMailHelper::decodePassword($sPassword, \md5($sEmail)) : '']; diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index 39fae6da3..0ff9da0f9 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -143,6 +143,23 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin 'WebDAV' => $sWebDAV // 'WebDAV_files' => $sWebDAV . '/files/' . $sUID ]; + if (empty($aResult['Auth'])) { + $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)) { + $sEmail = $sUID; + } else if ($config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) { + $sEmail = $config->getUserValue($sUID, 'settings', 'email', ''); + } + // If the user has set credentials for SnappyMail in their personal + // settings, override everything before and use those instead. + $sCustomEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', ''); + if ($sCustomEmail) { + $sEmail = $sCustomEmail; + } + $aResult['DevEmail'] = $sEmail ?: ''; + } } }