From 9ce8cf39ca11ace4a2fa25a2aaa746cd9596e223 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Tue, 19 Dec 2000 02:36:32 +0000 Subject: [PATCH] fix for #24626. when viewing a cancelled message, display the "error" in the message pane like we did in 4.x. add the code to display random html in the message pane to nsMsgWindow, so bienvenu can use it for offline imap. known problems: title isn't being set and headers aren't being hidden. but that's next. sr=bienvenu. git-svn-id: svn://10.0.0.236/trunk@83824 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/base/public/nsIMsgWindow.idl | 4 +- mozilla/mailnews/base/src/nsMsgWindow.cpp | 50 ++++++++++++ .../resources/locale/en-US/news.properties | 5 +- mozilla/mailnews/news/src/nsNNTPProtocol.cpp | 77 +++++++++++-------- 4 files changed, 103 insertions(+), 33 deletions(-) diff --git a/mozilla/mailnews/base/public/nsIMsgWindow.idl b/mozilla/mailnews/base/public/nsIMsgWindow.idl index c252b949c0d..673f62382c2 100644 --- a/mozilla/mailnews/base/public/nsIMsgWindow.idl +++ b/mozilla/mailnews/base/public/nsIMsgWindow.idl @@ -44,8 +44,10 @@ interface nsIMsgWindow : nsISupports { attribute nsIMessageView messageView; attribute nsIMsgFolder openFolder; attribute nsIDocShell rootDocShell; + void displayHTMLInMessageWindow(in wstring title, in wstring body); + readonly attribute nsIPrompt promptDialog; - attribute wstring mailCharacterSet; + attribute wstring mailCharacterSet; void SetDOMWindow(in nsIDOMWindowInternal window); void StopUrls(); diff --git a/mozilla/mailnews/base/src/nsMsgWindow.cpp b/mozilla/mailnews/base/src/nsMsgWindow.cpp index 8d54b7f52b9..d75c2877245 100644 --- a/mozilla/mailnews/base/src/nsMsgWindow.cpp +++ b/mozilla/mailnews/base/src/nsMsgWindow.cpp @@ -42,6 +42,10 @@ #include "nsICharsetConverterManager.h" #include "nsICharsetConverterManager2.h" +#include "plbase64.h" +#include "nsMsgI18N.h" +#include "nsIWebNavigation.h" + // XXX Remove #include "nsIWebShell.h" @@ -495,3 +499,49 @@ NS_IMETHODIMP nsMsgWindow::GetPromptDialog(nsIPrompt **aPrompt) else return NS_ERROR_NULL_POINTER; } + +NS_IMETHODIMP +nsMsgWindow::DisplayHTMLInMessageWindow(const PRUnichar *title, const PRUnichar *body) +{ + nsresult rv; + + nsCAutoString charSet; + charSet.AssignWithConversion(nsMsgI18NFileSystemCharset()); + + nsAutoString htmlStr; + htmlStr.Append(NS_LITERAL_STRING("").get()); + htmlStr.Append(NS_LITERAL_STRING("").get()); + htmlStr.Append(NS_LITERAL_STRING("").get()); + htmlStr.Append(body); + htmlStr.Append(NS_LITERAL_STRING("").get()); + + nsCAutoString convertedHtml; + rv = nsMsgI18NConvertFromUnicode(charSet,htmlStr,convertedHtml); + NS_ENSURE_SUCCESS(rv,rv); + + char *encodedHtml = PL_Base64Encode((const char *)convertedHtml, 0, nsnull); + if (!encodedHtml) return NS_ERROR_OUT_OF_MEMORY; + + nsCAutoString dataSpec; + dataSpec = "data:text/html;base64,"; + dataSpec += encodedHtml; + + PR_FREEIF(encodedHtml); + + nsCOMPtr uri = do_CreateInstance("@mozilla.org/network/simple-uri;1"); + if (!uri) return NS_ERROR_UNEXPECTED; + + rv = uri->SetSpec((const char *)dataSpec); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr docShell; + GetMessageWindowDocShell(getter_AddRefs(docShell)); + if (!docShell) return NS_ERROR_UNEXPECTED; + + rv = docShell->LoadURI(uri,nsnull,nsIWebNavigation::LOAD_FLAGS_NONE); + NS_ENSURE_SUCCESS(rv,rv); + + return NS_OK; +} diff --git a/mozilla/mailnews/news/resources/locale/en-US/news.properties b/mozilla/mailnews/news/resources/locale/en-US/news.properties index 3e5bc093cd3..9c31702d4c3 100644 --- a/mozilla/mailnews/news/resources/locale/en-US/news.properties +++ b/mozilla/mailnews/news/resources/locale/en-US/news.properties @@ -25,10 +25,11 @@ downloadHeadersTitlePrefix=Download Headers downloadHeadersInfoText1=There are # LOCALIZATION NOTE ( downloadHeadersInfoText2 ): See note for downloadHeadersInfoText1 downloadHeadersInfoText2=new message headers to download for this newsgroup. +htmlNewsErrorTitle=Error! # LOCALIZATION NOTE ( htmlNewsError ): In the following item, translate only "Error!" and "newsgroup server responded:" -htmlNewsError=Error!\n

Error!

newsgroup server responded: %.256s

\n +htmlNewsError=

Error!

newsgroup server responded: # LOCALIZATION NOTE ( articleExpired ): In the following item, translate only "Perhaps the article has expired" -articleExpired=

Perhaps the article has expired

\n +articleExpired=

Perhaps the article has expired

removeExpiredArtLinkText=Click here to remove all expired articles cancelDisallowed=This message does not appear to be from you. You may only cancel your own posts, not those made by others. cancelConfirm=Are you sure you want to cancel this message? diff --git a/mozilla/mailnews/news/src/nsNNTPProtocol.cpp b/mozilla/mailnews/news/src/nsNNTPProtocol.cpp index fab2d2a5244..f56bfc8b3b6 100644 --- a/mozilla/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mozilla/mailnews/news/src/nsNNTPProtocol.cpp @@ -24,7 +24,6 @@ * David Bienvenu * Jeff Tsai * Pierre Phaneuf - * */ #define FORCE_PR_LOG /* Allow logging in the release build (sorry this breaks the PCH) */ @@ -1990,45 +1989,61 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommandResponse() } if (NS_SUCCEEDED(rv) && group_name) { - // the right thing todo is: - // get the right docshell, gotten from the nsIMsgWindow - // build up a data url - // call (docshell)->LoadURL() with that data url -#ifdef NOT_WORKING_YET - char outputBuffer[OUTPUT_BUFFER_SIZE]; - PRUint32 count = 0; - + nsXPIDLString titleStr; + rv = GetNewsStringByName("htmlNewsErrorTitle", getter_Copies(titleStr)); + NS_ENSURE_SUCCESS(rv,rv); + nsXPIDLString newsErrorStr; - GetNewsStringByName("htmlNewsError", getter_Copies(newsErrorStr)); - nsCAutoString cString(newsErrorStr); - PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE, (const char *) cString, m_responseText); - mDisplayOutputStream->Write(outputBuffer, PL_strlen(outputBuffer), &count); - - GetNewsStringByName("articleExpired", getter_Copies(newsErrorStr)); - nsCAutoString cString2(newsErrorStr); - PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE, (const char *) cString2); - mDisplayOutputStream->Write(outputBuffer, PL_strlen(outputBuffer), &count); + rv = GetNewsStringByName("htmlNewsError", getter_Copies(newsErrorStr)); + NS_ENSURE_SUCCESS(rv,rv); + nsAutoString errorHtml; + errorHtml.Append(newsErrorStr); + + errorHtml.Append(NS_LITERAL_STRING("").get()); + errorHtml.AppendWithConversion(m_responseText); + errorHtml.Append(NS_LITERAL_STRING("

").get()); + + rv = GetNewsStringByName("articleExpired", getter_Copies(newsErrorStr)); + NS_ENSURE_SUCCESS(rv,rv); + errorHtml.Append(newsErrorStr); nsMsgKey key = nsMsgKey_None; rv = m_runningURL->GetMessageKey(&key); + NS_ENSURE_SUCCESS(rv,rv); + + char outputBuffer[OUTPUT_BUFFER_SIZE]; + NS_ASSERTION(m_messageID && (key != nsMsgKey_None), "unexpected"); if (m_messageID && (key != nsMsgKey_None)) { - PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

<%.512s> (%lu)", m_messageID, key); - mDisplayOutputStream->Write(outputBuffer, PL_strlen(outputBuffer), &count); + PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

<%.512s> (%lu)", m_messageID, key); + errorHtml.AppendWithConversion(outputBuffer); } - GetNewsStringByName("removeExpiredArtLinkText", getter_Copies(newsErrorStr)); - nsCAutoString cString3(newsErrorStr); if (m_userName) { - PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

%s

\n", kNewsRootURI, (const char *)m_userName, (const char *)m_hostName, - (const char *) group_name, (const char *) cString3); + PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

", kNewsRootURI, (const char *)m_userName, (const char *)m_hostName, + (const char *) group_name); } else { - PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

%s

\n", kNewsRootURI, (const char *)m_hostName, - (const char *) group_name, (const char *) cString3); + PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

", kNewsRootURI, (const char *)m_hostName, (const char *) group_name); } - mDisplayOutputStream->Write(outputBuffer, PL_strlen(outputBuffer), &count); -#endif /* NOT_WORKING_YET */ + + errorHtml.AppendWithConversion(outputBuffer); + + rv = GetNewsStringByName("removeExpiredArtLinkText", getter_Copies(newsErrorStr)); + NS_ENSURE_SUCCESS(rv,rv); + errorHtml.Append(newsErrorStr); + errorHtml.Append(NS_LITERAL_STRING("

").get()); + + if (!m_msgWindow) { + nsCOMPtr mailnewsurl = do_QueryInterface(m_runningURL); + if (mailnewsurl) { + rv = mailnewsurl->GetMsgWindow(getter_AddRefs(m_msgWindow)); + NS_ENSURE_SUCCESS(rv,rv); + } + } + if (!m_msgWindow) return NS_ERROR_FAILURE; + rv = m_msgWindow->DisplayHTMLInMessageWindow((const PRUnichar *)titleStr, errorHtml.GetUnicode()); + NS_ENSURE_SUCCESS(rv,rv); } return MK_NNTP_SERVER_ERROR; } @@ -4581,6 +4596,7 @@ PRInt32 nsNNTPProtocol::ListGroup() char outputBuffer[OUTPUT_BUFFER_SIZE]; PRInt32 status = 0; rv = m_newsgroup->GetName(getter_Copies(group_name)); + NS_ENSURE_SUCCESS(rv,rv); PR_snprintf(outputBuffer, OUTPUT_BUFFER_SIZE, @@ -4590,9 +4606,10 @@ PRInt32 nsNNTPProtocol::ListGroup() nsnull, NS_GET_IID(nsINNTPArticleList), getter_AddRefs(m_articleList)); - if (NS_FAILED(rv)) return -1; // ??? + NS_ENSURE_SUCCESS(rv,rv); - m_articleList->Initialize(m_newsHost, m_newsgroup); + rv = m_articleList->Initialize(m_newsHost, m_newsgroup); + NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr mailnewsurl = do_QueryInterface(m_runningURL); if (mailnewsurl)