summaryrefslogtreecommitdiffstats
path: root/mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-03 00:17:46 -0400
committerMatt A. Tobin <email@mattatobin.com>2019-11-03 00:17:46 -0400
commit302bf1b523012e11b60425d6eee1221ebc2724eb (patch)
treeb191a895f8716efcbe42f454f37597a545a6f421 /mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
parent21b3f6247403c06f85e1f45d219f87549862198f (diff)
downloadUXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.gz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.lz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.xz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.zip
Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1
Diffstat (limited to 'mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js')
-rw-r--r--mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js b/mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
new file mode 100644
index 000000000..1ace4ca50
--- /dev/null
+++ b/mailnews/addrbook/src/nsAbAutoCompleteMyDomain.js
@@ -0,0 +1,58 @@
+/* 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/. */
+
+Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function nsAbAutoCompleteMyDomain() {}
+
+nsAbAutoCompleteMyDomain.prototype = {
+ classID: Components.ID("{5b259db2-e451-4de9-8a6f-cfba91402973}"),
+ QueryInterface: XPCOMUtils.generateQI([
+ Components.interfaces.nsIAutoCompleteSearch]),
+
+ cachedIdKey: "",
+ cachedIdentity: null,
+
+ applicableHeaders: new Set(["addr_to", "addr_cc", "addr_bcc", "addr_reply"]),
+
+ startSearch: function(aString, aSearchParam, aResult, aListener) {
+ let params = aSearchParam ? JSON.parse(aSearchParam) : {};
+ let applicable = ("type" in params) && this.applicableHeaders.has(params.type);
+ const ACR = Components.interfaces.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: function() { return address; },
+ getLabelAt: function() { return this.getValueAt(); },
+ getCommentAt: function() { return null; },
+ getStyleAt: function() { return "default-match"; },
+ getImageAt: function() { return null; },
+ getFinalCompleteValueAt: function(aIndex) {
+ return this.getValueAt(aIndex);
+ },
+ removeValueAt: function() {}
+ };
+ aListener.onSearchResult(this, result);
+ },
+
+ stopSearch: function() {}
+};
+
+var components = [nsAbAutoCompleteMyDomain];
+var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);