Bug 1363281 - add UTF-7 support for IMAP. r=jcranmer
This commit is contained in:
Родитель
ccbd7f65b4
Коммит
a354c87eb0
|
@ -26,6 +26,9 @@
|
||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "nsUnicharUtils.h"
|
#include "nsUnicharUtils.h"
|
||||||
#include "nsIFileStreams.h"
|
#include "nsIFileStreams.h"
|
||||||
|
#include "../../intl/nsMUTF7ToUnicode.h"
|
||||||
|
#include "../../intl/nsUnicodeToMUTF7.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// International functions necessary for composition
|
// International functions necessary for composition
|
||||||
//
|
//
|
||||||
|
@ -79,6 +82,43 @@ nsresult nsMsgI18NConvertToUnicode(const char* aCharset,
|
||||||
outString);
|
outString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult CopyUTF16toMUTF7(const nsString &aSrc, nsACString& aDest)
|
||||||
|
{
|
||||||
|
#define IMAP_UTF7_BUF_LENGTH 100
|
||||||
|
nsUnicodeToMUTF7 converter;
|
||||||
|
static char buffer[IMAP_UTF7_BUF_LENGTH];
|
||||||
|
char16_t *in = (char16_t *)aSrc.get();
|
||||||
|
int32_t inLen = aSrc.Length();
|
||||||
|
int32_t outLen;
|
||||||
|
aDest.Truncate();
|
||||||
|
while (inLen > 0) {
|
||||||
|
outLen = IMAP_UTF7_BUF_LENGTH;
|
||||||
|
int32_t remaining = inLen;
|
||||||
|
converter.ConvertNoBuffNoErr(in, &remaining, buffer, &outLen);
|
||||||
|
aDest.Append(buffer, outLen);
|
||||||
|
in += remaining;
|
||||||
|
inLen -= remaining;
|
||||||
|
}
|
||||||
|
outLen = IMAP_UTF7_BUF_LENGTH;
|
||||||
|
converter.FinishNoBuff(buffer, &outLen);
|
||||||
|
if (outLen > 0)
|
||||||
|
aDest.Append(buffer, outLen);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult CopyMUTF7toUTF16(const nsCString& aSrc, nsAString& aDest)
|
||||||
|
{
|
||||||
|
// UTF-7 encoding size cannot be larger than the size in UTF-16.
|
||||||
|
nsMUTF7ToUnicode converter;
|
||||||
|
int32_t inLen = aSrc.Length();
|
||||||
|
int32_t outLen = inLen;
|
||||||
|
aDest.SetCapacity(outLen);
|
||||||
|
converter.ConvertNoBuff(aSrc.get(), &inLen, aDest.BeginWriting(), &outLen);
|
||||||
|
MOZ_ASSERT(inLen == aSrc.Length(), "UTF-7 should not produce a longer output");
|
||||||
|
aDest.SetLength(outLen);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// Charset used by the file system.
|
// Charset used by the file system.
|
||||||
const char * nsMsgI18NFileSystemCharset()
|
const char * nsMsgI18NFileSystemCharset()
|
||||||
{
|
{
|
||||||
|
|
|
@ -138,16 +138,9 @@ NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString,
|
||||||
const char* charset,
|
const char* charset,
|
||||||
nsACString& outString);
|
nsACString& outString);
|
||||||
|
|
||||||
// inline forwarders to avoid littering with 'x-imap4-.....'
|
// Convert between UTF-16 and modified UTF-7 used for IMAP.
|
||||||
inline nsresult CopyUTF16toMUTF7(const nsString &aSrc, nsACString& aDest)
|
NS_MSG_BASE nsresult CopyUTF16toMUTF7(const nsString &aSrc, nsACString& aDest);
|
||||||
{
|
NS_MSG_BASE nsresult CopyMUTF7toUTF16(const nsCString& aSrc, nsAString& aDest);
|
||||||
return nsMsgI18NConvertFromUnicode("x-imap4-modified-utf7", aSrc, aDest);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline nsresult CopyMUTF7toUTF16(const nsCString& aSrc, nsAString& aDest)
|
|
||||||
{
|
|
||||||
return nsMsgI18NConvertToUnicode("x-imap4-modified-utf7", aSrc, aDest);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline nsresult ConvertToUnicode(const char* charset,
|
inline nsresult ConvertToUnicode(const char* charset,
|
||||||
const nsCString &aSrc, nsAString& aDest)
|
const nsCString &aSrc, nsAString& aDest)
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
// Class nsBasicUTF7Decoder [implementation]
|
// Class nsBasicUTF7Decoder [implementation]
|
||||||
|
|
||||||
nsBasicUTF7Decoder::nsBasicUTF7Decoder(char aLastChar, char aEscChar)
|
nsBasicUTF7Decoder::nsBasicUTF7Decoder(char aLastChar, char aEscChar)
|
||||||
: nsBufferDecoderSupport(1)
|
|
||||||
{
|
{
|
||||||
mLastChar = aLastChar;
|
mLastChar = aLastChar;
|
||||||
mEscChar = aEscChar;
|
mEscChar = aEscChar;
|
||||||
|
@ -216,7 +215,7 @@ NS_IMETHODIMP nsBasicUTF7Decoder::Reset()
|
||||||
mEncoding = ENC_DIRECT;
|
mEncoding = ENC_DIRECT;
|
||||||
mEncBits = 0;
|
mEncBits = 0;
|
||||||
mEncStep = 0;
|
mEncStep = 0;
|
||||||
return nsBufferDecoderSupport::Reset();
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* @created 03/Jun/1999
|
* @created 03/Jun/1999
|
||||||
* @author Catalin Rotaru [CATA]
|
* @author Catalin Rotaru [CATA]
|
||||||
*/
|
*/
|
||||||
class nsBasicUTF7Decoder : public nsBufferDecoderSupport
|
class nsBasicUTF7Decoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ public:
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*/
|
*/
|
||||||
nsBasicUTF7Decoder(char aLastChar, char aEscChar);
|
nsBasicUTF7Decoder(char aLastChar, char aEscChar);
|
||||||
|
NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength,
|
||||||
|
char16_t * aDest, int32_t * aDestLength);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -43,8 +45,6 @@ protected:
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
// Subclassing of nsBufferDecoderSupport class [declaration]
|
// Subclassing of nsBufferDecoderSupport class [declaration]
|
||||||
|
|
||||||
NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength,
|
|
||||||
char16_t * aDest, int32_t * aDestLength);
|
|
||||||
NS_IMETHOD Reset();
|
NS_IMETHOD Reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
// Class nsBasicUTF7Encoder [implementation]
|
// Class nsBasicUTF7Encoder [implementation]
|
||||||
|
|
||||||
nsBasicUTF7Encoder::nsBasicUTF7Encoder(char aLastChar, char aEscChar)
|
nsBasicUTF7Encoder::nsBasicUTF7Encoder(char aLastChar, char aEscChar)
|
||||||
: nsEncoderSupport(5)
|
|
||||||
{
|
{
|
||||||
mLastChar = aLastChar;
|
mLastChar = aLastChar;
|
||||||
mEscChar = aEscChar;
|
mEscChar = aEscChar;
|
||||||
|
@ -262,7 +261,7 @@ NS_IMETHODIMP nsBasicUTF7Encoder::Reset()
|
||||||
mEncoding = ENC_DIRECT;
|
mEncoding = ENC_DIRECT;
|
||||||
mEncBits = 0;
|
mEncBits = 0;
|
||||||
mEncStep = 0;
|
mEncStep = 0;
|
||||||
return nsEncoderSupport::Reset();
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* @created 03/Jun/1999
|
* @created 03/Jun/1999
|
||||||
* @author Catalin Rotaru [CATA]
|
* @author Catalin Rotaru [CATA]
|
||||||
*/
|
*/
|
||||||
class nsBasicUTF7Encoder : public nsEncoderSupport
|
class nsBasicUTF7Encoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ public:
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
*/
|
*/
|
||||||
nsBasicUTF7Encoder(char aLastChar, char aEscChar);
|
nsBasicUTF7Encoder(char aLastChar, char aEscChar);
|
||||||
|
NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength,
|
||||||
|
char * aDest, int32_t * aDestLength);
|
||||||
|
NS_IMETHOD FinishNoBuff(char * aDest, int32_t * aDestLength);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -44,9 +47,6 @@ protected:
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
// Subclassing of nsEncoderSupport class [declaration]
|
// Subclassing of nsEncoderSupport class [declaration]
|
||||||
|
|
||||||
NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength,
|
|
||||||
char * aDest, int32_t * aDestLength);
|
|
||||||
NS_IMETHOD FinishNoBuff(char * aDest, int32_t * aDestLength);
|
|
||||||
NS_IMETHOD Reset();
|
NS_IMETHOD Reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче