diff options
Diffstat (limited to 'comm/mailnews/base/src/MsgProtocolInfo.sys.mjs')
-rw-r--r-- | comm/mailnews/base/src/MsgProtocolInfo.sys.mjs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/comm/mailnews/base/src/MsgProtocolInfo.sys.mjs b/comm/mailnews/base/src/MsgProtocolInfo.sys.mjs new file mode 100644 index 0000000000..7c9088e12e --- /dev/null +++ b/comm/mailnews/base/src/MsgProtocolInfo.sys.mjs @@ -0,0 +1,53 @@ +/* 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/. */ + +/** + * @see {nsIMsgProtocolInfo} + */ +export class MsgProtocolInfo { + get defaultLocalPath() { + let file = this._getFileValue(this.RELATIVE_PREF, this.ABSOLUTE_PREF); + if (!file) { + file = Services.dirsvc.get(this.DIR_SERVICE_PROP, Ci.nsIFile); + this._setFileValue(this.RELATIVE_PREF, this.ABSOLUTE_PREF, file); + } + if (!file.exists()) { + file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o775); + } + file.normalize(); + return file; + } + + set defaultLocalPath(value) { + this._setFileValue(this.RELATIVE_PREF, this.ABSOLUTE_PREF, value); + } + + _getFileValue(relPrefName, absPrefName) { + try { + return Services.prefs.getComplexValue(relPrefName, Ci.nsIRelativeFilePref) + .file; + } catch (e) { + try { + let file = Services.prefs.getComplexValue(absPrefName, Ci.nsIFile); + Services.prefs.setComplexValue(relPrefName, Ci.nsIRelativeFilePref, { + QueryInterface: ChromeUtils.generateQI(["nsIRelativeFilePref"]), + file, + relativeToKey: "ProfD", + }); + return file; + } catch (e) { + return null; + } + } + } + + _setFileValue(relPrefName, absPrefName, file) { + Services.prefs.setComplexValue(relPrefName, Ci.nsIRelativeFilePref, { + QueryInterface: ChromeUtils.generateQI(["nsIRelativeFilePref"]), + file, + relativeToKey: "ProfD", + }); + Services.prefs.setComplexValue(absPrefName, Ci.nsIFile, file); + } +} |