diff --git a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js index 459be3bf479..d2690ccdf21 100644 --- a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js @@ -1866,8 +1866,19 @@ function LoadIdentity(startup) try { serverURL.spec = prefs.CopyCharPref(autocompleteDirectory + ".uri"); } catch (ex) {dump("ERROR: " + ex + "\n");} - dump("url is " + serverURL.spec +"\n"); session2.serverURL = serverURL; + + // don't search on strings shorter than this + // + try { + session2.minStringLength = + prefs.GetIntPref(autocompleteDirectory + + ".autoComplete.minStringLength"); + } catch (ex) { + // if this pref isn't there, no big deal. just let + // nsLDAPAutoCompleteSession use its default. + } + session2.filterTemplate = "cn="; session2.outputFormat = "cn "; session2.sizeLimit = 10; diff --git a/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl b/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl index 49c34aa8042..8e32fb81c9a 100644 --- a/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl +++ b/mozilla/xpfe/components/autocomplete/public/nsILDAPAutoCompleteSession.idl @@ -62,6 +62,18 @@ interface nsILDAPAutoCompleteSession : nsIAutoCompleteSession { */ attribute long sizeLimit; + /** + * Strings shorter than this will return |nsIAutoCompleteStatus::ignored| + * rather than triggering a search. This allows browsers to be + * configured to not search on substrings so short that they + * aren't indexed by the LDAP server (such searches can use significantly + * more server resources and return a very large number of entries). + * The default is 0, meaning that no such limit is in effect. + * + * @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter + */ + attribute unsigned long minStringLength; + /** * LDAP server to complete against, in ldap: URL format. * May change to an nsILDAPServer once that infrastructure lands. diff --git a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp b/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp index 959278ce1b6..4990c9ead44 100644 --- a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp +++ b/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.cpp @@ -50,7 +50,7 @@ NS_IMPL_ISUPPORTS3(nsLDAPAutoCompleteSession, nsIAutoCompleteSession, nsILDAPMessageListener, nsILDAPAutoCompleteSession) nsLDAPAutoCompleteSession::nsLDAPAutoCompleteSession() : - mState(UNBOUND) + mState(UNBOUND), mMinStringLength(0) { NS_INIT_ISUPPORTS(); } @@ -89,11 +89,13 @@ nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString, mListener = listener; // save it for later callbacks } - // ignore the empty string and strings with @ in them + // ignore the empty string, strings with @ in them, and strings + // that are too short // - if (searchString[0] == 0 || - nsLiteralString(searchString).FindChar(PRUnichar('@'), 0) - != kNotFound) { + if (searchString[0] == 0 || + nsLiteralString(searchString).FindChar(PRUnichar('@'), 0) != + kNotFound || + mMinStringLength && nsCRT::strlen(searchString) < mMinStringLength) { FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored); return NS_OK; @@ -1028,4 +1030,24 @@ nsLDAPAutoCompleteSession::SetServerURL(nsILDAPURL * aServerURL) return NS_OK; } +// attribute unsigned long minStringLength +NS_IMETHODIMP +nsLDAPAutoCompleteSession::GetMinStringLength(PRUint32 *aMinStringLength) +{ + if (!aMinStringLength) { + return NS_ERROR_NULL_POINTER; + } + + *aMinStringLength = mMinStringLength; + return NS_OK; +} +NS_IMETHODIMP +nsLDAPAutoCompleteSession::SetMinStringLength(PRUint32 aMinStringLength) +{ + mMinStringLength = aMinStringLength; + + return NS_OK; +} + + #endif diff --git a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h b/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h index 78b979289e8..1c0fd535707 100644 --- a/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h +++ b/mozilla/xpfe/components/autocomplete/src/nsLDAPAutoCompleteSession.h @@ -61,7 +61,7 @@ class nsLDAPAutoCompleteSession : public nsILDAPMessageListener, nsString mOutputFormat; // how to format output nsCOMPtr mServerURL; // URL for the directory to search PRInt32 mSizeLimit; // return at most this many entries - + PRUint32 mMinStringLength; // strings < this size are ignored // stopgap until nsLDAPService works nsresult InitConnection();