diff --git a/intl/uconv/public/nsIPlatformCharset.h b/intl/uconv/public/nsIPlatformCharset.h index 9a070cb29ff7..08091eef8142 100644 --- a/intl/uconv/public/nsIPlatformCharset.h +++ b/intl/uconv/public/nsIPlatformCharset.h @@ -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 diff --git a/mailnews/base/util/nsMsgI18N.cpp b/mailnews/base/util/nsMsgI18N.cpp index ec8c6d324bdd..2d1eac3653f2 100644 --- a/mailnews/base/util/nsMsgI18N.cpp +++ b/mailnews/base/util/nsMsgI18N.cpp @@ -216,6 +216,21 @@ const char * nsMsgI18NFileSystemCharset() return fileSystemCharset.get(); } +// Charset used by the text file. +void nsMsgI18NTextFileCharset(nsACString& aCharset) +{ + nsresult rv; + nsCOMPtr 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) diff --git a/mailnews/base/util/nsMsgI18N.h b/mailnews/base/util/nsMsgI18N.h index ca7b1bc167ed..ac4c21f87da2 100644 --- a/mailnews/base/util/nsMsgI18N.h +++ b/mailnews/base/util/nsMsgI18N.h @@ -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. * diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index 2055fc5d0358..e9167ef8bfd5 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -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); diff --git a/mailnews/compose/src/nsMsgCompose.h b/mailnews/compose/src/nsMsgCompose.h index 64abdaf55eb5..9c9754f13d91 100644 --- a/mailnews/compose/src/nsMsgCompose.h +++ b/mailnews/compose/src/nsMsgCompose.h @@ -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)