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/import/modules/BaseProfileImporter.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/import/modules/BaseProfileImporter.jsm')
-rw-r--r-- | comm/mailnews/import/modules/BaseProfileImporter.jsm | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/comm/mailnews/import/modules/BaseProfileImporter.jsm b/comm/mailnews/import/modules/BaseProfileImporter.jsm new file mode 100644 index 0000000000..18c5dce16b --- /dev/null +++ b/comm/mailnews/import/modules/BaseProfileImporter.jsm @@ -0,0 +1,100 @@ +/* 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/. */ + +const EXPORTED_SYMBOLS = ["BaseProfileImporter"]; + +var { setTimeout } = ChromeUtils.importESModule( + "resource://gre/modules/Timer.sys.mjs" +); + +/** + * An object to represent a source profile to import from. + * + * @typedef {object} SourceProfile + * @property {string} name - The profile name. + * @property {nsIFile} dir - The profile location. + * + * An object to represent items to import. + * @typedef {object} ImportItems + * @property {boolean} accounts - Whether to import accounts and settings. + * @property {boolean} addressBooks - Whether to import address books. + * @property {boolean} calendars - Whether to import calendars. + * @property {boolean} mailMessages - Whether to import mail messages. + */ + +/** + * Common interfaces shared by profile importers. + * + * @abstract + */ +class BaseProfileImporter { + /** @type boolean - Whether to allow importing from a user picked dir. */ + USE_FILE_PICKER = true; + + /** @type ImportItems */ + SUPPORTED_ITEMS = { + accounts: true, + addressBooks: true, + calendars: true, + mailMessages: true, + }; + + /** When importing from a zip file, ignoring these folders. */ + IGNORE_DIRS = []; + + /** + * Callback for progress updates. + * + * @param {number} current - Current imported items count. + * @param {number} total - Total items count. + */ + onProgress = () => {}; + + /** + * @returns {SourceProfile[]} Profiles found on this machine. + */ + async getSourceProfiles() { + throw Components.Exception( + `getSourceProfiles not implemented in ${this.constructor.name}`, + Cr.NS_ERROR_NOT_IMPLEMENTED + ); + } + + /** + * Actually start importing things to the current profile. + * + * @param {nsIFile} sourceProfileDir - The source location to import from. + * @param {ImportItems} items - The items to import. + * @returns {boolean} Returns true when accounts have been imported, which + * means a restart is needed. Otherwise, no restart is needed. + */ + async startImport(sourceProfileDir, items) { + throw Components.Exception( + `startImport not implemented in ${this.constructor.name}`, + Cr.NS_ERROR_NOT_IMPLEMENTED + ); + } + + /** + * Reset use_without_mail_account, so that imported accounts are correctly + * rendered in the folderPane. + */ + _onImportAccounts() { + Services.prefs.setBoolPref("app.use_without_mail_account", false); + } + + /** + * Increase _itemsImportedCount by one, and call onProgress. + */ + async _updateProgress() { + this.onProgress(++this._itemsImportedCount, this._itemsTotalCount); + return new Promise(resolve => setTimeout(resolve)); + } + + _logger = console.createInstance({ + prefix: "mail.import", + maxLogLevel: "Warn", + maxLogLevelPref: "mail.import.loglevel", + }); +} |