Revision control

Copy as Markdown

Other Tools

/* 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 message identities used by the OpenPGP decryption cache
* distinguish messages from different servers.
*/
"use strict";
const { EnigmailURIs } = ChromeUtils.importESModule(
);
const { EnigmailSingletons } = ChromeUtils.importESModule(
);
function getId(spec) {
return EnigmailURIs.msgIdentificationFromUrl(Services.io.newURI(spec));
}
function sameMessage(spec1, spec2) {
const id1 = getId(spec1);
const id2 = getId(spec2);
return id1.folder === id2.folder && id1.msgNum === id2.msgNum;
}
add_task(function testImap() {
Assert.equal(getId(a).msgNum, "41", "IMAP UID should be the msgNum");
Assert.ok(
sameMessage(a, `${a}?header=filter&emitter=js&examineEncryptedParts=true`),
"the same IMAP message with a query should have the same identity"
);
Assert.ok(
"IMAP messages of different users should have different identities"
);
Assert.ok(
"IMAP messages on different ports should have different identities"
);
Assert.ok(
"IMAP messages on different hosts should have different identities"
);
Assert.ok(
"IMAP messages with different UIDs should have different identities"
);
Assert.ok(
"IMAP messages in different folders should have different identities"
);
});
add_task(function testNews() {
Assert.equal(getId(a).msgNum, "3510", "news key should be the msgNum");
Assert.ok(
sameMessage(a, `${a}&header=filter`),
"the same news message with a query should have the same identity"
);
Assert.ok(
"news messages on different servers should have different identities"
);
});
add_task(function testMailbox() {
const mailDir = PathUtils.toFileURI(
PathUtils.join(PathUtils.tempDir, "Mail")
).replace(/^file:/, "mailbox:");
const a = `${mailDir}/Local%20Folders/Inbox?number=41`;
const b = `${mailDir}/pop.example.com/Inbox?number=41`;
Assert.ok(
sameMessage(a, `${a}&part=1.1&filename=test.eml`),
"the same local message with a query should have the same identity"
);
Assert.ok(
!sameMessage(a, b),
"local messages in different folders should have different identities"
);
});
add_task(function testLastDecryptedMessagePart() {
EnigmailSingletons.clearLastDecryptedMessage();
EnigmailSingletons.lastDecryptedMessage.lastMessageURI = getId(
);
EnigmailSingletons.lastDecryptedMessage.mimePartNumber = "1";
Assert.ok(
EnigmailSingletons.isLastDecryptedMessagePart(idA.folder, idA.msgNum, "1"),
"the decrypted message should be recognized as the last one"
);
Assert.ok(
!EnigmailSingletons.isLastDecryptedMessagePart(idB.folder, idB.msgNum, "1"),
"a message from another account should not be recognized as the last one"
);
EnigmailSingletons.clearLastDecryptedMessage();
});