summaryrefslogtreecommitdiffstats
path: root/comm/mail/actors/MailLinkParent.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/mail/actors/MailLinkParent.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/mail/actors/MailLinkParent.jsm')
-rw-r--r--comm/mail/actors/MailLinkParent.jsm96
1 files changed, 96 insertions, 0 deletions
diff --git a/comm/mail/actors/MailLinkParent.jsm b/comm/mail/actors/MailLinkParent.jsm
new file mode 100644
index 0000000000..6c371658f6
--- /dev/null
+++ b/comm/mail/actors/MailLinkParent.jsm
@@ -0,0 +1,96 @@
+/* vim: set ts=2 sw=2 et tw=80: */
+/* 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/. */
+
+"use strict";
+
+const EXPORTED_SYMBOLS = ["MailLinkParent"];
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ AttachmentInfo: "resource:///modules/AttachmentInfo.sys.mjs",
+});
+
+XPCOMUtils.defineLazyModuleGetters(lazy, {
+ MailServices: "resource:///modules/MailServices.jsm",
+ MailUtils: "resource:///modules/MailUtils.jsm",
+});
+
+class MailLinkParent extends JSWindowActorParent {
+ receiveMessage(value) {
+ switch (value.name) {
+ case "imap:":
+ case "mailbox:":
+ this._handleMailboxLink(value);
+ break;
+ case "mailto:":
+ this._handleMailToLink(value);
+ break;
+ case "mid:":
+ this._handleMidLink(value);
+ break;
+ case "news:":
+ case "snews:":
+ this._handleNewsLink(value);
+ break;
+ default:
+ throw Components.Exception(
+ `Unsupported name=${value.name} url=${value.data}`,
+ Cr.NS_ERROR_ILLEGAL_VALUE
+ );
+ }
+ }
+
+ _handleMailboxLink({ data, target }) {
+ // AttachmentInfo is defined in msgHdrView.js.
+ let url = new URL(data);
+ new lazy.AttachmentInfo({
+ contentType: "",
+ url: data,
+ name: url.searchParams.get("filename"),
+ uri: "",
+ isExternalAttachment: false,
+ }).open(target.browsingContext.topChromeWindow, target.browsingContext.id);
+ }
+
+ _handleMailToLink({ data, target }) {
+ let identity = null;
+
+ // If the document with the link is a message, try to get the identity
+ // from the message and use it when composing.
+ let documentURI = target.windowContext.documentURI;
+ if (documentURI instanceof Ci.nsIMsgMessageUrl) {
+ documentURI.QueryInterface(Ci.nsIMsgMessageUrl);
+ [identity] = lazy.MailUtils.getIdentityForHeader(
+ documentURI.messageHeader
+ );
+ }
+
+ lazy.MailServices.compose.OpenComposeWindowWithURI(
+ undefined,
+ Services.io.newURI(data),
+ identity
+ );
+ }
+
+ _handleMidLink({ data }) {
+ // data is the mid: url.
+ lazy.MailUtils.openMessageByMessageId(data.slice(4));
+ }
+
+ _handleNewsLink({ data }) {
+ Services.ww.openWindow(
+ null,
+ "chrome://messenger/content/messageWindow.xhtml",
+ "_blank",
+ "all,chrome,dialog=no,status,toolbar",
+ Services.io.newURI(data)
+ );
+ }
+}