mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-03-06 11:49:32 +08:00
Additional accounts now always get the mail address from ldap
This commit is contained in:
parent
9cfe164633
commit
b8c681d1a5
3 changed files with 16 additions and 42 deletions
|
@ -87,7 +87,6 @@ class LdapMailAccounts
|
||||||
$this->config->field_domain,
|
$this->config->field_domain,
|
||||||
$this->config->bool_overwrite_mail_address_main_account,
|
$this->config->bool_overwrite_mail_address_main_account,
|
||||||
$this->config->field_mail_address_main_account,
|
$this->config->field_mail_address_main_account,
|
||||||
$this->config->bool_overwrite_mail_address_additional_account,
|
|
||||||
$this->config->field_mail_address_additional_account
|
$this->config->field_mail_address_additional_account
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -129,15 +128,7 @@ class LdapMailAccounts
|
||||||
$sUsername = $mailAddressResult->username;
|
$sUsername = $mailAddressResult->username;
|
||||||
$sDomain = $mailAddressResult->domain;
|
$sDomain = $mailAddressResult->domain;
|
||||||
$sName = $mailAddressResult->name;
|
$sName = $mailAddressResult->name;
|
||||||
$sEmail = "";
|
$sEmail = $mailAddressResult->mailAdditionalAccount;
|
||||||
|
|
||||||
//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
|
//Check if the domain of the found mail address is in the list of configured domains
|
||||||
if ($oActions->DomainProvider()->Load($sDomain, true))
|
if ($oActions->DomainProvider()->Load($sDomain, true))
|
||||||
|
@ -149,7 +140,7 @@ class LdapMailAccounts
|
||||||
//Try to login the user with the same password as the primary account has
|
//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
|
//if this fails the user will see the new mail addresses but will be asked for the correct password
|
||||||
$sPass = $oAccount->IncPassword();
|
$sPass = $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);
|
||||||
|
|
||||||
$aAccounts[$sEmail] = $oNewAccount->asTokenArray($oAccount);
|
$aAccounts[$sEmail] = $oNewAccount->asTokenArray($oAccount);
|
||||||
|
@ -294,7 +285,6 @@ class LdapMailAccounts
|
||||||
string $domainField,
|
string $domainField,
|
||||||
bool $overwriteMailMainAccount,
|
bool $overwriteMailMainAccount,
|
||||||
string $mailAddressFieldMainAccount,
|
string $mailAddressFieldMainAccount,
|
||||||
bool $overwriteMailAdditionalAccount,
|
|
||||||
string $mailAddressFieldAdditionalAccount): array
|
string $mailAddressFieldAdditionalAccount): array
|
||||||
{
|
{
|
||||||
$this->EnsureBound();
|
$this->EnsureBound();
|
||||||
|
@ -306,18 +296,12 @@ class LdapMailAccounts
|
||||||
$this->logger->Write("Used ldap filter to search for additional mail accounts: $filter", \LOG_NOTICE, self::LOG_KEY);
|
$this->logger->Write("Used ldap filter to search for additional mail accounts: $filter", \LOG_NOTICE, self::LOG_KEY);
|
||||||
|
|
||||||
//Set together the attributes to search inside the LDAP
|
//Set together the attributes to search inside the LDAP
|
||||||
$ldapAttributes = ['dn', $usernameField, $nameField, $domainField];
|
$ldapAttributes = ['dn', $usernameField, $nameField, $domainField, $mailAddressFieldAdditionalAccount];
|
||||||
if ($overwriteMailMainAccount)
|
if ($overwriteMailMainAccount)
|
||||||
{
|
{
|
||||||
\array_push($ldapAttributes, $mailAddressFieldMainAccount);
|
\array_push($ldapAttributes, $mailAddressFieldMainAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($overwriteMailAdditionalAccount)
|
|
||||||
{
|
|
||||||
\array_push($ldapAttributes, $mailAddressFieldAdditionalAccount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$ldapResult = @ldap_search($this->ldap, $searchBase, $filter, $ldapAttributes);
|
$ldapResult = @ldap_search($this->ldap, $searchBase, $filter, $ldapAttributes);
|
||||||
if (!$ldapResult) {
|
if (!$ldapResult) {
|
||||||
$this->HandleLdapError("Fetch $objectClass");
|
$this->HandleLdapError("Fetch $objectClass");
|
||||||
|
@ -346,7 +330,7 @@ class LdapMailAccounts
|
||||||
$result->domain = $this->RemoveEventualLocalPart($result->domain);
|
$result->domain = $this->RemoveEventualLocalPart($result->domain);
|
||||||
|
|
||||||
$result->mailMainAccount = $this->LdapGetAttribute($entry, $mailAddressFieldMainAccount, true, $overwriteMailMainAccount);
|
$result->mailMainAccount = $this->LdapGetAttribute($entry, $mailAddressFieldMainAccount, true, $overwriteMailMainAccount);
|
||||||
$result->mailAdditionalAccount = $this->LdapGetAttribute($entry, $mailAddressFieldAdditionalAccount, true, $overwriteMailAdditionalAccount);
|
$result->mailAdditionalAccount = $this->LdapGetAttribute($entry, $mailAddressFieldAdditionalAccount, true, true);
|
||||||
|
|
||||||
$results[] = $result;
|
$results[] = $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,9 @@ class LdapMailAccountsConfig
|
||||||
public const CONFIG_FIELD_USERNAME = "field_username";
|
public const CONFIG_FIELD_USERNAME = "field_username";
|
||||||
public const CONFIG_SEARCH_STRING = "search_string";
|
public const CONFIG_SEARCH_STRING = "search_string";
|
||||||
public const CONFIG_FIELD_MAIL_DOMAIN = "field_domain";
|
public const CONFIG_FIELD_MAIL_DOMAIN = "field_domain";
|
||||||
|
public const CONFIG_FIELD_MAIL_ADDRESS_ADDITIONAL_ACCOUNT = "field_mail_address_additional_account";
|
||||||
public const CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_MAIN_ACCOUNT = "bool_overwrite_mail_address_main_account";
|
public const CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_MAIN_ACCOUNT = "bool_overwrite_mail_address_main_account";
|
||||||
public const CONFIG_FIELD_MAIL_ADDRESS_MAIN_ACCOUNT = "field_mail_address_main_account";
|
public const CONFIG_FIELD_MAIL_ADDRESS_MAIN_ACCOUNT = "field_mail_address_main_account";
|
||||||
public const CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_ADDITIONAL_ACCOUNT = "bool_overwrite_mail_address_additional_account";
|
|
||||||
public const CONFIG_FIELD_MAIL_ADDRESS_ADDITIONAL_ACCOUNT = "field_mail_address_additional_account";
|
|
||||||
|
|
||||||
public $server;
|
public $server;
|
||||||
public $protocol;
|
public $protocol;
|
||||||
|
@ -37,7 +36,6 @@ class LdapMailAccountsConfig
|
||||||
public $field_mail_address_main_account;
|
public $field_mail_address_main_account;
|
||||||
public $field_mail_address_additional_account;
|
public $field_mail_address_additional_account;
|
||||||
public $bool_overwrite_mail_address_main_account;
|
public $bool_overwrite_mail_address_main_account;
|
||||||
public $bool_overwrite_mail_address_additional_account;
|
|
||||||
|
|
||||||
public static function MakeConfig(Plugin $config): LdapMailAccountsConfig
|
public static function MakeConfig(Plugin $config): LdapMailAccountsConfig
|
||||||
{
|
{
|
||||||
|
@ -53,10 +51,9 @@ class LdapMailAccountsConfig
|
||||||
$ldap->field_username = trim($config->Get("plugin", self::CONFIG_FIELD_USERNAME));
|
$ldap->field_username = trim($config->Get("plugin", self::CONFIG_FIELD_USERNAME));
|
||||||
$ldap->search_string = trim($config->Get("plugin", self::CONFIG_SEARCH_STRING));
|
$ldap->search_string = trim($config->Get("plugin", self::CONFIG_SEARCH_STRING));
|
||||||
$ldap->field_domain = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_DOMAIN));
|
$ldap->field_domain = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_DOMAIN));
|
||||||
|
$ldap->field_mail_address_additional_account = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_ADDRESS_ADDITIONAL_ACCOUNT));
|
||||||
$ldap->bool_overwrite_mail_address_main_account = $config->Get("plugin", self::CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_MAIN_ACCOUNT);
|
$ldap->bool_overwrite_mail_address_main_account = $config->Get("plugin", self::CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_MAIN_ACCOUNT);
|
||||||
$ldap->field_mail_address_main_account = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_ADDRESS_MAIN_ACCOUNT));
|
$ldap->field_mail_address_main_account = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_ADDRESS_MAIN_ACCOUNT));
|
||||||
$ldap->bool_overwrite_mail_address_additional_account = $config->Get("plugin", self::CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_ADDITIONAL_ACCOUNT);
|
|
||||||
$ldap->field_mail_address_additional_account = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_ADDRESS_ADDITIONAL_ACCOUNT));
|
|
||||||
|
|
||||||
return $ldap;
|
return $ldap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ class LdapMailAccountsPlugin extends AbstractPlugin
|
||||||
public function MapImapCredentialsByLDAP(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oImapClient, \MailSo\Imap\Settings $oSettings)
|
public function MapImapCredentialsByLDAP(\RainLoop\Model\Account $oAccount, \MailSo\Imap\ImapClient $oImapClient, \MailSo\Imap\Settings $oSettings)
|
||||||
{
|
{
|
||||||
//$oSettings->Login = $oAccount->IncLogin();
|
//$oSettings->Login = $oAccount->IncLogin();
|
||||||
|
//$this->Manager()->Actions()->Logger()->Write("E-Mail address: $oSettings->Login", \LOG_WARNING, "LDAP MAIL ACCOUNTS PLUGIN");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function gets called by Account.php
|
// Function gets called by Account.php
|
||||||
|
@ -97,20 +98,6 @@ class LdapMailAccountsPlugin extends AbstractPlugin
|
||||||
->SetDefaultValue("mail"),
|
->SetDefaultValue("mail"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$groupOverwriteAdditionalAccount = new \RainLoop\Plugins\PropertyCollection('Overwrite mail address of additional account');
|
|
||||||
$groupOverwriteAdditionalAccount->exchangeArray([
|
|
||||||
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_BOOL_OVERWRITE_MAIL_ADDRESS_ADDITIONAL_ACCOUNT)->SetLabel('Enabled')
|
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
|
||||||
->SetDefaultValue(false),
|
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_MAIL_ADDRESS_ADDITIONAL_ACCOUNT)
|
|
||||||
->SetLabel("Mail address field for additional account")
|
|
||||||
->SetType(RainLoop\Enumerations\PluginPropertyType::STRING)
|
|
||||||
->SetDescription("The ldap field containing the mail address to use on the found additional mail account.
|
|
||||||
\nThe value found inside ldap will be used as mail address of the additional mail accounts created by this plugin.")
|
|
||||||
->SetDefaultValue("mail"),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_SERVER)
|
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_SERVER)
|
||||||
->SetLabel("LDAP Server URL")
|
->SetLabel("LDAP Server URL")
|
||||||
|
@ -173,15 +160,21 @@ class LdapMailAccountsPlugin extends AbstractPlugin
|
||||||
\nIf this field contains an email address, only the domain-part after the @ is used.")
|
\nIf this field contains an email address, only the domain-part after the @ is used.")
|
||||||
->SetDefaultValue("mail"),
|
->SetDefaultValue("mail"),
|
||||||
|
|
||||||
|
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_MAIL_ADDRESS_ADDITIONAL_ACCOUNT)
|
||||||
|
->SetLabel("Mail address field for additional account")
|
||||||
|
->SetType(RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
|
->SetDescription("The ldap field containing the mail address to use on the found additional mail account.
|
||||||
|
\nThe value found inside ldap will be used as mail address of the additional mail accounts created by this plugin.
|
||||||
|
\nIn most cases this could be the same ldap field as in \"Domain name field of additional account\"")
|
||||||
|
->SetDefaultValue("mail"),
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_NAME)
|
\RainLoop\Plugins\Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_NAME)
|
||||||
->SetLabel("Additional account name field")
|
->SetLabel("Additional account name field")
|
||||||
->SetType(RainLoop\Enumerations\PluginPropertyType::STRING)
|
->SetType(RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
->SetDescription("The field containing the default sender name of the found additional mail account.")
|
->SetDescription("The field containing the default sender name of the found additional mail account.")
|
||||||
->SetDefaultValue("displayName"),
|
->SetDefaultValue("displayName"),
|
||||||
|
|
||||||
$groupOverwriteMainAccount,
|
$groupOverwriteMainAccount
|
||||||
|
|
||||||
$groupOverwriteAdditionalAccount,
|
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue