From 1e55f86f519b70251e247af3c8bee78a700de43e Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sun, 10 Mar 2024 23:58:18 +0100 Subject: [PATCH] Deprecate most Domain methods --- plugins/change-password/drivers/ldap.php | 4 +- plugins/change-password/index.php | 4 +- .../LdapContactsSuggestions.php | 4 +- plugins/ldap-contacts-suggestions/index.php | 4 +- .../ldap-mail-accounts/LdapMailAccounts.php | 4 +- plugins/ldap-mail-accounts/index.php | 16 +++--- plugins/smtp-use-from-adr-account/index.php | 51 +++++++++---------- .../0.0.0/app/libraries/RainLoop/Actions.php | 11 ++-- .../RainLoop/Actions/AdminDomains.php | 4 +- .../libraries/RainLoop/Actions/Messages.php | 2 +- .../app/libraries/RainLoop/Model/Account.php | 6 ++- .../app/libraries/RainLoop/Model/Domain.php | 39 ++++++++------ 12 files changed, 80 insertions(+), 69 deletions(-) diff --git a/plugins/change-password/drivers/ldap.php b/plugins/change-password/drivers/ldap.php index c53492263..73d8b5360 100644 --- a/plugins/change-password/drivers/ldap.php +++ b/plugins/change-password/drivers/ldap.php @@ -66,8 +66,8 @@ class ChangePasswordDriverLDAP '{email:domain}' => $sDomain, '{login}' => $oAccount->IncLogin(), '{imap:login}' => $oAccount->IncLogin(), - '{imap:host}' => $oAccount->Domain()->IncHost(), - '{imap:port}' => $oAccount->Domain()->IncPort(), + '{imap:host}' => $oAccount->Domain()->ImapSettings()->host, + '{imap:port}' => $oAccount->Domain()->ImapSettings()->port, '{gecos}' => \function_exists('posix_getpwnam') ? \posix_getpwnam($oAccount->IncLogin()) : '' )); diff --git a/plugins/change-password/index.php b/plugins/change-password/index.php index 3b1bc4afd..89294188b 100644 --- a/plugins/change-password/index.php +++ b/plugins/change-password/index.php @@ -6,8 +6,8 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin { const NAME = 'Change Password', - VERSION = '2.19', - RELEASE = '2023-04-11', + VERSION = '2.20', + RELEASE = '2024-03-10', REQUIRED = '2.23.0', CATEGORY = 'Security', DESCRIPTION = 'Extension to allow users to change their passwords'; diff --git a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php index 305f3d823..040c21156 100644 --- a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php +++ b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php @@ -102,8 +102,8 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges '{email:domain}' => $sDomain, '{login}' => $oAccount->IncLogin(), '{imap:login}' => $oAccount->IncLogin(), - '{imap:host}' => $oAccount->Domain()->IncHost(), - '{imap:port}' => $oAccount->Domain()->IncPort() + '{imap:host}' => $oAccount->Domain()->ImapSettings()->host, + '{imap:port}' => $oAccount->Domain()->ImapSettings()->port )); $aObjectClasses = empty($this->sObjectClasses) ? array() : \explode(',', $this->sObjectClasses); diff --git a/plugins/ldap-contacts-suggestions/index.php b/plugins/ldap-contacts-suggestions/index.php index c3c1242d4..01dbab362 100644 --- a/plugins/ldap-contacts-suggestions/index.php +++ b/plugins/ldap-contacts-suggestions/index.php @@ -4,8 +4,8 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin { const NAME = 'Contacts suggestions (LDAP)', - VERSION = '2.13', - RELEASE = '2023-10-01', + VERSION = '2.14', + RELEASE = '2024-03-10', REQUIRED = '2.23.0', CATEGORY = 'Contacts', DESCRIPTION = 'Get contacts suggestions from LDAP.'; diff --git a/plugins/ldap-mail-accounts/LdapMailAccounts.php b/plugins/ldap-mail-accounts/LdapMailAccounts.php index e68e9e179..bba3cf29e 100644 --- a/plugins/ldap-mail-accounts/LdapMailAccounts.php +++ b/plugins/ldap-mail-accounts/LdapMailAccounts.php @@ -70,7 +70,7 @@ class LdapMailAccounts $username = $sEmail; $oActions = \RainLoop\Api::Actions(); $oDomain = $oActions->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true); - if ($oDomain->IncShortLogin()){ + if ($oDomain->ImapSettings()->shortLogin){ $username = @ldap_escape($this->RemoveEventualDomainPart($sEmail), "", LDAP_ESCAPE_FILTER); } @@ -101,7 +101,7 @@ class LdapMailAccounts if (count($mailAddressResults) < 1) { $this->logger->Write("Could not find user $username in LDAP! Overwriting of main mail address not possible.", \LOG_NOTICE, self::LOG_KEY); return false; - } + } foreach($mailAddressResults as $mailAddressResult) { diff --git a/plugins/ldap-mail-accounts/index.php b/plugins/ldap-mail-accounts/index.php index e5258e26d..19010b046 100644 --- a/plugins/ldap-mail-accounts/index.php +++ b/plugins/ldap-mail-accounts/index.php @@ -12,10 +12,10 @@ class LdapMailAccountsPlugin extends AbstractPlugin { const NAME = 'LDAP Mail Accounts', - VERSION = '2.0.0', + VERSION = '2.1.0', AUTHOR = 'cm-schl', URL = 'https://github.com/cm-sch', - RELEASE = '2023-03-14', + RELEASE = '2024-03-10', REQUIRED = '2.25.4', CATEGORY = 'Accounts', DESCRIPTION = 'Add additional mail accounts the SnappyMail user has access to by a LDAP query. Basing on the work of FWest98 (https://github.com/FWest98).'; @@ -44,10 +44,10 @@ class LdapMailAccountsPlugin extends AbstractPlugin */ public function overwriteMainAccountEmail(&$sEmail, &$sLogin) { -$this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: $sEmail", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN"); + $this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: $sEmail", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN"); - // Set up config - $config = LdapMailAccountsConfig::MakeConfig($this->Config()); + // Set up config + $config = LdapMailAccountsConfig::MakeConfig($this->Config()); if ($config->bool_overwrite_mail_address_main_account) { @@ -55,7 +55,7 @@ $this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: $oldapMailAccounts->overwriteEmail($sEmail, $sLogin); } -$this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: $sEmail", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN"); + $this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: $sEmail", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN"); } // Function gets called by RainLoop/Actions/User.php @@ -90,7 +90,7 @@ $this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: \nThe value found inside ldap will overwrite the mail address of the SnappyMail main account (the account the user logged in at SnappyMail) \nThe mail address used at login will still be used to login to the servers.") ->SetDefaultValue("mail"), - ]); + ]); return [ \RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_SERVER) @@ -172,7 +172,7 @@ $this->Manager()->Actions()->Logger()->Write("Login DATA: login: $sLogin email: ->SetDefaultValue("displayName"), $groupOverwriteMainAccount - + ]; } } diff --git a/plugins/smtp-use-from-adr-account/index.php b/plugins/smtp-use-from-adr-account/index.php index d4b30843b..c77f8a628 100644 --- a/plugins/smtp-use-from-adr-account/index.php +++ b/plugins/smtp-use-from-adr-account/index.php @@ -7,8 +7,8 @@ class SmtpUseFromAdrAccountPlugin extends \RainLoop\Plugins\AbstractPlugin NAME = 'Use From-Address-Account for smtp', AUTHOR = 'attike', URL = 'https://github.com/attike', - VERSION = '1.0', - RELEASE = '2023-12-06', + VERSION = '1.1', + RELEASE = '2024-03-10', REQUIRED = '2.23.0', CATEGORY = 'Filters', DESCRIPTION = 'Set smpt-config and -credentials based on selected from-address-account'; @@ -34,8 +34,8 @@ class SmtpUseFromAdrAccountPlugin extends \RainLoop\Plugins\AbstractPlugin if (\strlen($sWhiteList) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sFrom, $sWhiteList, $sFoundValue) && $sFrom != $oAccount->Email()) { \SnappyMail\LOG::info(get_class($this) ,'From address different from account recognized: '. $oAccount->Email().' -> '.$sFrom . '(~ '.$sFoundValue.')'); $oMainAccount; - $oFromAccount; - if ( $oAccount instanceof \RainLoop\Model\MainAccount ) { + $oFromAccount; + if ($oAccount instanceof \RainLoop\Model\MainAccount ) { $oMainAccount=$oAccount; } else { $oMainAccount=$this->Manager()->Actions()->getMainAccountFromToken(); @@ -44,21 +44,21 @@ class SmtpUseFromAdrAccountPlugin extends \RainLoop\Plugins\AbstractPlugin return; } } - $aAccounts=$this->Manager()->Actions()->getAccounts($oMainAccount); - foreach ($aAccounts as &$value) { - $oValue=\RainLoop\Model\AdditionalAccount::NewInstanceFromTokenArray($this->Manager()->Actions(), $value); - if ($oValue->Email()==$sFrom) { - $oFromAccount = $oValue; - break; - } - } - if (is_null($oFromAccount)){ + $aAccounts = $this->Manager()->Actions()->getAccounts($oMainAccount); + foreach ($aAccounts as &$value) { + $oValue=\RainLoop\Model\AdditionalAccount::NewInstanceFromTokenArray($this->Manager()->Actions(), $value); + if ($oValue->Email()==$sFrom) { + $oFromAccount = $oValue; + break; + } + } + if (is_null($oFromAccount)){ \SnappyMail\LOG::info(get_class($this),'No Account found for '. $sFrom); if ($this->Config()->Get('plugin', 'throw_notfound_exception', true)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountDoesNotExist); } - return; - } + return; + } $this->aFromAccount[$oAccount->Email()]=$oFromAccount; } } @@ -71,10 +71,10 @@ class SmtpUseFromAdrAccountPlugin extends \RainLoop\Plugins\AbstractPlugin { if ( isset($this->aFromAccount[$oAccount->Email()]) ) { $oFromAccount = $this->aFromAccount[$oAccount->Email()]; - $oSettings->host = $oFromAccount->Domain()->OutHost(); - $oSettings->port = (int) $oFromAccount->Domain()->OutPort(); - $oSettings->type = $oFromAccount->Domain()-> SmtpSettings()->type; - \SnappyMail\LOG::info(get_class($this),'Smtp config rewrite: '. $oFromAccount->Domain()->OutHost()); + $oSettings->host = $oFromAccount->Domain()->SmtpSettings()->host; + $oSettings->port = (int) $oFromAccount->Domain()->SmtpSettings()->port; + $oSettings->type = $oFromAccount->Domain()->SmtpSettings()->type; + \SnappyMail\LOG::info(get_class($this),'Smtp config rewrite: '. $oSettings->host); } } @@ -88,9 +88,9 @@ class SmtpUseFromAdrAccountPlugin extends \RainLoop\Plugins\AbstractPlugin if ( isset($this->aFromAccount[$oAccount->Email()]) ) { $oFromAccount = $this->aFromAccount[$oAccount->Email()]; unset($this->aFromAccount[$oAccount->Email()]); - $oSettings->Login = $oFromAccount-> OutLogin(); - $oSettings->useAuth = $oFromAccount->Domain()-> SmtpSettings()->useAuth; - $oSettings->Password = $oFromAccount->IncPassword(); + $oSettings->Login = $oFromAccount->OutLogin(); + $oSettings->useAuth = $oFromAccount->Domain()->SmtpSettings()->useAuth; + $oSettings->Password = $oFromAccount->IncPassword(); \SnappyMail\LOG::info(get_class($this),'user/pwd rewrite: '. $oFromAccount->Email()); } } @@ -106,10 +106,9 @@ class SmtpUseFromAdrAccountPlugin extends \RainLoop\Plugins\AbstractPlugin ->SetDescription('space as delimiter, wildcard supported.') ->SetDefaultValue('user@example.com *@example2.com'), \RainLoop\Plugins\Property::NewInstance('throw_notfound_exception')->SetLabel('Throw Exception, if from-adr is not found as account') - ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) - ->SetDescription('it is not possible to send eMails in this case, regardless of whether the smtp-server would do it') - ->SetDefaultValue(true), - + ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) + ->SetDescription('it is not possible to send eMails in this case, regardless of whether the smtp-server would do it') + ->SetDefaultValue(true) ); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 461fef627..04a3486c6 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -269,13 +269,14 @@ class Actions } if ($oAccount) { + $oDomain = $oAccount->Domain(); $sLine = \str_replace('{imap:login}', $oAccount->IncLogin(), $sLine); - $sLine = \str_replace('{imap:host}', $oAccount->Domain()->IncHost(), $sLine); - $sLine = \str_replace('{imap:port}', $oAccount->Domain()->IncPort(), $sLine); + $sLine = \str_replace('{imap:host}', $oDomain->ImapSettings()->host, $sLine); + $sLine = \str_replace('{imap:port}', $oDomain->ImapSettings()->port, $sLine); $sLine = \str_replace('{smtp:login}', $oAccount->OutLogin(), $sLine); - $sLine = \str_replace('{smtp:host}', $oAccount->Domain()->OutHost(), $sLine); - $sLine = \str_replace('{smtp:port}', $oAccount->Domain()->OutPort(), $sLine); + $sLine = \str_replace('{smtp:host}', $oDomain->SmtpSettings()->host, $sLine); + $sLine = \str_replace('{smtp:port}', $oDomain->SmtpSettings()->port, $sLine); } $aClear['/\{imap:([^}]*)\}/i'] = 'imap'; @@ -899,7 +900,7 @@ class Actions 'Kolab' => false, // See Kolab plugin ); } - $aResult[Capa::SIEVE] = $bAdmin || ($oAccount && $oAccount->Domain()->UseSieve()); + $aResult[Capa::SIEVE] = $bAdmin || ($oAccount && $oAccount->Domain()->SieveSettings()->enabled); return $aResult; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php index c917f3bbf..e94769468 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php @@ -137,7 +137,7 @@ trait AdminDomains $sImapErrorDesc = $oException->getMessage(); } - if ($oDomain->OutUsePhpMail()) { + if ($oDomain->SmtpSettings()->usePhpMail) { $mSmtpResult = \MailSo\Base\Utils::FunctionCallable('mail'); if (!$mSmtpResult) { $sSmtpErrorDesc = 'PHP: mail() function is undefined'; @@ -179,7 +179,7 @@ trait AdminDomains } } - if ($oDomain->UseSieve()) { + if ($oDomain->SieveSettings()->enabled) { try { $oSieveClient = new \MailSo\Sieve\SieveClient(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index 6b7b713fc..1f178da63 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -964,7 +964,7 @@ trait Messages { $oMessage->SetFrom(new \MailSo\Mime\Email( $oIdentity->Email(), $oIdentity->Name())); - if ($oAccount->Domain()->OutSetSender()) { + if ($oAccount->Domain()->SmtpSettings()->setSender) { $oMessage->SetSender(\MailSo\Mime\Email::Parse($oAccount->Email())); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php index f2b9ad8b2..3d5d3a192 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php @@ -39,7 +39,7 @@ abstract class Account implements \JsonSerializable public function IncLogin() : string { - return $this->oDomain->IncShortLogin() + return $this->oDomain->ImapSettings()->shortLogin ? \MailSo\Base\Utils::GetAccountNameFromEmail($this->sLogin) : $this->sLogin; } @@ -52,7 +52,9 @@ abstract class Account implements \JsonSerializable public function OutLogin() : string { $sSmtpLogin = $this->sSmtpLogin ?: $this->sLogin; - return $this->oDomain->OutShortLogin() ? \MailSo\Base\Utils::GetAccountNameFromEmail($sSmtpLogin) : $sSmtpLogin; + return $this->oDomain->SmtpSettings()->shortLogin + ? \MailSo\Base\Utils::GetAccountNameFromEmail($sSmtpLogin) + : $sSmtpLogin; } public function Domain() : Domain diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Domain.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Domain.php index c2c9b65dc..ce977e959 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Domain.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Domain.php @@ -61,51 +61,60 @@ class Domain implements \JsonSerializable return $this->Name; } + /** + * @deprecated + */ public function IncHost() : string { + \trigger_error('Deprecated function called.', \E_USER_DEPRECATED); return $this->IMAP->host; } + /** + * @deprecated + */ public function IncPort() : int { + \trigger_error('Deprecated function called.', \E_USER_DEPRECATED); return $this->IMAP->port; } + /** + * @deprecated + */ public function IncShortLogin() : bool { + \trigger_error('Deprecated function called.', \E_USER_DEPRECATED); return $this->IMAP->shortLogin; } + /** + * @deprecated + */ public function UseSieve() : bool { + \trigger_error('Deprecated function called.', \E_USER_DEPRECATED); return $this->Sieve->enabled; } + /** + * @deprecated + */ public function OutHost() : string { + \trigger_error('Deprecated function called.', \E_USER_DEPRECATED); return $this->SMTP->host; } + /** + * @deprecated + */ public function OutPort() : int { + \trigger_error('Deprecated function called.', \E_USER_DEPRECATED); return $this->SMTP->port; } - public function OutShortLogin() : bool - { - return $this->SMTP->shortLogin; - } - - public function OutSetSender() : bool - { - return $this->SMTP->setSender; - } - - public function OutUsePhpMail() : bool - { - return $this->SMTP->usePhpMail; - } - public function SetAliasName(string $sAliasName) : void { $this->aliasName = $sAliasName;