From fbd57efd159ed4f663221d6541c30f7d4b094e98 Mon Sep 17 00:00:00 2001 From: "nhotta%netscape.com" Date: Tue, 11 Jul 2000 23:51:21 +0000 Subject: [PATCH] Added mailCharacterSet to nsIMsgWindow to keep the charset used by libmime, bug 28869, r=mscott. --- mailnews/base/public/nsIMsgWindow.idl | 1 + mailnews/base/src/nsMsgWindow.cpp | 33 +++++++++++++++++++++++++++ mailnews/base/src/nsMsgWindow.h | 2 ++ 3 files changed, 36 insertions(+) diff --git a/mailnews/base/public/nsIMsgWindow.idl b/mailnews/base/public/nsIMsgWindow.idl index 46153299a727..08f38623981f 100644 --- a/mailnews/base/public/nsIMsgWindow.idl +++ b/mailnews/base/public/nsIMsgWindow.idl @@ -45,6 +45,7 @@ interface nsIMsgWindow : nsISupports { attribute nsIMsgFolder openFolder; attribute nsIDocShell rootDocShell; readonly attribute nsIPrompt promptDialog; + attribute wstring mailCharacterSet; void SetDOMWindow(in nsIDOMWindow window); void StopUrls(); diff --git a/mailnews/base/src/nsMsgWindow.cpp b/mailnews/base/src/nsMsgWindow.cpp index 9f6aecc52c32..a57a2c76f0fb 100644 --- a/mailnews/base/src/nsMsgWindow.cpp +++ b/mailnews/base/src/nsMsgWindow.cpp @@ -39,6 +39,8 @@ #include "nsIWebProgressListener.h" #include "nsPIDOMWindow.h" #include "nsIPrompt.h" +#include "nsICharsetConverterManager.h" +#include "nsICharsetConverterManager2.h" // XXX Remove #include "nsIWebShell.h" @@ -230,6 +232,37 @@ NS_IMETHODIMP nsMsgWindow::SetRootDocShell(nsIDocShell * aDocShell) return NS_OK; } +NS_IMETHODIMP nsMsgWindow::GetMailCharacterSet(PRUnichar * *aMailCharacterSet) +{ + if(!aMailCharacterSet) + return NS_ERROR_NULL_POINTER; + + *aMailCharacterSet = mMailCharacterSet.ToNewUnicode(); + if (!(*aMailCharacterSet)) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; +} + +NS_IMETHODIMP nsMsgWindow::SetMailCharacterSet(const PRUnichar * aMailCharacterSet) +{ + mMailCharacterSet.Assign(aMailCharacterSet); + + // Convert to a canonical charset name instead of using the charset name from the message header as is. + // This is needed for charset menu item to have a check mark correctly. + nsresult rv; + nsCOMPtr ccm2 = do_GetService(NS_CHARSETCONVERTERMANAGER_PROGID, &rv); + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr charsetAtom; + rv = ccm2->GetCharsetAtom(mMailCharacterSet.GetUnicode(), getter_AddRefs(charsetAtom)); + if (NS_SUCCEEDED(rv)) + rv = charsetAtom->ToString(mMailCharacterSet); + } + + return NS_OK; +} + NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindow *aWindow) { if (!aWindow) diff --git a/mailnews/base/src/nsMsgWindow.h b/mailnews/base/src/nsMsgWindow.h index c06df3bce42f..c20852e4c8fa 100644 --- a/mailnews/base/src/nsMsgWindow.h +++ b/mailnews/base/src/nsMsgWindow.h @@ -57,6 +57,8 @@ protected: // let's not make this a strong ref - we don't own it. nsIDocShell *mRootDocShell; nsIDocShell *mMessageWindowDocShell; + + nsString mMailCharacterSet; }; #endif