Fix problem Chineese Headers encoded with RFC1522 are displaying wrong - Bug: 24862 - r: jefft

This commit is contained in:
rhp%netscape.com 2000-01-29 18:19:25 +00:00
Родитель f46c291443
Коммит f37e19efbc
3 изменённых файлов: 44 добавлений и 6 удалений

Просмотреть файл

@ -39,12 +39,15 @@
#include "nsFileSpec.h"
#include "nsIRegistry.h"
#include "nsIMimeStreamConverter.h"
#include "nsIMimeConverter.h"
#include "nsMsgMimeCID.h"
static PRLogModuleInfo * gMimeEmitterLogModule = nsnull;
#define MIME_URL "chrome://messenger/locale/mimeheader.properties"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID);
NS_IMPL_ISUPPORTS2(nsMimeBaseEmitter, nsIMimeEmitter, nsIPipeObserver)
@ -87,6 +90,11 @@ nsMimeBaseEmitter::nsMimeBaseEmitter()
// Setup format for output...
mFormat = nsMimeOutput::nsMimeMessageXULDisplay;
// This is needed for conversion of I18N Strings...
nsComponentManager::CreateInstance(kCMimeConverterCID, nsnull,
NS_GET_IID(nsIMimeConverter),
getter_AddRefs(mUnicodeConverter));
// Do prefs last since we can live without this if it fails...
nsresult rv = nsServiceManager::GetService(kPrefCID, nsIPref::GetIID(), (nsISupports**)&(mPrefs));
if (! (mPrefs && NS_SUCCEEDED(rv)))
@ -555,9 +563,12 @@ nsMimeBaseEmitter::AddHeaderField(const char *field, const char *value)
// The following code is responsible for formatting headers in a manner that is
// identical to the normal XUL output.
////////////////////////////////////////////////////////////////////////////////
nsresult
nsMimeBaseEmitter::WriteHeaderFieldHTML(const char *field, const char *value)
{
char *newValue = nsnull;
if ( (!field) || (!value) )
return NS_OK;
@ -568,7 +579,25 @@ nsMimeBaseEmitter::WriteHeaderFieldHTML(const char *field, const char *value)
if (!EmitThisHeaderForPrefSetting(mHeaderDisplayType, field))
return NS_OK;
char *newValue = nsEscapeHTML(value);
if (mUnicodeConverter)
{
nsAutoString unicodeHeaderValue;
nsAutoString charset ("UTF-8");
// we're going to need a converter to convert
nsresult rv = mUnicodeConverter->DecodeMimePartIIStr(value, charset, unicodeHeaderValue);
char *tValue = unicodeHeaderValue.ToNewCString();
if (!tValue)
return NS_OK;
newValue = nsEscapeHTML(tValue);
PR_FREEIF(tValue);
}
else
{
newValue = nsEscapeHTML(value);
}
if (!newValue)
return NS_OK;

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsIStringBundle.h"
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
#include "nsIMimeConverter.h"
//
// The base emitter will serve as the place to do all of the caching,
@ -144,6 +145,9 @@ protected:
// For the format being used...
PRInt32 mFormat;
// For I18N Conversion...
nsCOMPtr<nsIMimeConverter> mUnicodeConverter;
};
#endif /* _nsMimeBaseEmitter_h_ */

Просмотреть файл

@ -65,9 +65,7 @@ nsMimeHtmlDisplayEmitter::~nsMimeHtmlDisplayEmitter(void)
nsresult nsMimeHtmlDisplayEmitter::Init()
{
// we're going to need a converter to convert
return nsComponentManager::CreateInstance(kCMimeConverterCID, nsnull,
NS_GET_IID(nsIMimeConverter), getter_AddRefs(mUnicodeConverter));
return NS_OK;
}
PRBool nsMimeHtmlDisplayEmitter::BroadCastHeadersAndAttachments()
@ -186,7 +184,10 @@ nsresult nsMimeHtmlDisplayEmitter::WriteHTMLHeaders()
headerValue = headerInfo->value;
// this interface for DecodeMimePartIIStr requires us to pass in nsStrings by reference
// we should remove the nsString requirements from the interface....
rv = mUnicodeConverter->DecodeMimePartIIStr(headerValue, charset, unicodeHeaderValue);
if (mUnicodeConverter)
rv = mUnicodeConverter->DecodeMimePartIIStr(headerValue, charset, unicodeHeaderValue);
else
unicodeHeaderValue = headerValue;
if (NS_SUCCEEDED(rv))
headerSink->HandleHeader(headerInfo->name, unicodeHeaderValue.GetUnicode());
}
@ -227,7 +228,11 @@ nsMimeHtmlDisplayEmitter::StartAttachment(const char *name, const char *contentT
nsAutoString attachmentName (name);
nsAutoString charset ("UTF-8");
rv = mUnicodeConverter->DecodeMimePartIIStr(attachmentName, charset, unicodeHeaderValue);
if (mUnicodeConverter)
rv = mUnicodeConverter->DecodeMimePartIIStr(attachmentName, charset, unicodeHeaderValue);
else
unicodeHeaderValue = attachmentName;
if (NS_SUCCEEDED(rv))
headerSink->HandleAttachment(escapedUrl, unicodeHeaderValue.GetUnicode(), uriString);
nsCRT::free(escapedUrl);