From 185b1c375e959e005399053bb87466a887a6c4de Mon Sep 17 00:00:00 2001 From: "ducarroz%netscape.com" Date: Mon, 3 May 1999 21:40:44 +0000 Subject: [PATCH] fix for #5855, A=chofmann. delay Creation of mPath to avoid avoid to create a nsFileSpec without knowing the path. Propagate error returned by nsGetMailboxRoot() in nsLocalURI2Path(). --- mailnews/local/src/nsLocalMailFolder.cpp | 22 +++++++++++++++------- mailnews/local/src/nsLocalMailFolder.h | 2 +- mailnews/local/src/nsLocalUtils.cpp | 5 ++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index f532f132934..1e7543c1450 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -53,11 +53,11 @@ static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID); //////////////////////////////////////////////////////////////////////////////// nsMsgLocalMailFolder::nsMsgLocalMailFolder(void) - : nsMsgFolder(), mPath(""), mExpungedBytes(0), + : nsMsgFolder(), mExpungedBytes(0), mHaveReadNameFromDB(PR_FALSE), mGettingMail(PR_FALSE), mInitialized(PR_FALSE), mMailDatabase(nsnull) { - + mPath = nsnull; // NS_INIT_REFCNT(); done by superclass } @@ -66,6 +66,8 @@ nsMsgLocalMailFolder::~nsMsgLocalMailFolder(void) if(mMailDatabase) //Close releases db; mMailDatabase->Close(PR_TRUE); + if (mPath) + delete mPath; } NS_IMPL_ADDREF_INHERITED(nsMsgLocalMailFolder, nsMsgFolder) @@ -830,6 +832,9 @@ nsresult nsMsgLocalMailFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInf { nsresult openErr=NS_ERROR_UNEXPECTED; if(!db || !folderInfo) + return NS_ERROR_NULL_POINTER; //ducarroz: should we use NS_ERROR_INVALID_ARG? + + if (!mPath) return NS_ERROR_NULL_POINTER; nsIMsgDatabase * mailDBFactory = nsnull; @@ -838,7 +843,7 @@ nsresult nsMsgLocalMailFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInf nsresult rv = nsComponentManager::CreateInstance(kCMailDB, nsnull, nsIMsgDatabase::GetIID(), (void **) &mailDBFactory); if (NS_SUCCEEDED(rv) && mailDBFactory) { - openErr = mailDBFactory->Open(mPath, PR_FALSE, (nsIMsgDatabase **) &mailDB, PR_FALSE); + openErr = mailDBFactory->Open(*mPath, PR_FALSE, (nsIMsgDatabase **) &mailDB, PR_FALSE); mailDBFactory->Release(); } @@ -1081,12 +1086,15 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetRememberedPassword(char ** password) NS_IMETHODIMP nsMsgLocalMailFolder::GetPath(nsFileSpec& aPathName) { - nsFileSpec nopath(""); - if (mPath == nopath) { - nsresult rv = nsLocalURI2Path(kMailboxRootURI, mURI, mPath); + if (! mPath) { + mPath = new nsNativeFileSpec(""); + if (! mPath) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = nsLocalURI2Path(kMailboxRootURI, mURI, *mPath); if (NS_FAILED(rv)) return rv; } - aPathName = mPath; + aPathName = *mPath; return NS_OK; } diff --git a/mailnews/local/src/nsLocalMailFolder.h b/mailnews/local/src/nsLocalMailFolder.h index e4a10a47879..210cdccdf28 100644 --- a/mailnews/local/src/nsLocalMailFolder.h +++ b/mailnews/local/src/nsLocalMailFolder.h @@ -139,7 +139,7 @@ protected: protected: - nsNativeFileSpec mPath; + nsNativeFileSpec *mPath; PRUint32 mExpungedBytes; PRBool mHaveReadNameFromDB; PRBool mGettingMail; diff --git a/mailnews/local/src/nsLocalUtils.cpp b/mailnews/local/src/nsLocalUtils.cpp index d91b6ee07b2..3ccfa41a7a9 100644 --- a/mailnews/local/src/nsLocalUtils.cpp +++ b/mailnews/local/src/nsLocalUtils.cpp @@ -65,7 +65,8 @@ nsGetMailboxRoot(const char *hostname, nsFileSpec &result) #endif // if there are no pop servers, how did we get here? - if (! serverSupports) return NS_ERROR_UNEXPECTED; + if (! serverSupports) + return NS_ERROR_UNEXPECTED; nsCOMPtr server = do_QueryInterface(serverSupports); @@ -126,6 +127,8 @@ nsLocalURI2Path(const char* rootURI, const char* uriStr, // begin pathResult with the mailbox root rv = nsGetMailboxRoot(hostname, pathResult); delete[] hostname; + if (NS_FAILED(rv)) + return rv; if (slashPos) { // advance past hostname