Bug 1881929 - No longer return marked-to-be-expunged or marked-as-deleted messages in messages API. r=aleca
These messages are not usable and should not be touched by the API. Differential Revision: https://phabricator.services.mozilla.com/D204060 --HG-- extra : amend_source : f74f4095830ef7beb4f1869c6c9448c78f2dabc0
This commit is contained in:
Родитель
48a0f44b69
Коммит
36027afb14
|
@ -1270,7 +1270,7 @@ export class MessageList {
|
|||
const messageHeader = this.extension.messageManager.convert(msgHdr, {
|
||||
skipFolder: true,
|
||||
});
|
||||
if (this.log.has(messageHeader.id)) {
|
||||
if (!messageHeader || this.log.has(messageHeader.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1485,6 +1485,14 @@ export class MessageManager {
|
|||
// Cache msgHdr to reduce XPCOM requests.
|
||||
const cachedHdr = new CachedMsgHeader(msgHdr);
|
||||
|
||||
// Skip messages, which are actually deleted.
|
||||
if (
|
||||
cachedHdr.flags &
|
||||
(Ci.nsMsgMessageFlags.IMAPDeleted | Ci.nsMsgMessageFlags.Expunged)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const junkScore =
|
||||
parseInt(cachedHdr.getStringProperty("junkscore"), 10) || 0;
|
||||
const tags = (cachedHdr.getStringProperty("keywords") || "")
|
||||
|
@ -1528,7 +1536,20 @@ export class MessageManager {
|
|||
}
|
||||
|
||||
get(id) {
|
||||
return this._messageTracker.getMessage(id);
|
||||
const msgHdr = this._messageTracker.getMessage(id);
|
||||
if (!msgHdr) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Skip messages, which are actually deleted.
|
||||
if (
|
||||
msgHdr.flags &
|
||||
(Ci.nsMsgMessageFlags.IMAPDeleted | Ci.nsMsgMessageFlags.Expunged)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return msgHdr;
|
||||
}
|
||||
|
||||
startMessageList(messageList) {
|
||||
|
|
|
@ -390,7 +390,9 @@ async function getComposeDetails(composeWindow, extension) {
|
|||
composeWindow.gMsgCompose.originalMsgURI
|
||||
);
|
||||
const relatedMessage = extension.messageManager.convert(relatedMsgHdr);
|
||||
relatedMessageId = relatedMessage.id;
|
||||
if (relatedMessage) {
|
||||
relatedMessageId = relatedMessage.id;
|
||||
}
|
||||
} catch (ex) {
|
||||
// We are currently unable to get the fake msgHdr from the uri of messages
|
||||
// opened from file.
|
||||
|
@ -1067,9 +1069,10 @@ var afterSaveSendEventTracker = {
|
|||
|
||||
let convertedMessages;
|
||||
if (listener.extension.messageManager) {
|
||||
convertedMessages = messages.map(cachedMsgHdr =>
|
||||
listener.extension.messageManager.convert(cachedMsgHdr)
|
||||
);
|
||||
convertedMessages = messages.flatmap(cachedMsgHdr => {
|
||||
const msg = listener.extension.messageManager.convert(cachedMsgHdr);
|
||||
return msg ? [msg] : [];
|
||||
});
|
||||
}
|
||||
|
||||
await listener.onSuccess(
|
||||
|
|
|
@ -105,6 +105,9 @@ this.messageDisplay = class extends ExtensionAPIPersistent {
|
|||
const nativeTab = event.target.tabOrWindow;
|
||||
const tab = tabManager.wrapTab(nativeTab);
|
||||
const msg = messageManager.convert(event.detail);
|
||||
if (!msg) {
|
||||
return;
|
||||
}
|
||||
fire.async(tab.convert(), msg);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -240,6 +240,9 @@ this.messages = class extends ExtensionAPIPersistent {
|
|||
const { extension } = this;
|
||||
// The msgHdr could be gone after the wakeup, convert it early.
|
||||
const convertedMessage = extension.messageManager.convert(message);
|
||||
if (!convertedMessage) {
|
||||
return;
|
||||
}
|
||||
if (fire.wakeup) {
|
||||
await fire.wakeup();
|
||||
}
|
||||
|
@ -553,7 +556,7 @@ this.messages = class extends ExtensionAPIPersistent {
|
|||
}
|
||||
const messageHeader =
|
||||
context.extension.messageManager.convert(msgHdr);
|
||||
if (messageHeader.id != messageId) {
|
||||
if (!messageHeader || messageHeader.id != messageId) {
|
||||
throw new ExtensionError(
|
||||
"Unexpected Error: Returned message does not equal requested message."
|
||||
);
|
||||
|
|
|
@ -1178,3 +1178,189 @@ add_task(async function test_attached_message_with_missing_headers() {
|
|||
|
||||
cleanUpAccount(_account);
|
||||
});
|
||||
|
||||
add_task(async function test_get_deleted_messages() {
|
||||
const _account = createAccount();
|
||||
const _folder = await createSubfolder(
|
||||
_account.incomingServer.rootFolder,
|
||||
"test1"
|
||||
);
|
||||
await createMessages(_folder, 10);
|
||||
|
||||
const extension = ExtensionTestUtils.loadExtension({
|
||||
files: {
|
||||
"background.js": async () => {
|
||||
const accounts = await browser.accounts.list();
|
||||
browser.test.assertEq(
|
||||
1,
|
||||
accounts.length,
|
||||
"Should find the correct number of accounts"
|
||||
);
|
||||
const foundMessages = new Map();
|
||||
|
||||
for (const account of accounts) {
|
||||
const messageIds = [];
|
||||
|
||||
const folder = account.folders.find(f => f.name == "test1");
|
||||
const { messages: listMessages } = await browser.messages.list(
|
||||
folder.id
|
||||
);
|
||||
browser.test.assertEq(
|
||||
10,
|
||||
listMessages.length,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
const { messages: queryMessages } = await browser.messages.query({
|
||||
folderId: folder.id,
|
||||
});
|
||||
browser.test.assertEq(
|
||||
10,
|
||||
queryMessages.length,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
|
||||
let counts = 0;
|
||||
for (const msg of listMessages) {
|
||||
messageIds.push(msg.id);
|
||||
const header = await browser.messages.get(msg.id);
|
||||
if (header) {
|
||||
counts++;
|
||||
}
|
||||
}
|
||||
browser.test.assertEq(
|
||||
10,
|
||||
counts,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
foundMessages.set(account.id, messageIds);
|
||||
}
|
||||
|
||||
await window.sendMessage("markSomeAsIMAPDeleted", 3);
|
||||
|
||||
for (const account of accounts) {
|
||||
const folder = account.folders.find(f => f.name == "test1");
|
||||
const { messages: listMessages } = await browser.messages.list(
|
||||
folder.id
|
||||
);
|
||||
browser.test.assertEq(
|
||||
7,
|
||||
listMessages.length,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
const { messages: queryMessages } = await browser.messages.query({
|
||||
folderId: folder.id,
|
||||
});
|
||||
browser.test.assertEq(
|
||||
7,
|
||||
queryMessages.length,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
|
||||
const messageIds = foundMessages.get(account.id);
|
||||
let goodCounts = 0;
|
||||
let badCounts = 0;
|
||||
for (const msgId of messageIds) {
|
||||
try {
|
||||
const header = await browser.messages.get(msgId);
|
||||
if (header) {
|
||||
goodCounts++;
|
||||
}
|
||||
} catch (ex) {
|
||||
badCounts++;
|
||||
}
|
||||
}
|
||||
browser.test.assertEq(
|
||||
7,
|
||||
goodCounts,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
browser.test.assertEq(
|
||||
3,
|
||||
badCounts,
|
||||
"Should find the correct number of skipped messages"
|
||||
);
|
||||
}
|
||||
|
||||
await window.sendMessage("markSomeAsExpunged", 6);
|
||||
|
||||
for (const account of accounts) {
|
||||
const folder = account.folders.find(f => f.name == "test1");
|
||||
const { messages: listMessages } = await browser.messages.list(
|
||||
folder.id
|
||||
);
|
||||
browser.test.assertEq(
|
||||
4,
|
||||
listMessages.length,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
const { messages: queryMessages } = await browser.messages.query({
|
||||
folderId: folder.id,
|
||||
});
|
||||
browser.test.assertEq(
|
||||
4,
|
||||
queryMessages.length,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
|
||||
const messageIds = foundMessages.get(account.id);
|
||||
let goodCounts = 0;
|
||||
let badCounts = 0;
|
||||
for (const msgId of messageIds) {
|
||||
try {
|
||||
const header = await browser.messages.get(msgId);
|
||||
if (header) {
|
||||
goodCounts++;
|
||||
}
|
||||
} catch (ex) {
|
||||
badCounts++;
|
||||
}
|
||||
}
|
||||
browser.test.assertEq(
|
||||
4,
|
||||
goodCounts,
|
||||
"Should find the correct number of messages"
|
||||
);
|
||||
browser.test.assertEq(
|
||||
6,
|
||||
badCounts,
|
||||
"Should find the correct number of skipped messages"
|
||||
);
|
||||
}
|
||||
|
||||
browser.test.notifyPass("finished");
|
||||
},
|
||||
"utils.js": await getUtilsJS(),
|
||||
},
|
||||
manifest: {
|
||||
manifest_version: 2,
|
||||
background: { scripts: ["utils.js", "background.js"] },
|
||||
permissions: ["accountsRead", "messagesRead"],
|
||||
},
|
||||
});
|
||||
|
||||
extension.onMessage("markSomeAsIMAPDeleted", count => {
|
||||
const messages = _folder.messages;
|
||||
while (messages.hasMoreElements() && count > 0) {
|
||||
const msg = messages.getNext();
|
||||
msg.flags |= Ci.nsMsgMessageFlags.IMAPDeleted;
|
||||
count--;
|
||||
}
|
||||
extension.sendMessage();
|
||||
});
|
||||
|
||||
extension.onMessage("markSomeAsExpunged", count => {
|
||||
const messages = _folder.messages;
|
||||
while (messages.hasMoreElements() && count > 0) {
|
||||
const msg = messages.getNext();
|
||||
msg.flags |= Ci.nsMsgMessageFlags.Expunged;
|
||||
count--;
|
||||
}
|
||||
extension.sendMessage();
|
||||
});
|
||||
|
||||
await extension.startup();
|
||||
await extension.awaitFinish("finished");
|
||||
await extension.unload();
|
||||
|
||||
cleanUpAccount(_account);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче