Bug 1817914 - Allow virtual folders to search all folders. r=aleca

… where "all" means all folders in all accounts except trash, junk, outbox and virtual folders.

For these special virtual folders, choosing the folders to search will happen every time the
virtual folder is opened, instead of when it is created, avoiding problems keeping up with changes
such as new account creation.

Differential Revision: https://phabricator.services.mozilla.com/D179328

--HG--
extra : rebase_source : 552c6e2cb0fe05be7b8ca027f56c776364fa3394
extra : absorb_source : 863897ab278583559068f05f2925a74d71d05bbe
This commit is contained in:
Geoff Lankow 2023-05-25 20:36:39 +12:00
Родитель 705f728910
Коммит f084280177
6 изменённых файлов: 59 добавлений и 30 удалений

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

@ -1173,21 +1173,6 @@ var folderPane = {
return folder;
}
let unwantedFlags =
Ci.nsMsgFolderFlags.Trash |
Ci.nsMsgFolderFlags.Junk |
Ci.nsMsgFolderFlags.Queue |
Ci.nsMsgFolderFlags.Virtual;
let searchFolders = [];
for (let server of MailServices.accounts.allServers) {
searchFolders.push(server.rootFolder);
for (let f of server.rootFolder.descendants) {
if (!f.isSpecialFolder(unwantedFlags, true)) {
searchFolders.push(f);
}
}
}
folder = this._tagsFolder.createLocalSubfolder(tag.key);
folder.flags |= Ci.nsMsgFolderFlags.Virtual;
folder.prettyName = tag.tag;
@ -1199,10 +1184,7 @@ var folderPane = {
"searchStr",
`AND (tag,contains,${tag.key})`
);
folderInfo.setCharProperty(
"searchFolderUri",
searchFolders.map(f => f.URI).join("|")
);
folderInfo.setCharProperty("searchFolderUri", "*");
folderInfo.setUint32Property(
"searchFolderFlag",
Ci.nsMsgFolderFlags.Inbox

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

@ -151,15 +151,17 @@ function checkVirtualFolder(tagKey, tagLabel, expectedFolderURIs) {
let wrappedFolder = VirtualFolderHelper.wrapVirtualFolder(folder);
Assert.equal(folder.prettyName, tagLabel);
Assert.equal(wrappedFolder.searchString, `AND (tag,contains,${tagKey})`);
Assert.equal(wrappedFolder.searchFolderURIs, "*");
about3Pane.displayFolder(folder);
Assert.deepEqual(
wrappedFolder.searchFolders.map(f => f.URI).sort(),
about3Pane.gViewWrapper._underlyingFolders.map(f => f.URI).sort(),
expectedFolderURIs.sort()
);
}
add_task(async function testFolderSelection() {
let expectedFolderURIs = [
rootFolder.URI,
folders.Inbox.URI,
folders.Drafts.URI,
folders.Templates.URI,
@ -180,7 +182,7 @@ add_task(async function testFolderSelection() {
// Add a subfolder to the inbox. It should be added to the searched folders.
let newInboxFolder = folders.Inbox.createLocalSubfolder("tagsModeInbox2");
expectedFolderURIs.push(newInboxFolder.URI);
checkVirtualFolder("$label1", "Important", expectedFolderURIs);
checkVirtualFolder("$label2", "Work", expectedFolderURIs);
// Add a subfolder to the trash. It should NOT be added to the searched folders.
folders.Trash.createLocalSubfolder("tagsModeTrash2");
@ -196,9 +198,8 @@ add_task(async function testFolderSelection() {
await TestUtils.waitForCondition(() => rssRootFolder.subFolders.length == 2);
let rssFeedFolder = rssRootFolder.getChildNamed("Test Feed");
expectedFolderURIs.push(rssRootFolder.URI);
expectedFolderURIs.push(rssFeedFolder.URI);
checkVirtualFolder("$label1", "Important", expectedFolderURIs);
checkVirtualFolder("$label2", "Work", expectedFolderURIs);
// Delete the smart mailboxes server and check it is correctly recreated.
about3Pane.folderPane.activeModes = ["all"];

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

@ -997,10 +997,29 @@ DBViewWrapper.prototype = {
// - retrieve virtual folder configuration
if (aFolder.flags & Ci.nsMsgFolderFlags.Virtual) {
let virtFolder = VirtualFolderHelper.wrapVirtualFolder(aFolder);
// Filter out the server roots; they only exist for UI reasons.
this._underlyingFolders = virtFolder.searchFolders.filter(
folder => !folder.isServer
);
if (virtFolder.searchFolderURIs == "*") {
// This is a special virtual folder that searches all folders in all
// accounts (except the unwanted types listed). Get those folders now.
let unwantedFlags =
Ci.nsMsgFolderFlags.Trash |
Ci.nsMsgFolderFlags.Junk |
Ci.nsMsgFolderFlags.Queue |
Ci.nsMsgFolderFlags.Virtual;
this._underlyingFolders = [];
for (let server of MailServices.accounts.allServers) {
for (let f of server.rootFolder.descendants) {
if (!f.isSpecialFolder(unwantedFlags, true)) {
this._underlyingFolders.push(f);
}
}
}
} else {
// Filter out the server roots; they only exist for UI reasons.
this._underlyingFolders = virtFolder.searchFolders.filter(
folder => !folder.isServer
);
}
this._underlyingData =
this._underlyingFolders.length > 1
? this.kUnderlyingMultipleFolder

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

@ -2894,6 +2894,11 @@ nsresult nsMsgAccountManager::WriteLineToOutputStream(
* @param buffer On input, list of folder uri's, on output, verified list.
*/
void nsMsgAccountManager::ParseAndVerifyVirtualFolderScope(nsCString& buffer) {
if (buffer.Equals("*")) {
// This is a special virtual folder that searches all folders in all
// accounts. Folders are chosen by the front end at search time.
return;
}
nsCString verifiedFolders;
nsTArray<nsCString> folderUris;
ParseString(buffer, '|', folderUris);
@ -2919,6 +2924,10 @@ void nsMsgAccountManager::ParseAndVerifyVirtualFolderScope(nsCString& buffer) {
// This conveniently works to add a single folder as well.
nsresult nsMsgAccountManager::AddVFListenersForVF(
nsIMsgFolder* virtualFolder, const nsCString& srchFolderUris) {
if (srchFolderUris.Equals("*")) {
return NS_OK;
}
nsresult rv;
if (!m_dbService) {
m_dbService = do_GetService("@mozilla.org/msgDatabase/msgDBService;1", &rv);

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

@ -26,9 +26,11 @@ function run_test() {
localMailDir.append("Mail");
localMailDir.append("Local Folders");
localMailDir.append("unread-local");
localMailDir.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
localMailDir.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
localMailDir.leafName = "invalidserver-local";
localMailDir.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
localMailDir.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
localMailDir.leafName = "$label1";
localMailDir.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
MailServices.accounts.loadVirtualFolders();
let unreadLocal =
@ -48,4 +50,15 @@ function run_test() {
searchScope =
invalidServer.msgDatabase.dBFolderInfo.getCharProperty("searchFolderUri");
Assert.equal(searchScope, "mailbox://nobody@Local%20Folders/Inbox");
let tagsFolder =
localAccountUtils.incomingServer.rootMsgFolder.getChildNamed("$label1");
Assert.equal(
tagsFolder.msgDatabase.dBFolderInfo.getCharProperty("searchFolderUri"),
"*"
);
Assert.equal(
tagsFolder.msgDatabase.dBFolderInfo.getCharProperty("searchStr"),
"AND (tag,contains,$label1)"
);
}

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

@ -7,3 +7,8 @@ uri=mailbox://nobody@Local%20Folders/invalidserver-local
scope=mailbox://nobody@Local%20Folders/Inbox|user@foo/INBOX
terms=ALL
searchOnline=false
uri=mailbox://nobody@Local%20Folders/%24label1
searchFolderFlag=1000
scope=*
terms=AND (tag,contains,$label1)
searchOnline=false