allow creation of folders with double-byte characters r=putterman, 26745

This commit is contained in:
bienvenu%netscape.com 2000-02-07 00:20:37 +00:00
Родитель ea5f04c164
Коммит d7e992b034
16 изменённых файлов: 76 добавлений и 27 удалений

Просмотреть файл

@ -121,7 +121,7 @@ interface nsIMsgFolder : nsIFolder {
void propagateDelete(in nsIMsgFolder folder, in boolean deleteStorage);
void recursiveDelete(in boolean deleteStorage);
void createSubfolder(in string folderName);
void createSubfolder(in wstring folderName);
[noscript] nsIMsgFolder addSubfolder(in nsAutoString folderName);
void compact();

Просмотреть файл

@ -1522,11 +1522,8 @@ nsresult nsMsgFolderDataSource::DoNewFolder(nsIMsgFolder *folder, nsISupportsArr
{
PRUnichar *name;
literal->GetValue(&name);
nsAutoString tempStr(name);
nsCAutoString nameStr(tempStr);
rv = folder->CreateSubfolder(nameStr);
nsAllocator::Free(name);
rv = folder->CreateSubfolder(name);
}
return rv;
}

Просмотреть файл

@ -1013,7 +1013,7 @@ NS_IMETHODIMP nsMsgFolder::RecursiveDelete(PRBool deleteStorage)
return status;
}
NS_IMETHODIMP nsMsgFolder::CreateSubfolder(const char *folderName)
NS_IMETHODIMP nsMsgFolder::CreateSubfolder(const PRUnichar *folderName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -88,7 +88,7 @@ public:
NS_IMETHOD DeleteSubFolders(nsISupportsArray *folders);
NS_IMETHOD PropagateDelete(nsIMsgFolder *folder, PRBool deleteStorage);
NS_IMETHOD RecursiveDelete(PRBool deleteStorage);
NS_IMETHOD CreateSubfolder(const char *folderName);
NS_IMETHOD CreateSubfolder(const PRUnichar *folderName);
NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder **newFolder);
NS_IMETHOD Compact(void);
NS_IMETHOD EmptyTrash(void);

Просмотреть файл

@ -175,7 +175,7 @@ public:
nsIURI** url) = 0;
NS_IMETHOD CreateFolder(nsIEventQueue* eventQueue,
nsIMsgFolder* parent,
const char* leafName,
const PRUnichar* leafName,
nsIUrlListener* urlListener,
nsIURI** url) = 0;

Просмотреть файл

@ -508,7 +508,7 @@ NS_IMETHODIMP nsImapMailFolder::GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleE
return rv;
}
NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const char* folderName)
NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const PRUnichar* folderName)
{
nsresult rv = NS_ERROR_NULL_POINTER;
if (!folderName) return rv;

Просмотреть файл

@ -115,7 +115,7 @@ public:
NS_IMETHOD GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *result);
NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow);
NS_IMETHOD CreateSubfolder(const char *folderName);
NS_IMETHOD CreateSubfolder(const PRUnichar *folderName);
NS_IMETHOD AddSubfolder(nsAutoString *name, nsIMsgFolder **child);
NS_IMETHOD ForceDBClosed();

Просмотреть файл

@ -1600,7 +1600,7 @@ nsImapService::RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder,
NS_IMETHODIMP
nsImapService::CreateFolder(nsIEventQueue* eventQueue, nsIMsgFolder* parent,
const char* newFolderName,
const PRUnichar* newFolderName,
nsIUrlListener* urlListener, nsIURI** url)
{
NS_ASSERTION(eventQueue && parent && newFolderName && *newFolderName,
@ -1630,7 +1630,7 @@ nsImapService::CreateFolder(nsIEventQueue* eventQueue, nsIMsgFolder* parent,
urlSpec.Append((const char *) folderName);
urlSpec.Append(hierarchySeparator);
}
char *utfNewName = CreateUtf7ConvertedString( newFolderName, PR_TRUE);
char *utfNewName = CreateUtf7ConvertedStringFromUnicode( newFolderName);
char *escapedFolderName = nsEscape(utfNewName, url_Path);
urlSpec.Append(escapedFolderName);
nsCRT::free(escapedFolderName);

Просмотреть файл

@ -175,7 +175,7 @@ public:
nsIURI** url);
NS_IMETHOD CreateFolder(nsIEventQueue* eventQueue,
nsIMsgFolder* parent,
const char* leafName,
const PRUnichar* leafName,
nsIUrlListener* urlListener,
nsIURI** url);

Просмотреть файл

@ -453,3 +453,52 @@ CreateUtf7ConvertedString(const char * aSourceString,
return convertedString;
}
// convert back and forth between imap utf7 and unicode.
char*
CreateUtf7ConvertedStringFromUnicode(const PRUnichar * aSourceString)
{
nsresult res;
char *dstPtr = nsnull;
PRInt32 dstLength = 0;
char *convertedString = NULL;
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res);
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
nsString unicodeStr(aSourceString);
nsIUnicodeEncoder* encoder = nsnull;
aCharset.SetString("x-imap4-modified-utf7");
res = ccm->GetUnicodeEncoder(&aCharset, &encoder);
if(NS_SUCCEEDED(res) && (nsnull != encoder))
{
res = encoder->GetMaxLength(unicodeStr.GetUnicode(), unicodeStr.Length(), &dstLength);
// allocale an output buffer
dstPtr = (char *) PR_CALLOC(dstLength + 1);
unicharLength = unicodeStr.Length();
if (dstPtr == nsnull)
{
res = NS_ERROR_OUT_OF_MEMORY;
}
else
{
res = encoder->Convert(unicodeStr.GetUnicode(), &unicharLength, dstPtr, &dstLength);
dstPtr[dstLength] = 0;
}
}
// ack, this is silly - why pass through unicodeStr2 back to convertedString?
NS_IF_RELEASE(encoder);
nsString unicodeStr2(dstPtr);
convertedString = (char *) PR_Malloc(dstLength + 1);
if (convertedString)
unicodeStr2.ToCString(convertedString, dstLength + 1, 0);
}
PR_FREEIF(dstPtr);
return convertedString;
}

Просмотреть файл

@ -50,4 +50,7 @@ char*
CreateUtf7ConvertedString(const char * aSourceString,
PRBool aConvertToUtf7Imap);
char *
CreateUtf7ConvertedStringFromUnicode(const PRUnichar *aSourceString);
#endif //NS_IMAPUTILS_H

Просмотреть файл

@ -409,7 +409,8 @@ void nsImportGenericMail::GetDefaultDestination( void)
rootFolder->GenerateUniqueSubfolderName( "Imported Mail", nsnull, &pName);
if (pName) {
IMPORT_LOG1( "* Creating folder for importing mail: %s\n", pName);
rootFolder->CreateSubfolder( pName);
nsAutoString childName(pName);
rootFolder->CreateSubfolder( childName.GetUnicode());
nsCOMPtr<nsISupports> subFolder;
rootFolder->GetChildNamed( pName, getter_AddRefs( subFolder));
if (subFolder) {
@ -884,8 +885,9 @@ ImportMailThread( void *stuff)
lastName = pStr;
IMPORT_LOG1( "* Creating new import folder: %s\n", pStr);
rv = curProxy->CreateSubfolder( pStr);
nsAutoString newName(pStr);
rv = curProxy->CreateSubfolder( newName.GetUnicode());
IMPORT_LOG1( "New folder created, rv: 0x%lx\n", (long) rv);
if (NS_SUCCEEDED( rv)) {

Просмотреть файл

@ -602,7 +602,7 @@ nsresult nsMsgLocalMailFolder::CreateDirectoryForFolder(nsFileSpec &path)
}
nsresult
nsMsgLocalMailFolder::CreateSubfolder(const char *folderName)
nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName)
{
nsresult rv = NS_OK;
@ -692,11 +692,9 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EmptyTrash()
if (NS_SUCCEEDED(rv))
{
nsString folderName(idlFolderName);
char *cStringName = folderName.ToNewCString();
trashFolder->SetParent(nsnull);
parentFolder->PropagateDelete(trashFolder, PR_TRUE);
parentFolder->CreateSubfolder(cStringName);
nsCRT::free(cStringName);
parentFolder->CreateSubfolder(folderName.GetUnicode());
}
}
}

Просмотреть файл

@ -95,7 +95,7 @@ public:
NS_IMETHOD GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *result);
NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow);
NS_IMETHOD CreateSubfolder(const char *folderName);
NS_IMETHOD CreateSubfolder(const PRUnichar *folderName);
NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder** newFolder);
NS_IMETHOD Compact();

Просмотреть файл

@ -473,13 +473,13 @@ NS_IMETHODIMP nsMsgNewsFolder::GetFolderURL(char **url)
}
NS_IMETHODIMP nsMsgNewsFolder::CreateSubfolder(const char *newsgroupname)
NS_IMETHODIMP nsMsgNewsFolder::CreateSubfolder(const PRUnichar *uninewsgroupname)
{
nsresult rv = NS_OK;
if (!newsgroupname) return NS_ERROR_NULL_POINTER;
if (PL_strlen(newsgroupname) == 0) return NS_ERROR_FAILURE;
if (!uninewsgroupname) return NS_ERROR_NULL_POINTER;
if (nsCRT::strlen(uninewsgroupname) == 0) return NS_ERROR_FAILURE;
nsCAutoString newsgroupname(uninewsgroupname);
nsFileSpec path;
nsCOMPtr<nsIFileSpec> pathSpec;
rv = GetPath(getter_AddRefs(pathSpec));
@ -496,7 +496,7 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateSubfolder(const char *newsgroupname)
//Now we have a valid directory or we have returned.
//Make sure the new folder name is valid
// do we need to hash newsgroup name if it is too big?
path += newsgroupname;
path += (const char *) newsgroupname;
rv = AddNewsgroupToNewsrcFile(newsgroupname);
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -62,7 +62,7 @@ public:
NS_IMETHOD GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *result);
NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow);
NS_IMETHOD CreateSubfolder(const char *folderName);
NS_IMETHOD CreateSubfolder(const PRUnichar *folderName);
NS_IMETHOD Delete ();
NS_IMETHOD Rename (const char *newName);