mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 06:57:03 +03:00
Working prototype.
- Needs check if overwriting mail address is activated - Needs rework on ldap query function (looks up to much data) - Code cleanup is needed
This commit is contained in:
parent
7948e86a07
commit
a8f6dab672
2 changed files with 97 additions and 6 deletions
|
|
@ -46,15 +46,83 @@ class LdapMailAccounts
|
|||
$this->Connect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* AOverwrite 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)
|
||||
{
|
||||
try {
|
||||
$this->EnsureBound();
|
||||
} catch (LdapMailAccountsException $e) {
|
||||
return false; // exceptions are only thrown from the handleerror function that does logging already
|
||||
}
|
||||
|
||||
// Try to get account information. IncLogin() returns the username of the user
|
||||
// and removes the domainname if this was configured inside the domain config.
|
||||
$username = $sEmail;
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
$oDomain = $oActions->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true);
|
||||
if ($oDomain->IncShortLogin()){
|
||||
$username = @ldap_escape($this->RemoveEventualDomainPart($sEmail), "", LDAP_ESCAPE_FILTER);
|
||||
}
|
||||
|
||||
$searchString = $this->config->search_string;
|
||||
|
||||
// Replace placeholders inside the ldap search string with actual values
|
||||
$searchString = str_replace("#USERNAME#", $username, $searchString);
|
||||
$searchString = str_replace("#BASE_DN#", $this->config->base, $searchString);
|
||||
|
||||
$this->logger->Write("ldap search string after replacement of placeholders: $searchString", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
try {
|
||||
$mailAddressResults = $this->FindLdapResults(
|
||||
$this->config->field_search,
|
||||
$searchString,
|
||||
$this->config->base,
|
||||
$this->config->objectclass,
|
||||
$this->config->field_name,
|
||||
$this->config->field_username,
|
||||
$this->config->field_domain,
|
||||
$this->config->bool_overwrite_mail_address_main_account,
|
||||
$this->config->field_mail_address_main_account,
|
||||
$this->config->field_mail_address_additional_account
|
||||
);
|
||||
}
|
||||
catch (LdapMailAccountsException $e) {
|
||||
return false; // exceptions are only thrown from the handleerror function that does logging already
|
||||
}
|
||||
if (count($mailAddressResults) < 1) {
|
||||
$this->logger->Write("Could not find user $username", \LOG_NOTICE, self::LOG_KEY);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($mailAddressResults as $mailAddressResult)
|
||||
{
|
||||
if($mailAddressResult->username === $username) {
|
||||
//$sLogin is 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Add additional mail accounts to the given primary account by looking up the ldap directory
|
||||
*
|
||||
* The ldap lookup has to be configured in the plugin configuration of the extension (in the SnappyMail Admin Panel)
|
||||
* The ldap search string has to be configured in the plugin configuration of the extension (in the SnappyMail Admin Panel)
|
||||
*
|
||||
* @param MainAccount $oAccount
|
||||
* @return bool true if additional accounts have been added or no additional accounts where found in . false if an error occured
|
||||
* @return bool true if additional accounts have been added or no additional accounts where found in ldap. false if an error occured
|
||||
*/
|
||||
public function AddLdapMailAccounts(MainAccount $oAccount): bool
|
||||
{
|
||||
|
|
@ -64,7 +132,7 @@ class LdapMailAccounts
|
|||
return false; // exceptions are only thrown from the handleerror function that does logging already
|
||||
}
|
||||
|
||||
// Try to get account information. Login() returns the username of the user
|
||||
// Try to get account information. IncLogin() 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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue