add support for unicode error and status messages, fix non-latin1 folder names at startup, r=jefft 26596

git-svn-id: svn://10.0.0.236/trunk@60209 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bienvenu%netscape.com
2000-02-09 06:48:21 +00:00
parent 182f5c8e73
commit db0bc48cf5
6 changed files with 90 additions and 79 deletions

View File

@@ -188,11 +188,11 @@
## @name IMAP_RECEIVING_MESSAGE_HEADERS_OF
## @loc None
5036=%s Receiving: message headers %lu of %lu
5036=%S Receiving: message headers %lu of %lu
## @name IMAP_RECEIVING_MESSAGE_FLAGS_OF
## @loc None
5037=%s Receiving: message flags %lu of %lu
5037=%S Receiving: message flags %lu of %lu
## @name IMAP_DELETING_MESSAGES
## @loc None

View File

@@ -50,13 +50,11 @@
#include "nsRDFCID.h"
#include "nsINetSupportDialogService.h"
#include "nsEnumeratorUtils.h"
#include "nsICharsetConverterManager.h"
static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID);
static NS_DEFINE_CID(kImapProtocolCID, NS_IMAPPROTOCOL_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
NS_IMPL_ADDREF_INHERITED(nsImapIncomingServer, nsMsgIncomingServer)
NS_IMPL_RELEASE_INHERITED(nsImapIncomingServer, nsMsgIncomingServer)
@@ -1515,46 +1513,6 @@ NS_IMETHODIMP nsImapIncomingServer::RemoveChannelFromUrl(nsIMsgMailNewsUrl *aUrl
NS_IMETHODIMP nsImapIncomingServer::CreatePRUnicharStringFromUTF7(const char * aSourceString, PRUnichar **aUnicodeStr)
{
PRUnichar *convertedString = NULL;
nsresult res;
if (!aUnicodeStr)
return NS_ERROR_NULL_POINTER;
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 utf7 to unicode
nsIUnicodeDecoder* decoder = nsnull;
res = ccm->GetUnicodeDecoder(&aCharset, &decoder);
if(NS_SUCCEEDED(res) && (nsnull != decoder))
{
PRInt32 srcLen = PL_strlen(aSourceString);
res = decoder->GetMaxLength(aSourceString, srcLen, &unicharLength);
// temporary buffer to hold unicode string
unichars = new PRUnichar[unicharLength + 1];
if (unichars == nsnull)
{
res = NS_ERROR_OUT_OF_MEMORY;
}
else
{
res = decoder->Convert(aSourceString, &srcLen, unichars, &unicharLength);
unichars[unicharLength] = 0;
}
NS_IF_RELEASE(decoder);
nsString unicodeStr(unichars);
convertedString = unicodeStr.ToNewUnicode();
delete [] unichars;
}
}
*aUnicodeStr = convertedString;
return (convertedString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return CreateUnicodeStringFromUtf7(aSourceString, aUnicodeStr);
}

View File

@@ -51,6 +51,7 @@
#include "nsImapStringBundle.h"
#include "nsIMsgFolderCacheElement.h"
#include "nsIMsgStatusFeedback.h"
#include "nsTextFormatter.h"
#include "nsIMsgFilter.h"
#include "nsIMsgFilterService.h"
@@ -317,36 +318,47 @@ nsresult nsImapMailFolder::CreateSubFolders(nsFileSpec &path)
rv = NS_NewFileSpecWithSpec(currentFolderPath, getter_AddRefs(curFolder));
currentFolderDBNameStr = currentFolderNameStr;
nsAutoString utf7LeafName = currentFolderNameStr;
if (NS_SUCCEEDED(rv) && curFolder)
{
rv = GetFolderCacheElemFromFileSpec(curFolder, getter_AddRefs(cacheElement));
if (NS_SUCCEEDED(rv) && cacheElement)
{
nsXPIDLCString onlineName;
rv = cacheElement->GetStringProperty("onlineName", getter_Copies(onlineName));
if (NS_SUCCEEDED(rv) && (const char *) onlineName && nsCRT::strlen((const char *) onlineName))
nsXPIDLString unicodeName;
nsXPIDLCString onlineFullUtf7Name;
rv = cacheElement->GetStringProperty("onlineName", getter_Copies(onlineFullUtf7Name));
if (NS_SUCCEEDED(rv) && (const char *) onlineFullUtf7Name && nsCRT::strlen((const char *) onlineFullUtf7Name))
{
if (imapServer)
{
nsXPIDLString nonUtf7Name;
imapServer->CreatePRUnicharStringFromUTF7(onlineName, getter_Copies(nonUtf7Name));
currentFolderNameStr = nonUtf7Name;
}
else
currentFolderNameStr = onlineName;
imapServer->CreatePRUnicharStringFromUTF7(onlineFullUtf7Name, getter_Copies(unicodeName));
// take the full unicode folder name and find the unicode leaf name.
currentFolderNameStr = unicodeName;
PRInt32 leafPos = currentFolderNameStr.RFindChar('/');
if (leafPos > 0)
currentFolderNameStr.Cut(0, leafPos + 1);
// take the utf7 full online name, and determine the utf7 leaf name
utf7LeafName = onlineFullUtf7Name;
leafPos = utf7LeafName.RFindChar('/');
if (leafPos > 0)
utf7LeafName.Cut(0, leafPos + 1);
}
}
}
AddSubfolder(&currentFolderNameStr, getter_AddRefs(child));
// make the imap folder remember the file spec it was created with.
// use the utf7 name as the uri for the folder.
AddSubfolder(&utf7LeafName, getter_AddRefs(child));
if (child)
{
// use the unicode name as the "pretty" name. Set it so it won't be
// automatically computed from the URI, which is in utf7 form.
if (currentFolderNameStr.Length() > 0)
child->SetName(currentFolderNameStr.GetUnicode());
// make the imap folder remember the file spec it was created with.
nsCAutoString leafName (currentFolderDBNameStr);
nsCOMPtr <nsIFileSpec> msfFileSpec;
rv = NS_NewFileSpecWithSpec(currentFolderPath, getter_AddRefs(msfFileSpec));
@@ -3298,16 +3310,11 @@ nsImapMailFolder::ProgressStatus(nsIImapProtocol* aProtocol,
if (extraInfo)
{
// lossy, but what can we do?
nsCAutoString cProgressString(progressMsg);
char *printfString = PR_smprintf(cProgressString, extraInfo);
PRUnichar *printfString = nsTextFormatter::smprintf(progressMsg, extraInfo);
if (printfString)
{
nsString formattedString(printfString);
PR_FREEIF(progressMsg);
progressMsg = nsCRT::strdup(formattedString.GetUnicode());
PR_smprintf_free(printfString);
progressMsg = nsCRT::strdup(printfString);
nsTextFormatter::smprintf_free(printfString);
}
}

View File

@@ -51,7 +51,7 @@
#include "nsIMsgFolder.h"
#include "nsImapStringBundle.h"
#include "nsICopyMsgStreamListener.h"
#include "nsTextFormatter.h"
#include "nsAutoLock.h"
// for the memory cache...
@@ -3943,22 +3943,22 @@ nsImapProtocol::ShowProgress()
if (m_progressString && m_progressStringId)
{
PRUnichar *progressString = NULL;
// lossy if localized string has non-8-bit chars, but we're
// stuck with PR_smprintf for now.
nsCString cProgressString(m_progressString);
const char *mailboxName = GetServerStateParser().GetSelectedMailboxName();
char *printfString = PR_smprintf(cProgressString, (mailboxName) ? mailboxName : "", ++m_progressIndex, m_progressCount);
if (printfString)
{
nsString formattedString(printfString);
PR_FREEIF(printfString);
progressString = nsCRT::strdup(formattedString.GetUnicode());
nsXPIDLString unicodeMailboxName;
}
if (progressString)
PercentProgressUpdateEvent(progressString,(100*(m_progressIndex))/m_progressCount );
PR_FREEIF(progressString);
nsresult rv = CreateUnicodeStringFromUtf7(mailboxName, getter_Copies(unicodeMailboxName));
if (NS_SUCCEEDED(rv))
{
// ### should convert mailboxName to PRUnichar and change %s to %S in msg text
progressString = nsTextFormatter::smprintf(m_progressString, (const PRUnichar *) unicodeMailboxName, ++m_progressIndex, m_progressCount);
if (progressString)
{
PercentProgressUpdateEvent(progressString,(100*(m_progressIndex))/m_progressCount );
nsTextFormatter::smprintf_free(progressString);
}
}
}
}

View File

@@ -501,3 +501,47 @@ CreateUtf7ConvertedStringFromUnicode(const PRUnichar * aSourceString)
return convertedString;
}
nsresult CreateUnicodeStringFromUtf7(const char *aSourceString, PRUnichar **aUnicodeStr)
{
if (!aUnicodeStr)
return NS_ERROR_NULL_POINTER;
PRUnichar *convertedString = NULL;
nsresult res;
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 utf7 to unicode
nsIUnicodeDecoder* decoder = nsnull;
res = ccm->GetUnicodeDecoder(&aCharset, &decoder);
if(NS_SUCCEEDED(res) && (nsnull != decoder))
{
PRInt32 srcLen = PL_strlen(aSourceString);
res = decoder->GetMaxLength(aSourceString, srcLen, &unicharLength);
// temporary buffer to hold unicode string
unichars = new PRUnichar[unicharLength + 1];
if (unichars == nsnull)
{
res = NS_ERROR_OUT_OF_MEMORY;
}
else
{
res = decoder->Convert(aSourceString, &srcLen, unichars, &unicharLength);
unichars[unicharLength] = 0;
}
NS_IF_RELEASE(decoder);
nsString unicodeStr(unichars);
convertedString = unicodeStr.ToNewUnicode();
delete [] unichars;
}
}
*aUnicodeStr = convertedString;
return (convertedString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

View File

@@ -50,6 +50,8 @@ char*
CreateUtf7ConvertedString(const char * aSourceString,
PRBool aConvertToUtf7Imap);
nsresult CreateUnicodeStringFromUtf7(const char *aSourceString, PRUnichar **result);
char *
CreateUtf7ConvertedStringFromUnicode(const PRUnichar *aSourceString);