diff --git a/mozilla/mailnews/base/util/nsMsgFolder.cpp b/mozilla/mailnews/base/util/nsMsgFolder.cpp index 546760153a7..e138956e900 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgFolder.cpp @@ -930,9 +930,7 @@ NS_IMETHODIMP nsMsgFolder::GetChildWithURI(const char *uri, PRBool deep, nsIMsgF rv = folderResource->GetValue(&folderURI); if(NS_FAILED(rv)) return rv; - // case-insensitive compare is probably LCD across OS filesystems - - PRBool equal = (folderURI && nsCRT::strcasecmp(folderURI, uri)==0); + PRBool equal = (folderURI && nsCRT::strcmp(folderURI, uri)==0); nsMemory::Free(folderURI); if (equal) { diff --git a/mozilla/mailnews/imap/resources/locale/en-US/imapMsgs.properties b/mozilla/mailnews/imap/resources/locale/en-US/imapMsgs.properties index 0a627a36626..760d0a8e587 100644 --- a/mozilla/mailnews/imap/resources/locale/en-US/imapMsgs.properties +++ b/mozilla/mailnews/imap/resources/locale/en-US/imapMsgs.properties @@ -331,3 +331,6 @@ ## @loc None 5058=Deleting this folder is not undoable and will delete all of the messages it contains. Are you sure you still want to delete this folder? +## @name IMAP_MAILBOX_ALREADY_EXISTS +## @loc None +5061=The mailbox already exists. \ No newline at end of file diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index 39434672d5b..02db955069c 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -636,6 +636,18 @@ NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const PRUnichar* folderName, nsI { nsresult rv = NS_ERROR_NULL_POINTER; if (!folderName) return rv; + + if ( nsCRT::strcasecmp(folderName,"Trash") == 0 ) // Trash , a special folder + { + AlertSpecialFolderExists(msgWindow); + return NS_MSG_FOLDER_EXISTS; + } + else if ( nsCRT::strcasecmp(folderName,"Inbox") == 0 ) // Inbox, a special folder + { + AlertSpecialFolderExists(msgWindow); + return NS_MSG_FOLDER_EXISTS; + } + NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv); if (NS_SUCCEEDED(rv)) rv = imapService->CreateFolder(m_eventQueue, this, @@ -643,6 +655,26 @@ NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const PRUnichar* folderName, nsI return rv; } +nsresult +nsImapMailFolder::AlertSpecialFolderExists(nsIMsgWindow *msgWindow) +{ + nsresult rv = NS_OK; + nsCOMPtr docShell; + msgWindow->GetRootDocShell(getter_AddRefs(docShell)); + PRUnichar *alertString = IMAPGetStringByID(IMAP_MAILBOX_ALREADY_EXISTS); + if (!alertString) return rv; + if (docShell) + { + nsCOMPtr dialog(do_GetInterface(docShell)); + if (dialog) + { + rv = dialog->Alert(nsnull, alertString); + return rv; + } + } + return rv; +} + NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName, PRUnichar hierarchyDelimiter, PRInt32 flags) { nsresult rv = NS_OK; diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.h b/mozilla/mailnews/imap/src/nsImapMailFolder.h index ae8f043c1b3..5a3b809c667 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.h +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.h @@ -273,6 +273,9 @@ public: static nsresult AllocateUidStringFromKeyArray(nsMsgKeyArray &keyArray, nsCString &msgIds); protected: // Helper methods + + nsresult AlertSpecialFolderExists(nsIMsgWindow *msgWindow); + void FindKeysToAdd(const nsMsgKeyArray &existingKeys, nsMsgKeyArray &keysToFetch, nsIImapFlagAndUidState *flagState); void FindKeysToDelete(const nsMsgKeyArray &existingKeys, nsMsgKeyArray diff --git a/mozilla/mailnews/imap/src/nsImapStringBundle.h b/mozilla/mailnews/imap/src/nsImapStringBundle.h index 5bbf16b7480..dd16bde28ce 100644 --- a/mozilla/mailnews/imap/src/nsImapStringBundle.h +++ b/mozilla/mailnews/imap/src/nsImapStringBundle.h @@ -92,4 +92,5 @@ NS_END_EXTERN_C #define IMAP_DELETE_NO_TRASH 5058 #define IMAP_HTML_NO_CACHED_BODY_TITLE 5059 #define IMAP_HTML_NO_CACHED_BODY_BODY 5060 +#define IMAP_MAILBOX_ALREADY_EXISTS 5061 #endif /* _nsImapStringBundle_H__ */ diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp index 57b5b5c745c..84de89016df 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp @@ -751,12 +751,33 @@ nsMsgLocalMailFolder::AlertFolderExists(nsIMsgWindow *msgWindow) return rv; } +nsresult +nsMsgLocalMailFolder::CheckIfFolderExists(const PRUnichar *folderName, nsFileSpec &path, nsIMsgWindow *msgWindow) +{ + nsresult rv = NS_OK; + char *leafName=nsnull; + for (nsDirectoryIterator dir(path, PR_FALSE); dir.Exists(); dir++) + { + nsFileSpec currentFolderPath = dir.Spec(); + leafName = currentFolderPath.GetLeafName(); + if (leafName && nsCRT::strcasecmp(folderName,leafName) == 0) + { + if (msgWindow) + AlertFolderExists(msgWindow); + PL_strfree(leafName); + return NS_MSG_FOLDER_EXISTS; + } + } + if (leafName) + PL_strfree(leafName); + return rv; +} + nsresult nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow *msgWindow ) { nsresult rv = NS_OK; - PRBool exists = PR_FALSE; - + nsFileSpec path; nsCOMPtr child; //Get a directory based on our current path. @@ -766,14 +787,11 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow //Now we have a valid directory or we have returned. //Make sure the new folder name is valid + rv = CheckIfFolderExists(folderName, path, msgWindow); + if(NS_FAILED(rv)) + return rv; + path += nsAutoString(folderName); - exists=path.Exists(); - if (exists){ - if (msgWindow) - AlertFolderExists(msgWindow); - return NS_MSG_FOLDER_EXISTS; - } - nsOutputFileStream outputStream(path, PR_WRONLY | PR_CREATE_FILE, 00600); @@ -1118,28 +1136,31 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Rename(const PRUnichar *aNewName, nsIMsgWind return NS_ERROR_FAILURE; nsCAutoString newNameStr(convertedNewName); - PRBool sameName = PR_FALSE; - PRBool exists = PR_FALSE; - nsXPIDLCString oldLeafName; + nsXPIDLCString oldLeafName; oldPathSpec->GetLeafName(getter_Copies(oldLeafName)); - if (strcmp(oldLeafName.get(), convertedNewName) == 0) { - sameName = PR_TRUE; + if (PL_strcasecmp(oldLeafName.get(), convertedNewName) == 0) { + if(msgWindow) + rv=AlertFolderExists(msgWindow); + return NS_MSG_FOLDER_EXISTS; } else - { - oldPathSpec->SetLeafName(convertedNewName); - oldPathSpec->Exists(&exists); - //Set it back to oldLeafName so that actual renaming on disk can be done.... - oldPathSpec->SetLeafName(oldLeafName); + { + nsCOMPtr parentPathSpec; + parentFolder->GetPath(getter_AddRefs(parentPathSpec)); + NS_ENSURE_SUCCESS(rv,rv); - } + nsFileSpec parentPath; + parentPathSpec->GetFileSpec(&parentPath); + NS_ENSURE_SUCCESS(rv,rv); + + if (!parentPath.IsDirectory()) + AddDirectorySeparator(parentPath); - if ( exists || sameName ){ - if(msgWindow) - rv=AlertFolderExists(msgWindow); - return NS_MSG_FOLDER_EXISTS; - } + rv = CheckIfFolderExists(aNewName, parentPath, msgWindow); + if (NS_FAILED(rv)) return rv; + + } NotifyStoreClosedAllHeaders(); ForceDBClosed(); @@ -1831,18 +1852,8 @@ nsMsgLocalMailFolder::CopyFolderLocal( nsIMsgFolder *destFolder, nsIMsgFolder *s newPath.CreateDirectory(); } - PRBool exists = PR_FALSE; - nsFileSpec checkPath = newPath; - - checkPath += folderName; - exists=checkPath.Exists(); - - if (exists) - { - if (msgWindow) - AlertFolderExists(msgWindow); - return NS_MSG_FOLDER_EXISTS; - } + rv = CheckIfFolderExists(idlName.get(), newPath, msgWindow); + if(NS_FAILED(rv)) return rv; nsFileSpec path = oldPath; diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.h b/mozilla/mailnews/local/src/nsLocalMailFolder.h index 2bc4dce1910..a225eba2d47 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.h +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.h @@ -163,6 +163,8 @@ protected: nsresult RecursiveSetDeleteIsMoveTrash(PRBool bVal); nsresult AlertFolderExists(nsIMsgWindow *msgWindow); + nsresult CheckIfFolderExists(const PRUnichar *folderName, nsFileSpec &path, nsIMsgWindow *msgWindow); + /* Finds the directory associated with this folder. That is if the path is c:\Inbox, it will return c:\Inbox.sbd if it succeeds. If that path doesn't currently exist then it will create it