fix bug 562104, crash when subscribed to imap folder '/', r/sr=standard8 COMM193a5_20100623_RELBRANCH
authorDavid Bienvenu <bienvenu@nventure.com>
Thu, 24 Jun 2010 07:24:31 -0700
branchCOMM193a5_20100623_RELBRANCH
changeset 5911 7d067bc2575cbcdd6c283eafd15f0077fb3299e0
parent 5910 51b6b3c86072ca4edb6fb43f572cade8cae4ee1b
child 5912 e0c779269296c7cb2b91b23754c80b4a32e340b7
push idunknown
push userunknown
push dateunknown
bugs562104
fix bug 562104, crash when subscribed to imap folder '/', r/sr=standard8
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/imap/test/unit/test_mailboxes.js
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -1052,16 +1052,18 @@ NS_IMETHODIMP nsImapIncomingServer::Poss
 
   if(NS_FAILED(rv))
     return rv;
 
   nsCAutoString dupFolderPath(folderPath);
   if (dupFolderPath.Last() == '/')
   {
     dupFolderPath.SetLength(dupFolderPath.Length()-1);
+    if (dupFolderPath.IsEmpty())
+      return NS_ERROR_FAILURE;
     // *** this is what we did in 4.x in order to list uw folder only
     // mailbox in order to get the \NoSelect flag
     explicitlyVerify = !(boxFlags & kNameSpace);
   }
   if (mDoingSubscribeDialog)
   {
     // Make sure the imapmailfolder object has the right delimiter because the unsubscribed
     // folders (those not in the 'lsub' list) have the delimiter set to the default ('^').
@@ -1160,17 +1162,18 @@ NS_IMETHODIMP nsImapIncomingServer::Poss
       a_nsIFolder->GetChildWithURI(parentUri, PR_TRUE, caseInsensitive, getter_AddRefs(parent));
       if (!parent /* || parentFolder->GetFolderNeedsAdded()*/)
       {
         PossibleImapMailbox(parentName, hierarchyDelimiter, kNoselect | // be defensive
           ((boxFlags  & //only inherit certain flags from the child
           (kPublicMailbox | kOtherUsersMailbox | kPersonalMailbox))), &parentIsNew);
       }
     }
-    hostFolder->CreateClientSubfolderInfo(dupFolderPath, hierarchyDelimiter,boxFlags, PR_FALSE);
+    rv = hostFolder->CreateClientSubfolderInfo(dupFolderPath, hierarchyDelimiter,boxFlags, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
     caseInsensitive = MsgLowerCaseEqualsLiteral(dupFolderPath, "inbox");
     a_nsIFolder->GetChildWithURI(uri, PR_TRUE, caseInsensitive, getter_AddRefs(child));
   }
   if (child)
   {
     nsCOMPtr <nsIMsgImapMailFolder> imapFolder = do_QueryInterface(child);
     if (imapFolder)
     {
--- a/mailnews/imap/test/unit/test_mailboxes.js
+++ b/mailnews/imap/test/unit/test_mailboxes.js
@@ -54,16 +54,26 @@ const gTestArray =
     gIMAPService.renameLeaf(uiThread, i18nChild, "test \u00E4", UrlListener, null);
   },
   function checkRename() {
     do_check_true(rootFolder.containsChildNamed("test \u00E4"));
     let newChild = rootFolder.getChildNamed("test \u00E4").
                    QueryInterface(Ci.nsIMsgImapMailFolder);
     newChild.updateFolderWithListener(null, UrlListener);
   },
+  function checkEmptyFolder() {
+    try {
+    let serverSink = gLocalServer.QueryInterface(Ci.nsIImapServerSink);
+      serverSink.possibleImapMailbox("/", '/', 0);
+    }
+    catch (ex) {
+      // we expect this to fail, but not crash or assert.
+    }
+    do_timeout_function(0, function(){doTest(++gCurTestNum)});
+  },
 ];
 
 function endTest()
 {
   // Clean up the server in preparation
   gServer.resetTest();
   gLocalServer.closeCachedConnections();
   gServer.performTest();
@@ -75,17 +85,17 @@ function doTest(test)
 {
   if (test <= gTestArray.length)
   {
     dump("Doing test " + test + "\n");
     gCurTestNum = test;
 
     var testFn = gTestArray[test-1];
     // Set a limit of 10 seconds; if the notifications haven't arrived by then there's a problem.
-    do_timeout(10000, function(){
+    do_timeout_function(10000, function(){
         if (gCurTestNum == test) 
           do_throw("Notifications not received in 10000 ms for operation " + testFn.name + 
             ", current status is " + gCurrStatus);
         }
       );
     try {
     testFn();
     } catch(ex) {do_throw(ex);}
@@ -108,11 +118,11 @@ var UrlListener =
 
   OnStopRunningUrl: function (aUrl, aExitCode) {
     // Check: message successfully copied.
     do_check_eq(aExitCode, 0);
     // Ugly hack: make sure we don't get stuck in a JS->C++->JS->C++... call stack
     // This can happen with a bunch of synchronous functions grouped together, and
     // can even cause tests to fail because they're still waiting for the listener
     // to return
-    do_timeout(0, function(){doTest(++gCurTestNum)});
+    do_timeout_function(0, function(){doTest(++gCurTestNum)});
   }
 };