Bug 456440 - "IMAP folder paths not initialized correctly if done for the first time inside nsImapMailFolder::GetFilePath" [r+sr=bienvenu]
authorSiddharth Agarwal <sid1337@gmail.com>
Tue, 23 Sep 2008 09:00:25 +0100
changeset 399 73cc90a6e8d682370a140b8f8c4cd60ebd50882a
parent 398 5a1b4384c192edadb566de475bb9f8633d9c1f15
child 400 3a2b64bc09bcae1ee47a7feda1edaed73f53807d
push idunknown
push userunknown
push dateunknown
bugs456440
Bug 456440 - "IMAP folder paths not initialized correctly if done for the first time inside nsImapMailFolder::GetFilePath" [r+sr=bienvenu]
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapUtils.cpp
mailnews/imap/src/nsImapUtils.h
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -5757,23 +5757,18 @@ nsresult nsMsgIMAPFolderACL::CreateACLRi
       aRightsString.Append(curRight);
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsImapMailFolder::GetFilePath(nsILocalFile ** aPathName)
 {
-  nsresult rv;
-  if (!mPath)
-  {
-    rv = nsImapURI2Path(kImapRootURI, mURI.get(), getter_AddRefs(mPath));
-    if (NS_FAILED(rv)) return rv;
-  }
   // this will return a copy of mPath, which is what we want.
+  // this will also initialize mPath using parseURI if it isn't already done
   return nsMsgDBFolder::GetFilePath(aPathName);
 }
 
 NS_IMETHODIMP nsImapMailFolder::SetFilePath(nsILocalFile * aPathName)
 {
   return nsMsgDBFolder::SetFilePath(aPathName);   // call base class so mPath will get set
 }
 
--- a/mailnews/imap/src/nsImapUtils.cpp
+++ b/mailnews/imap/src/nsImapUtils.cpp
@@ -54,98 +54,16 @@
 #include "nsImapCore.h"
 #include "nsMsgUtils.h"
 #include "nsImapFlagAndUidState.h"
 #include "nsISupportsObsolete.h"
 #include "nsIMAPNamespace.h"
 #include "nsIImapFlagAndUidState.h"
 
 nsresult
-nsImapURI2Path(const char* rootURI, const char* uriStr, nsILocalFile **pathResult)
-{
-  nsresult rv;
-  
-  nsCOMPtr<nsIURL> url;
- 
-  url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) return rv;
-  
-  nsCAutoString uri(uriStr);
-  if (uri.Find(rootURI) != 0)     // if doesn't start with rootURI
-    return NS_ERROR_FAILURE;
-  
-  if ((PL_strcmp(rootURI, kImapRootURI) != 0) &&
-      (PL_strcmp(rootURI, kImapMessageRootURI) != 0)) 
-  {
-    *pathResult = nsnull;
-    rv = NS_ERROR_FAILURE; 
-  }
-  
-  // Set our url to the string given
-  rv = url->SetSpec(nsDependentCString(uriStr));
-  if (NS_FAILED(rv)) return rv;
-
-  // Set the folder to the url path
-  nsCAutoString folder;
-  rv = url->GetPath(folder);
-  // can't have leading '/' in path
-  if (folder.CharAt(0) == '/')
-    folder.Cut(0, 1);
-
-  const char *curPos = uriStr + PL_strlen(rootURI);
-  nsCAutoString newPath("");
-  if (curPos) 
-  {
-    // advance past hostname
-    while (*curPos && (*curPos)!='/') 
-      curPos++;
-
-    char *unescaped = NS_strdup(curPos);  
-    if (unescaped) 
-    {
-      nsUnescape(unescaped);
-      NS_MsgCreatePathStringFromFolderURI(unescaped, newPath);
-      NS_Free(unescaped);
-    }
-    else
-      NS_MsgCreatePathStringFromFolderURI(curPos, newPath);
-  }
-  // Now find the server from the URL
-  nsCOMPtr<nsIMsgIncomingServer> server;
-  nsCOMPtr<nsIMsgAccountManager> accountManager = 
-    do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
-  if(NS_FAILED(rv)) return rv;
-  
-  rv = accountManager->FindServerByURI(url, PR_FALSE,
-    getter_AddRefs(server));
-
-  if (NS_FAILED(rv)) return rv;
-  
-  nsCOMPtr<nsILocalFile> localPath;
-  if (server) 
-  {
-    rv = server->GetLocalPath(getter_AddRefs(localPath));
-    NS_ENSURE_SUCCESS(rv, rv);
-    
-    // This forces the creation of the parent server directory
-    // so that we don't get imapservername.sbd instead
-    // when the host directory has been deleted. See bug 210683
-    localPath->Create(nsIFile::DIRECTORY_TYPE, 0700);
-  }
-  if (NS_FAILED(rv)) 
-  {
-    pathResult = nsnull;
-    return rv;
-  }
-  localPath->AppendRelativeNativePath(newPath);
-  NS_IF_ADDREF(*pathResult = localPath);
-  return NS_OK;
-}
-
-nsresult
 nsImapURI2FullName(const char* rootURI, const char* hostName, const char* uriStr,
                    char **name)
 {
     nsAutoString uri;
     CopyASCIItoUTF16(uriStr, uri);
     nsAutoString fullName;
     if (uri.Find(rootURI) != 0)
       return NS_ERROR_FAILURE;
--- a/mailnews/imap/src/nsImapUtils.h
+++ b/mailnews/imap/src/nsImapUtils.h
@@ -48,21 +48,16 @@ class nsImapFlagAndUidState;
 class nsImapProtocol;
 
 static const char kImapRootURI[] = "imap:/";
 static const char kImapMessageRootURI[] = "imap-message:/";
 static const char kModSeqPropertyName[] = "highestModSeq";
 static const char kHighestRecordedUIDPropertyName[] = "highestRecordedUID";
 static const char kDeletedHdrCountPropertyName[] = "numDeletedHeaders";
 
-
-extern nsresult
-nsImapURI2Path(const char* rootURI, const char* uriStr, 
-               nsILocalFile **pathResult);
-
 extern nsresult
 nsImapURI2FullName(const char* rootURI, const char* hostname, const char* uriStr,
                    char **name);
 
 extern nsresult
 nsParseImapMessageURI(const char* uri, nsCString& folderURI, PRUint32 *key, char **part);
 
 extern nsresult