mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-22 22:04:43 +08:00
[ldap-contacts-suggestions] Support multiple objectClasses
This is mostly for consistency with the other LDAP attributes.
This commit is contained in:
parent
8eec9d4a8f
commit
3beef5a789
2 changed files with 25 additions and 9 deletions
|
@ -30,7 +30,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sObjectClass = 'inetOrgPerson';
|
||||
private $sObjectClasses = 'inetOrgPerson';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
|
@ -63,7 +63,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
* @param string $sBindDn
|
||||
* @param string $sBindPassword
|
||||
* @param string $sBaseDn
|
||||
* @param string $sObjectClass
|
||||
* @param string $sObjectClasses
|
||||
* @param string $sNameAttributes
|
||||
* @param string $sEmailAttributes
|
||||
* @param string $sUidAttributes
|
||||
|
@ -71,7 +71,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
*
|
||||
* @return \LdapContactsSuggestions
|
||||
*/
|
||||
public function SetConfig($sLdapUri, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidAttributes, $sNameAttributes, $sEmailAttributes, $sAllowedEmails)
|
||||
public function SetConfig($sLdapUri, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClasses, $sUidAttributes, $sNameAttributes, $sEmailAttributes, $sAllowedEmails)
|
||||
{
|
||||
$this->sLdapUri = $sLdapUri;
|
||||
$this->bUseStartTLS = $bUseStartTLS;
|
||||
|
@ -81,7 +81,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
$this->sBindPassword = $sBindPassword;
|
||||
}
|
||||
$this->sBaseDn = $sBaseDn;
|
||||
$this->sObjectClass = $sObjectClass;
|
||||
$this->sObjectClasses = $sObjectClasses;
|
||||
$this->sUidAttributes = $sUidAttributes;
|
||||
$this->sNameAttributes = $sNameAttributes;
|
||||
$this->sEmailAttributes = $sEmailAttributes;
|
||||
|
@ -228,16 +228,30 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
'{imap:port}' => $oAccount->DomainIncPort()
|
||||
));
|
||||
|
||||
$aObjectClasses = empty($this->sObjectClasses) ? array() : \explode(',', $this->sObjectClasses);
|
||||
$aEmails = empty($this->sEmailAttributes) ? array() : \explode(',', $this->sEmailAttributes);
|
||||
$aNames = empty($this->sNameAttributes) ? array() : \explode(',', $this->sNameAttributes);
|
||||
$aUIDs = empty($this->sUidAttributes) ? array() : \explode(',', $this->sUidAttributes);
|
||||
|
||||
$aObjectClasses = \array_map('trim', $aObjectClasses);
|
||||
$aEmails = \array_map('trim', $aEmails);
|
||||
$aNames = \array_map('trim', $aNames);
|
||||
$aUIDs = \array_map('trim', $aUIDs);
|
||||
|
||||
$aFields = \array_merge($aEmails, $aNames, $aUIDs);
|
||||
|
||||
$iObjCount = 0;
|
||||
$sObjFilter = '';
|
||||
foreach ($aObjectClasses as $sItem)
|
||||
{
|
||||
if (!empty($sItem))
|
||||
{
|
||||
$iObjCount++;
|
||||
$sObjFilter .= '(objectClass='.$sItem.')';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$aItems = array();
|
||||
$sSubFilter = '';
|
||||
foreach ($aFields as $sItem)
|
||||
|
@ -249,7 +263,8 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
}
|
||||
}
|
||||
|
||||
$sFilter = '(&(objectclass='.$this->sObjectClass.')';
|
||||
$sFilter = '(&';
|
||||
$sFilter .= (1 < $iObjCount ? '(|' : '').$sObjFilter.(1 < $iObjCount ? ')' : '');
|
||||
$sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : '');
|
||||
$sFilter .= ')';
|
||||
|
||||
|
|
|
@ -46,18 +46,18 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$sBindDn = \trim($this->Config()->Get('plugin', 'bind_dn', ''));
|
||||
$sBindPassword = \trim($this->Config()->Get('plugin', 'bind_password', ''));
|
||||
$sBaseDn = \trim($this->Config()->Get('plugin', 'base_dn', ''));
|
||||
$sObjectClass = \trim($this->Config()->Get('plugin', 'object_class', ''));
|
||||
$sObjectClasses = \trim($this->Config()->Get('plugin', 'object_classes', ''));
|
||||
$sUidAttributes = \trim($this->Config()->Get('plugin', 'uid_attributes', ''));
|
||||
$sNameAttributes = \trim($this->Config()->Get('plugin', 'name_attributes', ''));
|
||||
$sEmailAttributes = \trim($this->Config()->Get('plugin', 'mail_attributes', ''));
|
||||
$sAllowedEmails = \trim($this->Config()->Get('plugin', 'allowed_emails', ''));
|
||||
|
||||
if (0 < \strlen($sLdapUri) && 0 < \strlen($sBaseDn) && 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailAttributes))
|
||||
if (0 < \strlen($sLdapUri) && 0 < \strlen($sBaseDn) && 0 < \strlen($sObjectClasses) && 0 < \strlen($sEmailAttributes))
|
||||
{
|
||||
include_once __DIR__.'/LdapContactsSuggestions.php';
|
||||
|
||||
$oProvider = new LdapContactsSuggestions();
|
||||
$oProvider->SetConfig($sLdapUri, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidAttributes, $sNameAttributes, $sEmailAttributes, $sAllowedEmails);
|
||||
$oProvider->SetConfig($sLdapUri, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClasses, $sUidAttributes, $sNameAttributes, $sEmailAttributes, $sAllowedEmails);
|
||||
|
||||
$mResult[] = $oProvider;
|
||||
}
|
||||
|
@ -87,7 +87,8 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
\RainLoop\Plugins\Property::NewInstance('base_dn')->SetLabel('Search base DN')
|
||||
->SetDescription('DN to use as the search base. Supported tokens: {domain}, {domain:dc}, {email}, {email:user}, {email:domain}, {login}, {imap:login}, {imap:host}, {imap:port}')
|
||||
->SetDefaultValue('ou=People,dc=example,dc=com'),
|
||||
\RainLoop\Plugins\Property::NewInstance('object_class')->SetLabel('objectClass value')
|
||||
\RainLoop\Plugins\Property::NewInstance('object_classes')->SetLabel('objectClasses to use')
|
||||
->SetDescription('LDAP objectClasses to search for, comma separated list')
|
||||
->SetDefaultValue('inetOrgPerson'),
|
||||
\RainLoop\Plugins\Property::NewInstance('uid_attributes')->SetLabel('uid attributes')
|
||||
->SetDescription('LDAP attributes for userids, comma separated list in order of preference')
|
||||
|
|
Loading…
Reference in a new issue