Bug 201071 signature file containing accented characters has become corrupted / Bug 153855 Composer does not display a UTF-8 signature in the right way. r=jshin, sr=bienvenu

This commit is contained in:
masayuki%d-toybox.com 2006-04-10 15:27:29 +00:00
parent a9c327f9c9
commit 7fcaf1d989
5 changed files with 40 additions and 6 deletions

View File

@ -62,7 +62,8 @@ typedef enum {
kPlatformCharsetSel_4xBookmarkFile = 3,
kPlatformCharsetSel_KeyboardInput = 4,
kPlatformCharsetSel_WindowManager = 5,
kPlatformCharsetSel_4xPrefsJS = 6
kPlatformCharsetSel_4xPrefsJS = 6,
kPlatformCharsetSel_PlainTextInFile = 7
} nsPlatformCharsetSel;
class nsIPlatformCharset : public nsISupports

View File

@ -216,6 +216,21 @@ const char * nsMsgI18NFileSystemCharset()
return fileSystemCharset.get();
}
// Charset used by the text file.
void nsMsgI18NTextFileCharset(nsACString& aCharset)
{
nsresult rv;
nsCOMPtr <nsIPlatformCharset> platformCharset =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = platformCharset->GetCharset(kPlatformCharsetSel_PlainTextInFile,
aCharset);
}
if (NS_FAILED(rv))
aCharset.Assign("ISO-8859-1");
}
// MIME encoder, output string should be freed by PR_FREE
// XXX : fix callers later to avoid allocation and copy
char * nsMsgI18NEncodeMimePartIIStr(const char *header, PRBool structured, const char *charset, PRInt32 fieldnamelen, PRBool usemime)

View File

@ -105,6 +105,13 @@ NS_MSG_BASE const char *nsMsgI18NGetAcceptLanguage(void);
*/
NS_MSG_BASE const char * nsMsgI18NFileSystemCharset(void);
/**
* Return charset name of text file (OS dependent).
*
* @param aCharset [OUT] Text file charset name.
*/
NS_MSG_BASE void nsMsgI18NTextFileCharset(nsACString& aCharset);
/**
* Convert from unicode to target charset.
*

View File

@ -3498,7 +3498,8 @@ nsMsgCompose::ConvertTextToHTML(nsFileSpec& aSigFile, nsString &aSigData)
}
nsresult
nsMsgCompose::LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData)
nsMsgCompose::LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData,
PRBool aAllowUTF8)
{
PRInt32 readSize;
PRInt32 nGot;
@ -3534,9 +3535,17 @@ nsMsgCompose::LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData)
nsCAutoString sigEncoding(nsMsgI18NParseMetaCharset(&fSpec));
PRBool removeSigCharset = !sigEncoding.IsEmpty() && m_composeHTML;
//default to platform encoding for signature files w/o meta charset
if (sigEncoding.IsEmpty())
sigEncoding.Assign(nsMsgI18NFileSystemCharset());
if (sigEncoding.IsEmpty()) {
if (aAllowUTF8 && IsUTF8(nsDependentCString(readBuf))) {
sigEncoding.Assign("UTF-8");
}
else {
//default to platform encoding for plain text files w/o meta charset
nsCAutoString textFileCharset;
nsMsgI18NTextFileCharset(textFileCharset);
sigEncoding.Assign(textFileCharset);
}
}
if (NS_FAILED(ConvertToUnicode(sigEncoding.get(), readBuf, sigData)))
CopyASCIItoUTF16(readBuf, sigData);

View File

@ -97,7 +97,9 @@ private:
PRInt32 mWhatHolder;
nsresult LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData);
nsresult LoadDataFromFile(nsFileSpec& fSpec,
nsString &sigData,
PRBool aAllowUTF8 = PR_TRUE);
/*
nsresult GetCompFields(nsMsgCompFields **aCompFields)