Bug 445554 - "MsgMailboxGetURI doesn't escape the relative path as should be done for a URL" - only escape for local folders. [r+sr=bienvenu]
--- a/mailnews/base/src/nsMessengerBootstrap.cpp
+++ b/mailnews/base/src/nsMessengerBootstrap.cpp
@@ -335,40 +335,40 @@ NS_IMETHODIMP nsMessengerBootstrap::Open
nsresult
nsMessengerBootstrap::HandleIndexerResult(const nsString &aPath)
{
nsresult rv;
// parse file name - get path to containing folder, and message-id of message we're looking for
// Then, open that message (in a 3-pane window?)
PRInt32 mozmsgsIndex = aPath.Find(NS_LITERAL_STRING(".mozmsgs"));
- nsString folderPath;
- aPath.Left(folderPath, mozmsgsIndex);
- nsCOMPtr<nsILocalFile> msgFolder;
+ nsString folderPathStr;
+ aPath.Left(folderPathStr, mozmsgsIndex);
+ nsCOMPtr<nsILocalFile> folderPath;
#ifdef XP_MACOSX
// We're going to have a native path file url:
// file://<folder path>.mozmsgs/<message-id>.mozeml
// need to convert to 8 bit chars...i.e., a local path.
nsCString nativeArg;
- NS_CopyUnicodeToNative(folderPath, nativeArg);
+ NS_CopyUnicodeToNative(folderPathStr, nativeArg);
// Get the nsILocalFile for this file:// URI.
- rv = MsgGetLocalFileFromURI(nativeArg, getter_AddRefs(msgFolder));
+ rv = MsgGetLocalFileFromURI(nativeArg, getter_AddRefs(folderPath));
NS_ENSURE_SUCCESS(rv, rv);
#endif
#ifdef XP_WIN
// get the nsILocalFile for this path
- msgFolder = do_CreateInstance("@mozilla.org/file/local;1");
- rv = msgFolder->InitWithPath(folderPath);
+ folderPath = do_CreateInstance("@mozilla.org/file/local;1");
+ rv = folderPath->InitWithPath(folderPathStr);
NS_ENSURE_SUCCESS(rv, rv);
#endif
nsCString folderUri;
- rv = MsgMailboxGetURI(msgFolder, folderUri);
+ rv = FolderUriFromDirInProfile(folderPath, folderUri);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString unicodeMessageId;
// strip off .mozeml/.wdseml at the end as well
aPath.Mid(unicodeMessageId, mozmsgsIndex + 9, aPath.Length() - (mozmsgsIndex + 9 + 7));
nsCAutoString escapedMessageId;
NS_CopyUnicodeToNative(unicodeMessageId, escapedMessageId);
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -1420,17 +1420,17 @@ PRBool MsgHostDomainIsTrusted(nsCString
}
}
domain = end + 1;
} while (*end);
return domainIsTrusted;
}
-nsresult MsgMailboxGetURI(nsILocalFile *aLocalPath, nsACString &mailboxUri)
+nsresult FolderUriFromDirInProfile(nsILocalFile *aLocalPath, nsACString &mailboxUri)
{
nsresult rv;
nsCOMPtr<nsIMsgAccountManager> accountManager =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@@ -1463,22 +1463,31 @@ nsresult MsgMailboxGetURI(nsILocalFile *
nsCString serverURI;
rv = server->GetServerURI(serverURI);
if (NS_FAILED(rv)) continue;
PRInt32 sbdIndex;
while((sbdIndex = pathStr.Find(".sbd", PR_TRUE)) != -1)
pathStr.Cut(sbdIndex, 4);
- nsCString escapedPathStr;
- MsgEscapeURL(pathStr, nsINetUtil::ESCAPE_URL_MINIMAL, escapedPathStr);
-
mailboxUri = serverURI;
mailboxUri.Append('/');
- mailboxUri.Append(escapedPathStr);
+
+ // If it's a local folder, escape the folder name
+ nsCAutoString localStoreType;
+ server->GetLocalStoreType(localStoreType);
+ if (localStoreType.Equals(NS_LITERAL_CSTRING("mailbox")))
+ {
+ nsCAutoString escapedPathStr;
+ MsgEscapeURL(pathStr, nsINetUtil::ESCAPE_URL_MINIMAL, escapedPathStr);
+ mailboxUri.Append(escapedPathStr);
+ }
+ else
+ mailboxUri.Append(pathStr);
+
break;
}
}
return mailboxUri.IsEmpty() ? NS_ERROR_FAILURE : NS_OK;
}
nsresult MsgGetLocalFileFromURI(const nsACString &aUTF8Path, nsILocalFile **aFile)
{
--- a/mailnews/base/util/nsMsgUtils.h
+++ b/mailnews/base/util/nsMsgUtils.h
@@ -169,17 +169,17 @@ NS_MSG_BASE nsresult MsgGetFileStream(ns
NS_MSG_BASE nsresult MsgReopenFileStream(nsILocalFile *file, nsIInputStream *fileStream);
// fills in the position of the passed in keyword in the passed in keyword list
// and returns false if the keyword isn't present
NS_MSG_BASE PRBool MsgFindKeyword(const nsCString &keyword, nsCString &keywords, PRInt32 *aStartOfKeyword, PRInt32 *aLength);
NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);
-NS_MSG_BASE nsresult MsgMailboxGetURI(nsILocalFile *aLocalPath, nsACString &mailboxUri);
+NS_MSG_BASE nsresult FolderUriFromDirInProfile(nsILocalFile *aLocalPath, nsACString &mailboxUri);
// gets an nsILocalFile from a UTF-8 file:// path
NS_MSG_BASE nsresult MsgGetLocalFileFromURI(const nsACString &aUTF8Path, nsILocalFile **aFile);
NS_MSG_BASE void MsgStripQuotedPrintable (unsigned char *src);
NS_MSG_BASE void MsgCompressWhitespace(nsCString& aString);
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -187,17 +187,17 @@ NS_IMETHODIMP nsMailboxUrl::GetUri(char
*aURI = ToNewCString(mURI);
else
{
if (m_filePath)
{
nsCAutoString baseUri;
// we blow off errors here so that we can open attachments
// in .eml files.
- (void) MsgMailboxGetURI(m_filePath, baseUri);
+ (void) FolderUriFromDirInProfile(m_filePath, baseUri);
if (baseUri.IsEmpty())
m_baseURL->GetSpec(baseUri);
nsCString baseMessageURI;
nsCreateLocalBaseMessageURI(baseUri, baseMessageURI);
char * uri = nsnull;
nsCAutoString uriStr;
nsBuildLocalMessageURI(baseMessageURI.get(), m_messageKey, uriStr);
uri = ToNewCString(uriStr);