Changed the conversion from UTF-8 to UCS2 to use uconv which can handle stream input,

bug 118664, r=ducarroz, sr=sspitzer.
This commit is contained in:
nhotta%netscape.com 2002-02-20 03:04:40 +00:00
parent 5f883a9e95
commit 2d23aab608
4 changed files with 67 additions and 1 deletions

View File

@ -40,6 +40,7 @@ REQUIRES = xpcom \
mime \
pref \
intl \
uconv \
locale \
unicharutil \
content \

View File

@ -33,6 +33,7 @@ REQUIRES = xpcom \
mime \
pref \
intl \
uconv \
locale \
uconv \
unicharutil \

View File

@ -1530,6 +1530,8 @@ NS_IMETHODIMP nsMsgCompose::GetSavedFolderURI(char ** folderURI)
////////////////////////////////////////////////////////////////////////////////////
QuotingOutputStreamListener::~QuotingOutputStreamListener()
{
if (mUnicodeConversionBuffer)
nsMemory::Free(mUnicodeConversionBuffer);
}
QuotingOutputStreamListener::QuotingOutputStreamListener(const char * originalMsgURI,
@ -1543,6 +1545,8 @@ QuotingOutputStreamListener::QuotingOutputStreamListener(const char * originalMs
mQuoteHeaders = quoteHeaders;
mHeadersOnly = headersOnly;
mIdentity = identity;
mUnicodeBufferCharacterLength = 0;
mUnicodeConversionBuffer = nsnull;
if (! mHeadersOnly)
{
@ -2005,7 +2009,63 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnDataAvailable(nsIRequest *request,
rv = NS_OK;
newBuf[numWritten] = '\0';
if (NS_SUCCEEDED(rv) && numWritten > 0)
mMsgBody.Append(NS_ConvertUTF8toUCS2(newBuf, numWritten));
{
// Create unicode decoder.
if (!mUnicodeDecoder)
{
nsCOMPtr<nsICharsetConverterManager2> ccm2 =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr <nsIAtom> charsetAtom = getter_AddRefs(NS_NewAtom("UTF-8"));
if (!charsetAtom)
{
PR_Free(newBuf);
return NS_ERROR_OUT_OF_MEMORY;
}
rv = ccm2->GetUnicodeDecoder(charsetAtom, getter_AddRefs(mUnicodeDecoder));
}
}
if (NS_SUCCEEDED(rv))
{
PRInt32 unicharLength;
PRInt32 inputLength = (PRInt32) numWritten;
rv = mUnicodeDecoder->GetMaxLength(newBuf, numWritten, &unicharLength);
if (NS_SUCCEEDED(rv))
{
// Use this local buffer if possible.
const PRUint32 kLocalBufSize = 4096;
PRUnichar localBuf[kLocalBufSize];
PRUnichar *unichars = localBuf;
if (unicharLength > kLocalBufSize)
{
// Otherwise, use the buffer of the class.
if (!mUnicodeConversionBuffer ||
unicharLength > mUnicodeBufferCharacterLength)
{
if (mUnicodeConversionBuffer)
nsMemory::Free(mUnicodeConversionBuffer);
mUnicodeConversionBuffer = (PRUnichar *) nsMemory::Alloc(unicharLength * sizeof(PRUnichar));
if (!mUnicodeConversionBuffer)
{
mUnicodeBufferCharacterLength = 0;
PR_Free(newBuf);
return NS_ERROR_OUT_OF_MEMORY;
}
mUnicodeBufferCharacterLength = unicharLength;
}
unichars = mUnicodeConversionBuffer;
}
rv = mUnicodeDecoder->Convert(newBuf, &inputLength, unichars, &unicharLength);
if (NS_SUCCEEDED(rv))
mMsgBody.Append(unichars, unicharLength);
}
}
}
PR_FREEIF(newBuf);
return rv;

View File

@ -56,6 +56,7 @@
#include "nsIWebProgressListener.h"
#include "nsIAbDirectory.h"
#include "nsIMimeConverter.h"
#include "nsICharsetConverterManager2.h"
// Forward declares
class QuotingOutputStreamListener;
@ -190,6 +191,9 @@ private:
nsCOMPtr<nsIMsgIdentity> mIdentity;
nsString mCiteReference;
nsCOMPtr<nsIMimeConverter> mMimeConverter;
nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
PRInt32 mUnicodeBufferCharacterLength;
PRUnichar* mUnicodeConversionBuffer;
};
////////////////////////////////////////////////////////////////////////////////////