63300. r=racham, sr=bienvenu. Making IMAP folders case-sensitive and local folders

case-insensitive as done in 4x.


git-svn-id: svn://10.0.0.236/trunk@86363 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
naving%netscape.com 2001-02-06 23:17:26 +00:00
parent ff29d5d766
commit d02f094038
7 changed files with 90 additions and 40 deletions

View File

@ -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)
{

View File

@ -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.

View File

@ -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<nsIDocShell> docShell;
msgWindow->GetRootDocShell(getter_AddRefs(docShell));
PRUnichar *alertString = IMAPGetStringByID(IMAP_MAILBOX_ALREADY_EXISTS);
if (!alertString) return rv;
if (docShell)
{
nsCOMPtr<nsIPrompt> 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;

View File

@ -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

View File

@ -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__ */

View File

@ -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<nsIMsgFolder> 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 <nsIFileSpec> 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;

View File

@ -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