Changed to escape folder name to prevent 8 bit data from bad conversions,

also changed to apply correct conversions (UTF-8 for RDF, OS native charset for file name), bug 52165, r=putterman, a=alecf.
This commit is contained in:
nhotta%netscape.com 2000-09-22 23:58:19 +00:00
parent b44ba3bf53
commit 2bcfce77e9
4 changed files with 34 additions and 13 deletions

View File

@ -36,6 +36,7 @@
#include "nsMsgLocalCID.h"
#include "nsMsgBaseCID.h"
#include "nsMsgImapCID.h"
#include "nsMsgI18N.h"
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
static NS_DEFINE_CID(kCMailboxUrl, NS_MAILBOXURL_CID);
@ -336,7 +337,17 @@ nsresult NS_MsgHashIfNecessary(nsCAutoString &name)
nsresult NS_MsgCreatePathStringFromFolderURI(const char *folderURI, nsCString& pathString)
{
nsCAutoString oldPath(folderURI);
// A file name has to be in native charset, convert from UTF-8.
nsCAutoString oldPath;
const nsString fileCharset(nsMsgI18NFileSystemCharset());
char *nativeString;
nsresult rv = ConvertFromUnicode(fileCharset, nsAutoString(NS_ConvertUTF8toUCS2(folderURI)), &nativeString);
if (NS_SUCCEEDED(rv))
oldPath.Assign(nativeString);
else
oldPath.Assign(folderURI);
PR_FREEIF(nativeString);
nsCAutoString pathPiece;
PRInt32 startSlashPos = oldPath.FindChar('/');

View File

@ -509,18 +509,15 @@ NS_IMETHODIMP nsMsgLocalMailFolder::AddSubfolder(nsAutoString *name,
nsCAutoString uri(mURI);
uri.Append('/');
// Convert from Unicode to filesystem charactorset
// XXX URI should use UTF-8?
// URI should use UTF-8
// (see RFC2396 Uniform Resource Identifiers (URI): Generic Syntax)
const nsString fileCharset(nsMsgI18NFileSystemCharset());
char *convertedName;
rv = ConvertFromUnicode(fileCharset, *name, &convertedName);
if (NS_FAILED(rv))
return rv;
uri.Append(convertedName);
PR_Free((void*) convertedName);
char *escapedName = nsEscape(NS_ConvertUCS2toUTF8(name->GetUnicode()), url_Path);
if (escapedName)
{
uri.Append(escapedName);
PR_FREEIF(escapedName);
}
nsCOMPtr<nsIRDFResource> res;
rv = rdf->GetResource(uri.GetBuffer(), getter_AddRefs(res));

View File

@ -308,8 +308,17 @@ nsresult nsMailboxService::PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsI
nsFileSpec folderPath;
nsMsgKey msgKey;
const char *part = PL_strstr(aSrcMsgMailboxURI, "part=");
rv = nsParseLocalMessageURI(aSrcMsgMailboxURI, folderURI, &msgKey);
// Unescape folder name
char *unescapedFolderURI = nsCRT::strdup(folderURI);
if (unescapedFolderURI)
{
nsUnescape(unescapedFolderURI);
folderURI.Assign(unescapedFolderURI);
PR_Free(unescapedFolderURI);
}
rv = nsLocalURI2Path(kMailboxMessageRootURI, folderURI, folderPath);
if (NS_SUCCEEDED(rv))

View File

@ -49,6 +49,7 @@
#include "nsRDFCID.h"
#include "nsIPref.h"
#include "nsIRDFService.h"
#include "nsMsgI18N.h"
static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID);
@ -103,7 +104,10 @@ NS_IMETHODIMP nsMsgMailboxParser::OnStartRequest(nsIChannel * /* aChannel */, ns
nsXPIDLCString tempfolder;
rv = ioServ->Unescape(folderName, getter_Copies(tempfolder));
m_folderName.Assign(NS_ConvertUTF8toUCS2(tempfolder));
// convert from OS native charset to unicode
rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), tempfolder, m_folderName);
if (NS_FAILED(rv))
m_folderName.AssignWithConversion(tempfolder);
if (fileName)
{