diff --git a/mailnews/base/public/nsIMessenger.idl b/mailnews/base/public/nsIMessenger.idl index 75f89c257c1..1a5f7ee5e1f 100644 --- a/mailnews/base/public/nsIMessenger.idl +++ b/mailnews/base/public/nsIMessenger.idl @@ -80,10 +80,10 @@ interface nsIMessenger : nsISupports { void NewFolder(in nsIRDFCompositeDataSource database, in nsIRDFResource parentFolder, - in string name); + in wstring name); void RenameFolder(in nsIRDFCompositeDataSource db, - in nsIRDFResource folder, in string name); + in nsIRDFResource folder, in wstring name); void CompactFolder(in nsIRDFCompositeDataSource db, in nsIRDFResource folder); void EmptyTrash(in nsIRDFCompositeDataSource db, diff --git a/mailnews/base/public/nsIMsgFolder.idl b/mailnews/base/public/nsIMsgFolder.idl index 834e0b2258c..42b34a2696c 100644 --- a/mailnews/base/public/nsIMsgFolder.idl +++ b/mailnews/base/public/nsIMsgFolder.idl @@ -132,7 +132,7 @@ interface nsIMsgFolder : nsIFolder { * * @param name the new name of the folder */ - void rename(in string name); + void rename(in wstring name); void adopt(in nsIMsgFolder srcFolder, out unsigned long outPos); /** diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 8a16c0633f9..7de6ad081d6 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -848,7 +848,7 @@ nsMessenger::MarkMessagesFlagged(nsIRDFCompositeDataSource *database, NS_IMETHODIMP nsMessenger::NewFolder(nsIRDFCompositeDataSource *database, nsIRDFResource *parentFolderResource, - const char *name) + const PRUnichar *name) { nsresult rv; nsCOMPtr nameArray, folderArray; @@ -884,23 +884,25 @@ nsMessenger::NewFolder(nsIRDFCompositeDataSource *database, nsIRDFResource *pare NS_IMETHODIMP nsMessenger::RenameFolder(nsIRDFCompositeDataSource* db, nsIRDFResource* folderResource, - const char* name) + const PRUnichar* name) { nsresult rv = NS_ERROR_NULL_POINTER; if (!db || !folderResource || !name || !*name) return rv; - nsCOMPtr streamSupport; - rv = NS_NewCharInputStream(getter_AddRefs(streamSupport), name); - if (NS_SUCCEEDED(rv)) - { nsCOMPtr folderArray; nsCOMPtr argsArray; - rv = NS_NewISupportsArray(getter_AddRefs(folderArray)); - if (NS_FAILED(rv)) return rv; - folderArray->AppendElement(folderResource); - rv = NS_NewISupportsArray(getter_AddRefs(argsArray)); - if (NS_FAILED(rv)) return rv; - argsArray->AppendElement(streamSupport); + rv = NS_NewISupportsArray(getter_AddRefs(folderArray)); + if (NS_FAILED(rv)) return rv; + folderArray->AppendElement(folderResource); + rv = NS_NewISupportsArray(getter_AddRefs(argsArray)); + if (NS_FAILED(rv)) return rv; + NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); + if(NS_SUCCEEDED(rv)) + { + nsCOMPtr nameLiteral; + + rdfService->GetLiteral(name, getter_AddRefs(nameLiteral)); + argsArray->AppendElement(nameLiteral); rv = DoCommand(db, NC_RDF_RENAME, folderArray, argsArray); } return rv; diff --git a/mailnews/base/src/nsMsgFolderDataSource.cpp b/mailnews/base/src/nsMsgFolderDataSource.cpp index ba78748d398..5697e311268 100644 --- a/mailnews/base/src/nsMsgFolderDataSource.cpp +++ b/mailnews/base/src/nsMsgFolderDataSource.cpp @@ -678,28 +678,16 @@ nsMsgFolderDataSource::DoCommand(nsISupportsArray/**/* aSources, } else if ((aCommand == kNC_Rename)) { - nsCOMPtr streamSupport = getter_AddRefs(aArguments->ElementAt(0)); - if (streamSupport) - { - nsCOMPtr charInputStream = do_QueryInterface(streamSupport); - if (charInputStream) - { - PRUint32 length = 0; - rv = charInputStream->Available(&length); - if (NS_SUCCEEDED(rv) && length > 0) - { - char *newName = (char*) PR_MALLOC(length+1); - PRUint32 readCount = 0; - rv = charInputStream->Read(newName, length, &readCount); - if(NS_SUCCEEDED(rv) && readCount > 0) - { - newName[readCount] = 0; - rv = folder->Rename(newName); - } - PR_FREEIF(newName); - } - } - } + nsCOMPtr elem = getter_AddRefs(aArguments->ElementAt(0)); + nsCOMPtr literal = do_QueryInterface(elem, &rv); + if(NS_SUCCEEDED(rv)) + { + PRUnichar *name; + literal->GetValue(&name); + + rv = folder->Rename(name); + PR_FREEIF(name); + } } } } diff --git a/mailnews/base/util/nsMsgFolder.cpp b/mailnews/base/util/nsMsgFolder.cpp index c97effb6f42..cf7a0dc94a2 100644 --- a/mailnews/base/util/nsMsgFolder.cpp +++ b/mailnews/base/util/nsMsgFolder.cpp @@ -735,10 +735,13 @@ NS_IMETHODIMP nsMsgFolder::GetName(PRUnichar **name) NS_IMETHODIMP nsMsgFolder::SetName(const PRUnichar * name) { // override the URI-generated name - mName = name; + if (!mName.Equals(name)) + { + mName = name; // old/new value doesn't matter here - NotifyUnicharPropertyChanged(kNameAtom, name, name); + NotifyUnicharPropertyChanged(kNameAtom, name, name); + } return NS_OK; } @@ -1034,7 +1037,7 @@ NS_IMETHODIMP nsMsgFolder::EmptyTrash() return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsMsgFolder::Rename(const char *name) +NS_IMETHODIMP nsMsgFolder::Rename(const PRUnichar *name) { nsresult status = NS_OK; nsAutoString2 unicharString(name); diff --git a/mailnews/base/util/nsMsgFolder.h b/mailnews/base/util/nsMsgFolder.h index 9300b845270..d0d2e99402e 100644 --- a/mailnews/base/util/nsMsgFolder.h +++ b/mailnews/base/util/nsMsgFolder.h @@ -92,7 +92,7 @@ public: NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder **newFolder); NS_IMETHOD Compact(void); NS_IMETHOD EmptyTrash(void); - NS_IMETHOD Rename(const char *name); + NS_IMETHOD Rename(const PRUnichar *name); NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos); NS_IMETHOD ContainsChildNamed(const char *name, PRBool *_retval); NS_IMETHOD IsAncestorOf(nsIMsgFolder *folder, PRBool *_retval); diff --git a/mailnews/imap/public/nsIImapIncomingServer.idl b/mailnews/imap/public/nsIImapIncomingServer.idl index 3de97f14dd2..d0de964ea9c 100644 --- a/mailnews/imap/public/nsIImapIncomingServer.idl +++ b/mailnews/imap/public/nsIImapIncomingServer.idl @@ -61,4 +61,5 @@ interface nsIImapIncomingServer : nsISupports { void ResetNamespaceReferences(); void PseudoInterruptMsgLoad(in nsIImapUrl aImapUrl, out boolean interrupted); void ResetConnection(in string folderName); + void CreatePRUnicharStringFromUTF7(in string aSourceString, out wstring aUnicodeStr); }; diff --git a/mailnews/imap/public/nsIImapService.h b/mailnews/imap/public/nsIImapService.h index 2615c8a74e6..525e30405be 100644 --- a/mailnews/imap/public/nsIImapService.h +++ b/mailnews/imap/public/nsIImapService.h @@ -166,7 +166,7 @@ public: nsIURI** aUrl) = 0; NS_IMETHOD RenameLeaf(nsIEventQueue* aClientEventQ, nsIMsgFolder* srcFolder, - const char* leafName, + const PRUnichar* leafName, nsIUrlListener* urlListener, nsIURI** url) = 0; NS_IMETHOD DeleteFolder(nsIEventQueue* aClientEventQ, diff --git a/mailnews/imap/src/nsImapIncomingServer.cpp b/mailnews/imap/src/nsImapIncomingServer.cpp index 3a1a2207eeb..df9764e1740 100644 --- a/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mailnews/imap/src/nsImapIncomingServer.cpp @@ -1507,7 +1507,7 @@ NS_IMETHODIMP nsImapIncomingServer::RemoveChannelFromUrl(nsIMsgMailNewsUrl *aUrl return rv; } -nsresult nsImapIncomingServer::CreatePRUnicharStringFromUTF7(const char * aSourceString, PRUnichar **aUnicodeStr) +NS_IMETHODIMP nsImapIncomingServer::CreatePRUnicharStringFromUTF7(const char * aSourceString, PRUnichar **aUnicodeStr) { PRUnichar *convertedString = NULL; nsresult res; diff --git a/mailnews/imap/src/nsImapIncomingServer.h b/mailnews/imap/src/nsImapIncomingServer.h index 116265af0c3..3fd9dc2c495 100644 --- a/mailnews/imap/src/nsImapIncomingServer.h +++ b/mailnews/imap/src/nsImapIncomingServer.h @@ -61,8 +61,6 @@ protected: PRBool NoDescendentsAreVerified(nsIFolder *parentFolder); PRBool AllDescendentsAreNoSelect(nsIFolder *parentFolder); - nsresult CreatePRUnicharStringFromUTF7(const char * aSourceString, PRUnichar **aUnicodeStr); - private: nsresult CreateImapConnection (nsIEventQueue* aEventQueue, nsIImapUrl* aImapUrl, diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 6715708500f..b2d4f441529 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -287,6 +287,12 @@ nsresult nsImapMailFolder::CreateSubFolders(nsFileSpec &path) nsAutoString currentFolderNameStr; // online name nsAutoString currentFolderDBNameStr; // possibly munged name nsCOMPtr child; + nsCOMPtr server; + nsCOMPtr imapServer; + + if (NS_SUCCEEDED(GetServer(getter_AddRefs(server))) && server) + imapServer = do_QueryInterface(server); + char *folderName; for (nsDirectoryIterator dir(path, PR_FALSE); dir.Exists(); dir++) { @@ -321,11 +327,19 @@ nsresult nsImapMailFolder::CreateSubFolders(nsFileSpec &path) rv = cacheElement->GetStringProperty("onlineName", getter_Copies(onlineName)); if (NS_SUCCEEDED(rv) && (const char *) onlineName && nsCRT::strlen((const char *) onlineName)) { - currentFolderNameStr = onlineName; + if (imapServer) + { + nsXPIDLString nonUtf7Name; + imapServer->CreatePRUnicharStringFromUTF7(onlineName, getter_Copies(nonUtf7Name)); + currentFolderNameStr = nonUtf7Name; + + } + else + currentFolderNameStr = onlineName; + PRInt32 leafPos = currentFolderNameStr.RFindChar('/'); if (leafPos > 0) currentFolderNameStr.Cut(0, leafPos + 1); - } } } @@ -856,11 +870,12 @@ NS_IMETHODIMP nsImapMailFolder::Delete () return rv; } -NS_IMETHODIMP nsImapMailFolder::Rename (const char *newName) +NS_IMETHODIMP nsImapMailFolder::Rename (const PRUnichar *newName) { nsresult rv = NS_ERROR_FAILURE; - - rv = RenameLocal(newName); + char *utf7Name = CreateUtf7ConvertedStringFromUnicode(newName); + rv = RenameLocal(utf7Name); + nsCRT::free(utf7Name); NS_WITH_SERVICE (nsIImapService, imapService, kCImapService, &rv); if (NS_SUCCEEDED(rv)) diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index b43da78aaad..a3eff26a00e 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -122,7 +122,7 @@ public: NS_IMETHOD Compact(); NS_IMETHOD EmptyTrash(); NS_IMETHOD Delete (); - NS_IMETHOD Rename (const char *newName); + NS_IMETHOD Rename (const PRUnichar *newName); NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos); NS_IMETHOD GetPrettyName(PRUnichar ** prettyName); // Override of the base, for top-level mail folder diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index 440ec536b96..a682161abb8 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -1825,10 +1825,10 @@ void nsImapProtocol::ProcessSelectedStateURL() char *canonicalName = NULL; if (nameStruct) { - const char *mailboxName = GetServerStateParser().GetSelectedMailboxName(); - if (mailboxName ) + const char *selectedMailboxName = GetServerStateParser().GetSelectedMailboxName(); + if (selectedMailboxName ) { - m_runningUrl->AllocateCanonicalPath(mailboxName, + m_runningUrl->AllocateCanonicalPath(selectedMailboxName, kOnlineHierarchySeparatorUnknown, &canonicalName); } } @@ -5105,17 +5105,15 @@ void nsImapProtocol::FolderRenamed(const char *oldName, (m_hierarchyNameState == kListingForInfoAndDiscovery)) { - char *oldName, *newName; + nsXPIDLCString canonicalOldName, canonicalNewName; m_runningUrl->AllocateCanonicalPath(oldName, onlineDelimiter, - &oldName); + getter_Copies(canonicalOldName)); m_runningUrl->AllocateCanonicalPath(newName, onlineDelimiter, - &newName); + getter_Copies(canonicalNewName)); - m_imapServerSink->OnlineFolderRename(oldName, newName); - PR_FREEIF (oldName); - PR_FREEIF(newName); + m_imapServerSink->OnlineFolderRename(canonicalOldName, canonicalNewName); } } diff --git a/mailnews/imap/src/nsImapService.cpp b/mailnews/imap/src/nsImapService.cpp index 17921398644..0aa4f1bfe6d 100644 --- a/mailnews/imap/src/nsImapService.cpp +++ b/mailnews/imap/src/nsImapService.cpp @@ -1553,7 +1553,7 @@ nsImapService::MoveFolder(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, NS_IMETHODIMP nsImapService::RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, - const char* newLeafName, nsIUrlListener* urlListener, + const PRUnichar* newLeafName, nsIUrlListener* urlListener, nsIURI** url) { NS_ASSERTION(eventQueue && srcFolder && newLeafName && *newLeafName, @@ -1581,6 +1581,9 @@ nsImapService::RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, urlSpec.Append((const char *) folderName); urlSpec.Append('>'); urlSpec.Append(hierarchySeparator); + + char *utfNewName = CreateUtf7ConvertedStringFromUnicode( newLeafName); + nsCAutoString cStrFolderName = (const char *) folderName; PRInt32 leafNameStart = cStrFolderName.RFindChar('/'); // ** troublesome hierarchyseparator @@ -1589,7 +1592,11 @@ nsImapService::RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, cStrFolderName.SetLength(leafNameStart+1); urlSpec.Append(cStrFolderName.GetBuffer()); } - urlSpec.Append(newLeafName); + + urlSpec.Append(utfNewName); + + nsCRT::free(utfNewName); + rv = uri->SetSpec((char*) urlSpec.GetBuffer()); if (NS_SUCCEEDED(rv)) { diff --git a/mailnews/imap/src/nsImapService.h b/mailnews/imap/src/nsImapService.h index 903e3659d92..d8028017bd3 100644 --- a/mailnews/imap/src/nsImapService.h +++ b/mailnews/imap/src/nsImapService.h @@ -166,7 +166,7 @@ public: nsIURI** url); NS_IMETHOD RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, - const char* leafName, + const PRUnichar* leafName, nsIUrlListener* urlListener, nsIURI** url); NS_IMETHOD DeleteFolder(nsIEventQueue* eventQueue, diff --git a/mailnews/imap/src/nsImapUtils.cpp b/mailnews/imap/src/nsImapUtils.cpp index e2cfdba6d43..ba4677b7ab4 100644 --- a/mailnews/imap/src/nsImapUtils.cpp +++ b/mailnews/imap/src/nsImapUtils.cpp @@ -467,7 +467,6 @@ CreateUtf7ConvertedStringFromUnicode(const PRUnichar * aSourceString) if(NS_SUCCEEDED(res) && (nsnull != ccm)) { nsString aCharset("x-imap4-modified-utf7"); - PRUnichar *unichars = nsnull; PRInt32 unicharLength; // convert from 8 bit ascii string to modified utf7