diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/addrbook/src/AbAutoCompleteMyDomain.jsm | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/addrbook/src/AbAutoCompleteMyDomain.jsm')
-rw-r--r-- | comm/mailnews/addrbook/src/AbAutoCompleteMyDomain.jsm | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/comm/mailnews/addrbook/src/AbAutoCompleteMyDomain.jsm b/comm/mailnews/addrbook/src/AbAutoCompleteMyDomain.jsm new file mode 100644 index 0000000000..08a2654d03 --- /dev/null +++ b/comm/mailnews/addrbook/src/AbAutoCompleteMyDomain.jsm @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var EXPORTED_SYMBOLS = ["AbAutoCompleteMyDomain"]; + +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); + +function AbAutoCompleteMyDomain() {} + +AbAutoCompleteMyDomain.prototype = { + QueryInterface: ChromeUtils.generateQI(["nsIAutoCompleteSearch"]), + + cachedIdKey: "", + cachedIdentity: null, + + applicableHeaders: new Set(["addr_to", "addr_cc", "addr_bcc", "addr_reply"]), + + startSearch(aString, aSearchParam, aResult, aListener) { + let params = aSearchParam ? JSON.parse(aSearchParam) : {}; + let applicable = + "type" in params && this.applicableHeaders.has(params.type); + const ACR = Ci.nsIAutoCompleteResult; + var address = null; + if (applicable && aString && !aString.includes(",")) { + if ("idKey" in params && params.idKey != this.cachedIdKey) { + this.cachedIdentity = MailServices.accounts.getIdentity(params.idKey); + this.cachedIdKey = params.idKey; + } + if (this.cachedIdentity.autocompleteToMyDomain) { + address = aString.includes("@") + ? aString + : this.cachedIdentity.email.replace(/[^@]*/, aString); + } + } + + var result = { + searchString: aString, + searchResult: address ? ACR.RESULT_SUCCESS : ACR.RESULT_FAILURE, + defaultIndex: -1, + errorDescription: null, + matchCount: address ? 1 : 0, + getValueAt() { + return address; + }, + getLabelAt() { + return this.getValueAt(); + }, + getCommentAt() { + return null; + }, + getStyleAt() { + return "default-match"; + }, + getImageAt() { + return null; + }, + getFinalCompleteValueAt(aIndex) { + return this.getValueAt(aIndex); + }, + removeValueAt() {}, + }; + aListener.onSearchResult(this, result); + }, + + stopSearch() {}, +}; |