diff --git a/plugins/ldap-mail-accounts/LdapMailAccounts.php b/plugins/ldap-mail-accounts/LdapMailAccounts.php index 2f93dbd14..06ba15d28 100644 --- a/plugins/ldap-mail-accounts/LdapMailAccounts.php +++ b/plugins/ldap-mail-accounts/LdapMailAccounts.php @@ -3,6 +3,7 @@ use RainLoop\Enumerations\Capa; use MailSo\Log\Logger; use RainLoop\Actions; +use RainLoop\Model\AdditionalAccount; use RainLoop\Model\MainAccount; class LdapMailAccounts @@ -50,14 +51,13 @@ class LdapMailAccounts /** * @inheritDoc * - * AOverwrite the MainAccount mail address by looking up the new one in the ldap directory + * Overwrite the MainAccount mail address by looking up the new one in the ldap directory * * The ldap search string has to be configured in the plugin configuration of the extension (in the SnappyMail Admin Panel) * * @param string &$sEmail - * @param string &$sLogin */ - public function overwriteEmail(&$sEmail, &$sLogin) + public function overwriteEmail(&$sEmail) { try { $this->EnsureBound(); @@ -105,10 +105,12 @@ class LdapMailAccounts foreach($mailAddressResults as $mailAddressResult) { + $this->logger->Write("AAAAAAA: $mailAddressResult->username , $username , $mailAddressResult->mailMainAccount , $sEmail", \LOG_NOTICE, self::LOG_KEY); if($mailAddressResult->username === $username) { - //$sLogin is already set to be the same as $sEmail by function "resolveLoginCredentials" in /RainLoop/Actions/UserAuth.php + //$sImapUser and $sSmtpUser are already set to be the same as $sEmail by function "resolveLoginCredentials" in /RainLoop/Actions/UserAuth.php //that called this hook, so we just have to overwrite the mail address $sEmail = $mailAddressResult->mailMainAccount; + $this->logger->Write("BBBBBBB: $mailAddressResult->username , $username , $mailAddressResult->mailMainAccount , $sEmail", \LOG_NOTICE, self::LOG_KEY); } } } @@ -131,10 +133,10 @@ class LdapMailAccounts return false; // exceptions are only thrown from the handle error function that does logging already } - // Try to get account information. IncLogin() returns the username of the user + // Try to get account information. ImapUser() returns the username of the user // and removes the domainname if this was configured inside the domain config. - $username = @ldap_escape($oAccount->IncLogin(), "", LDAP_ESCAPE_FILTER); - + $username = @ldap_escape($oAccount->ImapUser(), "", LDAP_ESCAPE_FILTER); + $searchString = $this->config->search_string; // Replace placeholders inside the ldap search string with actual values @@ -210,7 +212,19 @@ class LdapMailAccounts //if this fails the user will see the new mail addresses but will be asked for the correct password $sPass = new \SnappyMail\SensitiveString($oAccount->IncPassword()); //After creating the accounts here $sUsername is used as username to login to the IMAP server (see Account.php) - $oNewAccount = RainLoop\Model\AdditionalAccount::NewInstanceFromCredentials($oActions, $sEmail, $sUsername, $sPass); + //$oNewAccount = RainLoop\Model\AdditionalAccount::NewInstanceFromCredentials($oActions, $sEmail, $sUsername, $sPass); + + $oDomain = $oActions->DomainProvider()->Load($sDomain, false); + + $oNewAccount = new AdditionalAccount; + $oNewAccount->setCredentials( + $oDomain, + $sEmail, + $sUsername, + $sPass, + $sUsername, + $sPass + ); $aAccounts[$sEmail] = $oNewAccount->asTokenArray($oAccount); } diff --git a/plugins/ldap-mail-accounts/index.php b/plugins/ldap-mail-accounts/index.php index a6063c640..7947f58bb 100644 --- a/plugins/ldap-mail-accounts/index.php +++ b/plugins/ldap-mail-accounts/index.php @@ -40,11 +40,13 @@ class LdapMailAccountsPlugin extends AbstractPlugin * Overwrite the MainAccount mail address by looking up the new one in the ldap directory * * @param string &$sEmail - * @param string &$sLogin + * @param string &$sImapUser + * @param string &$sPassword + * @param string &$sSmtpUser */ - public function overwriteMainAccountEmail(&$sEmail, &$sLogin) + public function overwriteMainAccountEmail(&$sEmail, &$sImapUser, &$sPassword, &$sSmtpUser) { - $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: $sImapUser email: $sEmail", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN"); // Set up config $config = LdapMailAccountsConfig::MakeConfig($this->Config()); @@ -52,10 +54,10 @@ class LdapMailAccountsPlugin extends AbstractPlugin if ($config->bool_overwrite_mail_address_main_account) { $oldapMailAccounts = new LdapMailAccounts($config, $this->Manager()->Actions()->Logger()); - $oldapMailAccounts->overwriteEmail($sEmail, $sLogin); + $oldapMailAccounts->overwriteEmail($sEmail); } - $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: $sImapUser email: $sEmail", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN"); } // Function gets called by RainLoop/Actions/User.php