Bug 550414 - Use current identity's compose format for mailto: links. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D227526 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
a04d4cd951
Коммит
e84f16660d
|
@ -2036,10 +2036,9 @@ function getEmail(url) {
|
|||
* default identity is used.
|
||||
*/
|
||||
function composeEmailTo(linkURL, identity) {
|
||||
const uri = Services.io.newURI(linkURL);
|
||||
const params = MailServices.compose.getParamsForMailto(uri);
|
||||
if (identity) {
|
||||
params.identity = identity;
|
||||
}
|
||||
MailServices.compose.OpenComposeWindowWithParams(null, params);
|
||||
MailServices.compose.OpenComposeWindowWithURI(
|
||||
null,
|
||||
Services.io.newURI(linkURL),
|
||||
identity
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3232,7 +3232,8 @@ const gMessageHeader = {
|
|||
openListURL(event) {
|
||||
const url = event.target.value;
|
||||
if (url.startsWith("mailto:")) {
|
||||
top.composeEmailTo(url, MailUtils.getIdentityForHeader(gMessage));
|
||||
const [identity] = MailUtils.getIdentityForHeader(gMessage);
|
||||
top.composeEmailTo(url, identity);
|
||||
return;
|
||||
}
|
||||
openUILink(url, event);
|
||||
|
|
|
@ -848,10 +848,8 @@
|
|||
) {
|
||||
event.preventDefault();
|
||||
if (event.target.href.startsWith("mailto:")) {
|
||||
top.composeEmailTo(
|
||||
event.target.href,
|
||||
lazy.MailUtils.getIdentityForHeader(gMessage)
|
||||
);
|
||||
const [identity] = lazy.MailUtils.getIdentityForHeader(gMessage);
|
||||
top.composeEmailTo(event.target.href, identity);
|
||||
return;
|
||||
}
|
||||
openUILink(event.target.href, event);
|
||||
|
|
|
@ -90,6 +90,7 @@ reason = Cannot open the Format menu
|
|||
[browser_inlineImage.js]
|
||||
skip-if = headless # clipboard doesn't work with headless
|
||||
[browser_linkPreviews.js]
|
||||
[browser_mailtoComposeFormat.js]
|
||||
[browser_messageBody.js]
|
||||
[browser_multipartRelated.js]
|
||||
[browser_newmsgComposeIdentity.js]
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/* 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/. */
|
||||
|
||||
/**
|
||||
* Tests that clicking a mailto: link in the message body chooses the correct
|
||||
* identity and format (HTML/plain text) for the compose window.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
var { close_compose_window, compose_window_ready } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/mail/ComposeHelpers.sys.mjs"
|
||||
);
|
||||
|
||||
var {
|
||||
add_message_to_folder,
|
||||
assert_selected_and_displayed,
|
||||
be_in_folder,
|
||||
create_message,
|
||||
get_about_message,
|
||||
select_click_row,
|
||||
} = ChromeUtils.importESModule(
|
||||
"resource://testing-common/mail/FolderDisplayHelpers.sys.mjs"
|
||||
);
|
||||
|
||||
var { promise_new_window } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/mail/WindowHelpers.sys.mjs"
|
||||
);
|
||||
|
||||
var accountA, accountB;
|
||||
var identityA0, identityB0, identityB1;
|
||||
var inboxA, inboxB;
|
||||
|
||||
add_setup(async function () {
|
||||
const createTestMessage = async (folder, identity) => {
|
||||
await add_message_to_folder(
|
||||
[folder],
|
||||
create_message({
|
||||
from: "Tester <test@example.org>",
|
||||
to: identity.email,
|
||||
subject: `Mailto Test`,
|
||||
body: {
|
||||
body: `<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<a href="mailto:mailtoRecipient@example.org" id="mailtolink">Mailto Link</a>
|
||||
</body>
|
||||
<hml>`,
|
||||
contentType: "text/html",
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
accountA = MailServices.accounts.createAccount();
|
||||
accountA.incomingServer = MailServices.accounts.createIncomingServer(
|
||||
"someone",
|
||||
"accountA.invalid",
|
||||
"pop3"
|
||||
);
|
||||
|
||||
accountB = MailServices.accounts.createAccount();
|
||||
accountB.incomingServer = MailServices.accounts.createIncomingServer(
|
||||
"someone",
|
||||
"accountB.invalid",
|
||||
"pop3"
|
||||
);
|
||||
|
||||
inboxA = accountA.incomingServer.rootFolder.getFolderWithFlags(
|
||||
Ci.nsMsgFolderFlags.Inbox
|
||||
);
|
||||
inboxB = accountB.incomingServer.rootFolder.getFolderWithFlags(
|
||||
Ci.nsMsgFolderFlags.Inbox
|
||||
);
|
||||
|
||||
identityA0 = MailServices.accounts.createIdentity();
|
||||
identityA0.email = "someone@accountA.invalid";
|
||||
accountA.addIdentity(identityA0);
|
||||
|
||||
identityB0 = MailServices.accounts.createIdentity();
|
||||
identityB0.email = "someone@accountB.invalid";
|
||||
accountB.addIdentity(identityB0);
|
||||
|
||||
identityB1 = MailServices.accounts.createIdentity();
|
||||
identityB1.email = "someone.else@accountB.invalid";
|
||||
accountB.addIdentity(identityB1);
|
||||
|
||||
await createTestMessage(inboxA, identityA0);
|
||||
await createTestMessage(inboxB, identityB1);
|
||||
await createTestMessage(inboxB, identityB0);
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
accountB.removeIdentity(identityB1);
|
||||
identityB0.clearAllValues();
|
||||
MailServices.accounts.removeAccount(accountB, true);
|
||||
identityA0.clearAllValues();
|
||||
MailServices.accounts.removeAccount(accountA, true);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_mailto_links() {
|
||||
const subTest = async (formatA0, formatB0, formatB1) => {
|
||||
const clickMailtoLink = async (folder, identity, row = 0) => {
|
||||
await be_in_folder(folder);
|
||||
const msg = await select_click_row(row);
|
||||
await assert_selected_and_displayed(window, msg);
|
||||
|
||||
const composePromise = promise_new_window("msgcompose");
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter(
|
||||
"#mailtolink",
|
||||
{},
|
||||
get_about_message().getMessagePaneBrowser()
|
||||
);
|
||||
const cwc = await compose_window_ready(composePromise);
|
||||
|
||||
Assert.equal(
|
||||
cwc.gMsgCompose.identity,
|
||||
identity,
|
||||
"The correct identity should be selected."
|
||||
);
|
||||
Assert.equal(
|
||||
cwc.gMsgCompose.composeHTML,
|
||||
identity.composeHtml,
|
||||
"Compose HTML should match the identity's setting."
|
||||
);
|
||||
|
||||
await close_compose_window(cwc);
|
||||
};
|
||||
|
||||
identityA0.composeHtml = formatA0;
|
||||
identityB0.composeHtml = formatB0;
|
||||
identityB1.composeHtml = formatB1;
|
||||
await clickMailtoLink(inboxA, identityA0);
|
||||
await clickMailtoLink(inboxB, identityB0);
|
||||
await clickMailtoLink(inboxB, identityB1, 1);
|
||||
};
|
||||
|
||||
await subTest(true, false, true);
|
||||
await subTest(false, true, false);
|
||||
});
|
|
@ -90,10 +90,15 @@ interface nsIMsgComposeService : nsISupports {
|
|||
[noscript] boolean determineComposeHTML(in nsIMsgIdentity aIdentity, in MSG_ComposeFormat aFormat);
|
||||
|
||||
/**
|
||||
* given a mailto url, parse the attributes and turn them into a nsIMsgComposeParams object
|
||||
* @return nsIMsgComposeParams which corresponds to the passed in mailto url
|
||||
* Given a mailto url and an optional identity, parse the attributes and turn
|
||||
* them into a nsIMsgComposeParams object.
|
||||
*
|
||||
* @param aURI The mailto url to parse.
|
||||
* @param aIdentity An optional identity to send the message from.
|
||||
|
||||
* @return nsIMsgComposeParams which corresponds to the passed in data.
|
||||
*/
|
||||
nsIMsgComposeParams getParamsForMailto(in nsIURI aURI);
|
||||
nsIMsgComposeParams getParamsForMailto(in nsIURI aURI, [optional] in nsIMsgIdentity aIdentity);
|
||||
|
||||
/**
|
||||
* @{
|
||||
|
|
|
@ -425,7 +425,7 @@ nsMsgComposeService::OpenComposeWindow(
|
|||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(
|
||||
nsIURI* aURI, nsIMsgComposeParams** aParams) {
|
||||
nsIURI* aURI, nsIMsgIdentity* aIdentity, nsIMsgComposeParams** aParams) {
|
||||
nsresult rv = NS_OK;
|
||||
if (aURI) {
|
||||
nsCString spec;
|
||||
|
@ -454,7 +454,8 @@ NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(
|
|||
nsAutoString sanitizedBody;
|
||||
|
||||
bool composeHTMLFormat;
|
||||
DetermineComposeHTML(NULL, requestedComposeFormat, &composeHTMLFormat);
|
||||
DetermineComposeHTML(aIdentity, requestedComposeFormat,
|
||||
&composeHTMLFormat);
|
||||
|
||||
// If there was an 'html-body' param, finding it will have requested
|
||||
// HTML format in GetMessageContents, so we try to use it first. If it's
|
||||
|
@ -493,6 +494,9 @@ NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(
|
|||
pMsgComposeParams->SetFormat(composeHTMLFormat
|
||||
? nsIMsgCompFormat::HTML
|
||||
: nsIMsgCompFormat::PlainText);
|
||||
if (aIdentity) {
|
||||
pMsgComposeParams->SetIdentity(aIdentity);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMsgCompFields> pMsgCompFields(do_CreateInstance(
|
||||
"@mozilla.org/messengercompose/composefields;1", &rv));
|
||||
|
@ -522,12 +526,10 @@ NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(
|
|||
NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(
|
||||
const char* aMsgComposeWindowURL, nsIURI* aURI, nsIMsgIdentity* identity) {
|
||||
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams;
|
||||
nsresult rv = GetParamsForMailto(aURI, getter_AddRefs(pMsgComposeParams));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
pMsgComposeParams->SetIdentity(identity);
|
||||
rv = OpenComposeWindowWithParams(aMsgComposeWindowURL, pMsgComposeParams);
|
||||
}
|
||||
return rv;
|
||||
nsresult rv =
|
||||
GetParamsForMailto(aURI, identity, getter_AddRefs(pMsgComposeParams));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return OpenComposeWindowWithParams(aMsgComposeWindowURL, pMsgComposeParams);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgComposeService::InitCompose(nsIMsgComposeParams* aParams,
|
||||
|
|
Загрузка…
Ссылка в новой задаче