From db5fcc067fc0cd1ea572310668d986ba4c2bd60b Mon Sep 17 00:00:00 2001 From: "cavin%netscape.com" Date: Fri, 17 Jan 2003 21:33:55 +0000 Subject: [PATCH] Fix for bug 179958. Get the first folder uri for the selected server. It's INBOX for imap and pop accts and 1st news group for news. r/sr=sspitzer. --- .../resources/content/FilterListDialog.js | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/mailnews/base/search/resources/content/FilterListDialog.js b/mailnews/base/search/resources/content/FilterListDialog.js index 849a3e8ab2c7..b7300d94f33b 100644 --- a/mailnews/base/search/resources/content/FilterListDialog.js +++ b/mailnews/base/search/resources/content/FilterListDialog.js @@ -18,6 +18,8 @@ * Rights Reserved. */ +const MSG_FOLDER_FLAG_INBOX = 0x1000 + var gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); var gEditButton; @@ -165,7 +167,7 @@ function setServer(uri) // root the folder picker to this server gRunFiltersFolderPicker.setAttribute("ref", uri); - + // run filters after the fact not supported by news if (msgFolder.server.type == "nntp" && !msgFolder.isServer) { gRunFiltersFolderPicker.setAttribute("hidden", "true"); @@ -181,10 +183,13 @@ function setServer(uri) gRunFiltersFolderPicker.selectedIndex = 0; } - SetFolderPicker(uri, "runFiltersFolder"); + // Get the first folder uri for this server. INBOX for + // imap and pop accts and 1st news group for news. + var firstFolderURI = getFirstFolderURI(msgFolder); + SetFolderPicker(firstFolderURI, "runFiltersFolder"); updateButtons(); - gCurrentServerURI = uri; + gCurrentServerURI = firstFolderURI; } function toggleFilter(aFilterURI) @@ -584,3 +589,34 @@ function doHelpButton() openHelp("mail-filters"); } +/** + * For a given server folder, get the uri for the first folder. For imap + * and pop it's INBOX and it's the very first group for news accounts. + */ +function getFirstFolderURI(msgFolder) +{ + // Sanity check. + if (! msgFolder.isServer) + return msgFolder.URI; + + try { + // Find Inbox for imap and pop + if (msgFolder.server.type != "nntp") + { + var outNumFolders = new Object(); + var inboxFolder = msgFolder.getFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, outNumFolders); + if (inboxFolder) + return inboxFolder.URI; + else + // If inbox does not exist then use the server uri as default. + return msgFolder.URI; + } + else + // XXX TODO: For news, we should find the 1st group/folder off the news groups. For now use server uri. + return msgFolder.URI; + } + catch (ex) { + dump(ex + "\n"); + } + return msgFolder.URI; +}