summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/src/MailServices.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/base/src/MailServices.jsm
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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/base/src/MailServices.jsm')
-rw-r--r--comm/mailnews/base/src/MailServices.jsm169
1 files changed, 169 insertions, 0 deletions
diff --git a/comm/mailnews/base/src/MailServices.jsm b/comm/mailnews/base/src/MailServices.jsm
new file mode 100644
index 0000000000..f316b16bde
--- /dev/null
+++ b/comm/mailnews/base/src/MailServices.jsm
@@ -0,0 +1,169 @@
+/* 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 = ["MailServices"];
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+var MailServices = {
+ /**
+ * Gets the `nsIMsgMessageService` for a given message URI. This should have
+ * the same behaviour as `GetMessageServiceFromURI` (nsMsgUtils.cpp).
+ *
+ * @param {string} uri - The URI of a folder or message.
+ * @returns {nsIMsgMessageService}
+ */
+ messageServiceFromURI(uri) {
+ let index = uri.indexOf(":");
+ if (index == -1) {
+ throw new Components.Exception(
+ `Bad message URI: ${uri}`,
+ Cr.NS_ERROR_FAILURE
+ );
+ }
+
+ let protocol = uri.substring(0, index);
+ if (protocol == "file") {
+ protocol = "mailbox";
+ }
+ return Cc[
+ `@mozilla.org/messenger/messageservice;1?type=${protocol}`
+ ].getService(Ci.nsIMsgMessageService);
+ },
+};
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "mailSession",
+ "@mozilla.org/messenger/services/session;1",
+ "nsIMsgMailSession"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "accounts",
+ "@mozilla.org/messenger/account-manager;1",
+ "nsIMsgAccountManager"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "pop3",
+ "@mozilla.org/messenger/popservice;1",
+ "nsIPop3Service"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "imap",
+ "@mozilla.org/messenger/imapservice;1",
+ "nsIImapService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "nntp",
+ "@mozilla.org/messenger/nntpservice;1",
+ "nsINntpService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "smtp",
+ "@mozilla.org/messengercompose/smtp;1",
+ "nsISmtpService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "compose",
+ "@mozilla.org/messengercompose;1",
+ "nsIMsgComposeService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "ab",
+ "@mozilla.org/abmanager;1",
+ "nsIAbManager"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "copy",
+ "@mozilla.org/messenger/messagecopyservice;1",
+ "nsIMsgCopyService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "mfn",
+ "@mozilla.org/messenger/msgnotificationservice;1",
+ "nsIMsgFolderNotificationService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "headerParser",
+ "@mozilla.org/messenger/headerparser;1",
+ "nsIMsgHeaderParser"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "mimeConverter",
+ "@mozilla.org/messenger/mimeconverter;1",
+ "nsIMimeConverter"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "tags",
+ "@mozilla.org/messenger/tagservice;1",
+ "nsIMsgTagService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "filters",
+ "@mozilla.org/messenger/services/filters;1",
+ "nsIMsgFilterService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "junk",
+ "@mozilla.org/messenger/filter-plugin;1?name=bayesianfilter",
+ "nsIJunkMailPlugin"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "newMailNotification",
+ "@mozilla.org/newMailNotificationService;1",
+ "mozINewMailNotificationService"
+);
+
+XPCOMUtils.defineLazyServiceGetter(
+ MailServices,
+ "folderLookup",
+ "@mozilla.org/mail/folder-lookup;1",
+ "nsIFolderLookupService"
+);
+
+// Clean up all of these references at shutdown, so that they don't appear as
+// a memory leak in test logs.
+Services.obs.addObserver(
+ {
+ observe() {
+ for (let key of Object.keys(MailServices)) {
+ delete MailServices[key];
+ }
+ Services.obs.removeObserver(this, "xpcom-shutdown");
+ },
+ },
+ "xpcom-shutdown"
+);