Whenever an LDAP query is sent to a Microsoft Exchange's Active Directory via LDAP, the results are extremely slow to come. This is definitely an Exchange bug -- it appears to timeout in searching and then replies after 120 seconds. However, there's a specific field of the LDAP query that triggers it and it can be worked around.
In (kdepim) libkdepim/ldap/ldapclientsearch.cpp, we have:
const QString filter = QString( "&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))"
.arg( d->mSearchText ).arg( d->mSearchText )
.arg( d->mSearchText ).arg( d->mSearchText ).arg( d->mSearchText );
The field that causes the slowdown is the (mail=*@%3*) part. In fact, it appears that Exchange is slow for any query that starts with * in the field. If that part of the query is removed, the server replies in reasonable time.
Steps to Reproduce:
1. Set up LDAP to an Exchange AD server
2. Open a KMail Composer window
3. Start typing someone's name, surname or email address
No search results are shown for 2 minutes. That's because no network traffic occurs for those 2 minutes: the server does not reply.
Search results come quickly.
PS: it's not necessary to have 4 .arg() calls with the same value. Replacing all of the fields with %1 and using one .arg() call is enough.
Problem if I remove "(mail=*@%3*)" we will not able to search address as "*@mandriva*"
Will investigate if there is another method to do it.
(In reply to comment #1)
> Problem if I remove "(mail=*@%3*)" we will not able to search address as
I know. The thing is that Exchange is often used in corporate environments, which means that search will either have no results, or it'll match *everyone* (Intel's servers only have @intel.com people listed).
Anyway, looks like Exchange doesn't like any queries beginning with *.
Yes it's right by default a ldap will search in one server so search for *@intel.com or other is not useful.
Ok will remove it.
Will do soon.
Git commit aea27876c7f3a7232727204b053a8953d5f67c81 by Montel Laurent.
Committed on 08/08/2013 at 10:48.
Pushed by mlaurent into branch 'KDE/4.11'.
Fix Bug 323272 - Querying a Microsoft Exchange's Active Directory via LDAP is extremely slow
M +6 -0 libkdepim/ldap/ldapclientsearch.cpp