Bug 1588391 - In WebExtensions folder lookup, don't encode path components for IMAP servers; r=mkmelin

--HG--
extra : rebase_source : c16b59dabdaa7e608c1bb90f1b838368899a8630
extra : amend_source : 9ccefee9c2ea0c8a9caee379810ba7f6221d5dbe
This commit is contained in:
Geoff Lankow 2019-10-15 11:55:27 +13:00
Родитель 6c162ff6af
Коммит dfcc80d890
2 изменённых файлов: 81 добавлений и 7 удалений

Просмотреть файл

@ -1250,11 +1250,16 @@ function folderURIToPath(uri) {
* @return {String}
*/
function folderPathToURI(accountId, path) {
let rootURI = MailServices.accounts.getAccount(accountId).incomingServer
.rootFolder.URI;
let server = MailServices.accounts.getAccount(accountId).incomingServer;
let rootURI = server.rootFolder.URI;
if (path == "/") {
return rootURI;
}
// The .URI property of an IMAP folder doesn't have %-encoded characters.
// If encoded here, the folder lookup service won't find the folder.
if (server.type == "imap") {
return rootURI + path;
}
return (
rootURI +
path

Просмотреть файл

@ -9,6 +9,14 @@ var { ExtensionTestUtils } = ChromeUtils.import(
);
ExtensionTestUtils.init(this);
var imapd = ChromeUtils.import("resource://testing-common/mailnews/imapd.js");
var { nsMailServer } = ChromeUtils.import(
"resource://testing-common/mailnews/maild.js"
);
var { PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
);
add_task(async function test_accounts() {
let extension = ExtensionTestUtils.loadExtension({
async background() {
@ -89,7 +97,7 @@ add_task(async function test_accounts() {
assertDeepEqual(
{
id: account2Id,
name: "Mail for username@hostname",
name: "Mail for xpcshell@localhost",
type: "imap",
folders: [
{
@ -141,13 +149,60 @@ add_task(async function test_accounts() {
result5.folders
);
// Check we can access the folders through folderPathToURI.
for (let folder of result5.folders) {
await browser.messages.list(folder);
}
let result6 = await browser.accounts.get(account2Id);
assertDeepEqual(
[
{
accountId: account2Id,
name: "Inbox",
path: "/INBOX",
type: "inbox",
},
{
accountId: account2Id,
name: "foo bar",
path: "/INBOX/foo bar",
},
{
accountId: account2Id,
name: "Ϟ",
path: "/INBOX/&A94-",
},
{
// The trash folder magically appears at this point.
// It wasn't here before.
accountId: "account2",
name: "Trash",
path: "/Trash",
type: "trash",
},
],
result6.folders
);
// Check we can access the folders through folderPathToURI.
for (let folder of result6.folders) {
await browser.messages.list(folder);
}
browser.test.notifyPass("finished");
},
manifest: {
permissions: ["accountsRead"],
permissions: ["accountsRead", "messagesRead"],
},
});
let daemon = new imapd.imapDaemon();
let server = new nsMailServer(function createHandler(d) {
return new imapd.IMAP_RFC3501_handler(d);
}, daemon);
server.start();
let account1 = createAccount();
await extension.startup();
@ -155,17 +210,31 @@ add_task(async function test_accounts() {
await extension.awaitMessage("create account 2");
let account2 = MailServices.accounts.createAccount();
account2.incomingServer = MailServices.accounts.createIncomingServer(
"username",
"hostname",
addIdentity(account2);
let iServer = MailServices.accounts.createIncomingServer(
"user",
"localhost",
"imap"
);
iServer.port = server.port;
iServer.username = "user";
iServer.password = "password";
account2.incomingServer = iServer;
extension.sendMessage(account2.key);
await extension.awaitMessage("create folders");
let inbox1 = [...account1.incomingServer.rootFolder.subFolders][0];
inbox1.createSubfolder("foo bar", null); // Test our code can handle spaces.
inbox1.createSubfolder("Ϟ", null); // Test our code can handle unicode.
let inbox2 = [...account2.incomingServer.rootFolder.subFolders][0];
inbox2.QueryInterface(Ci.nsIMsgImapMailFolder).hierarchyDelimiter = "/";
inbox2.createSubfolder("foo bar", null); // Test our code can handle spaces.
await PromiseTestUtils.promiseFolderAdded("foo bar");
inbox2.createSubfolder("Ϟ", null); // Test our code can handle unicode.
await PromiseTestUtils.promiseFolderAdded("Ϟ");
extension.sendMessage();
await extension.awaitFinish("finished");