Revision control

Copy as Markdown

Other Tools

/* 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/. */
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
});
export 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.
const 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.
const 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.openMessageForMessageId(data.slice(4));
}
_handleNewsLink({ data }) {
lazy.MailUtils.handleNewsUri(
data,
Services.wm.getMostRecentWindow("mail:3pane")
);
}
}