mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-31 11:09:14 +08:00
Works now with additional accounts:
The mail address is correctly set by ldap value. But plugin needs rework: it makes no sense to let the user use the non existing mail address "username@domain" used only by SnappyMail. Plugin should always use a looked up mail address
This commit is contained in:
parent
aa03e84c79
commit
9cfe164633
2 changed files with 44 additions and 7 deletions
|
@ -113,7 +113,7 @@ class LdapMailAccounts
|
|||
|
||||
$aAccounts = $oActions->GetAccounts($oAccount);
|
||||
|
||||
//Search for accounts with suffix " (LDAP)" at the end of the name that where created by this plugin and initially remove them from the
|
||||
//Search for accounts with suffix " (LDAP)" at the end of the name that were created by this plugin and initially remove them from the
|
||||
//account array. This only removes the visibility but does not delete the config done by the user. So if a user looses access to a
|
||||
//mailbox the user will not see the account anymore but the configuration can be restored when the user regains access to it
|
||||
foreach($aAccounts as $key => $aAccount)
|
||||
|
@ -129,31 +129,40 @@ class LdapMailAccounts
|
|||
$sUsername = $mailAddressResult->username;
|
||||
$sDomain = $mailAddressResult->domain;
|
||||
$sName = $mailAddressResult->name;
|
||||
$sEmail = "";
|
||||
|
||||
//Create the email string - if disabled inside the config the email is a combination of the found username + @ + the found domain
|
||||
if ($this->config->bool_overwrite_mail_address_additional_account) {
|
||||
$sEmail = $mailAddressResult->mailAdditionalAccount;
|
||||
}
|
||||
else {
|
||||
$sEmail = "$sUsername@$sDomain";
|
||||
}
|
||||
|
||||
//Check if the domain of the found mail address is in the list of configured domains
|
||||
if ($oActions->DomainProvider()->Load($sDomain, true))
|
||||
{
|
||||
//only execute if the found account isn't already in the list of additional accounts
|
||||
//and if the found account is different from the main account
|
||||
if (!isset($aAccounts["$sUsername@$sDomain"]) && $oAccount->Email() !== "$sUsername@$sDomain")
|
||||
if (!isset($aAccounts[$sEmail]) && $oAccount->Email() !== $sEmail)
|
||||
{
|
||||
//Try to login the user with the same password as the primary account has
|
||||
//if this fails the user will see the new mail addresses but will be asked for the correct password
|
||||
$sPass = $oAccount->IncPassword();
|
||||
|
||||
$oNewAccount = RainLoop\Model\AdditionalAccount::NewInstanceFromCredentials($oActions, "$sUsername@$sDomain", $sUsername, $sPass);
|
||||
$oNewAccount = RainLoop\Model\AdditionalAccount::NewInstanceFromCredentials($oActions, $sEmail, $sUsername, $sPass);
|
||||
|
||||
$aAccounts["$sUsername@$sDomain"] = $oNewAccount->asTokenArray($oAccount);
|
||||
$aAccounts[$sEmail] = $oNewAccount->asTokenArray($oAccount);
|
||||
}
|
||||
|
||||
//Always inject/update the found mailbox names into the array (also if the mailbox already existed)
|
||||
if (isset($aAccounts["$sUsername@$sDomain"]))
|
||||
if (isset($aAccounts[$sEmail]))
|
||||
{
|
||||
$aAccounts["$sUsername@$sDomain"]['name'] = $sName . " (LDAP)";
|
||||
$aAccounts[$sEmail]['name'] = $sName . " (LDAP)";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->logger->Write("Domain $sDomain is not part of configured domains in SnappyMail Admin Panel - mail address $sUsername@$sDomain will not be added.", \LOG_NOTICE, self::LOG_KEY);
|
||||
$this->logger->Write("Domain $sDomain is not part of configured domains in SnappyMail Admin Panel - mail address $sEmail will not be added.", \LOG_NOTICE, self::LOG_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ class LdapMailAccountsPlugin extends AbstractPlugin
|
|||
public function Init(): void
|
||||
{
|
||||
$this->addHook("login.success", 'AddAdditionalLdapMailAccounts');
|
||||
$this->addHook('imap.before-login', 'MapImapCredentialsByLDAP');
|
||||
$this->addHook('smtp.before-login', 'MapSmtpCredentialsByLDAP');
|
||||
}
|
||||
|
||||
// Function gets called by RainLoop/Actions/User.php
|
||||
|
@ -50,6 +52,32 @@ class LdapMailAccountsPlugin extends AbstractPlugin
|
|||
$oldapMailAccounts->AddLdapMailAccounts($oAccount);
|
||||
}
|
||||
|
||||
// Function gets called by Account.php
|
||||
/**
|
||||
* Overwrite the mailaddress of the account with the one found in LDAP by this plugin at IMAP login
|
||||
*
|
||||
* @param Account $oAccount
|
||||
* @param ImapClient $oImapClient
|
||||
* @param \MailSo\Imap\Settings $oSettings
|
||||
*/
|
||||
public function MapImapCredentialsByLDAP(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oImapClient, \MailSo\Imap\Settings $oSettings)
|
||||
{
|
||||
//$oSettings->Login = $oAccount->IncLogin();
|
||||
}
|
||||
|
||||
// Function gets called by Account.php
|
||||
/**
|
||||
* Overwrite the mailaddress of the account with the one found in LDAP by this plugin at SMTP login
|
||||
*
|
||||
* @param Account $oAccount
|
||||
* @param SmtpClient $oSmtpClient
|
||||
* @param \MailSo\Smtp\Settings $oSettings
|
||||
*/
|
||||
public function MapSmtpCredentialsByLDAP(\RainLoop\Model\Account $oAccount, \MailSo\Smtp\SmtpClient $oSmtpClient, \MailSo\Smtp\Settings $oSettings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the content of the plugin configuration page inside the Admin Panel of SnappyMail
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue