From 21297e7a96ba563360d999907e5ca599c5bbb773 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Sun, 13 Jun 1999 20:37:56 +0000 Subject: [PATCH] clean up my original hack to display error messages in the message pane. before I was using a .eml file, and so I need the error message to be an rfc 822 message for things to work. Now, the file is a .htm file, so I can just write normal html to the file, and it will work. all this will go away when we don't have to use files, and we can write directly to the stream. --- mailnews/news/src/nsNNTPProtocol.cpp | 30 ++++++++++++++-------------- mailnews/news/src/nsNNTPProtocol.h | 9 ++++++++- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 18af6f3bd1eb..6da544e09278 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -365,7 +365,7 @@ char *MSG_UnEscapeSearchUrl (const char *commandSpecificData) /////////////////////////////////////////////////////////////////////////////////////////// -nsNNTPProtocol::nsNNTPProtocol() : m_tempArticleFile(ARTICLE_PATH) +nsNNTPProtocol::nsNNTPProtocol() : m_tempArticleFile(ARTICLE_PATH), m_tempErrorFile(ERROR_PATH) { m_cancelFromHdr = nsnull; m_cancelNewsgroups = nsnull; @@ -1833,7 +1833,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommandResponse() else m_nextState = NNTP_ERROR; - /* START OF HACK */ + /* START OF HACK TO DISPLAY THE ERROR IN THE MESSAGE PANE */ nsresult rv = NS_OK; char *group_name = nsnull; char outputBuffer[OUTPUT_BUFFER_SIZE]; @@ -1846,39 +1846,39 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommandResponse() #if 0 PR_snprintf(outputBuffer, OUTPUT_BUFFER_SIZE, "

%s

\n", "news:", m_hostName, group_name, "Click here to remove all expired articles"); #else - PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"Path: secnews.netscape.com!not-for-mail\nFrom: article expired\nSubject: Error! Article cancelled.\nOrganization: article expired\nNewsgroups: article expired\nLines: 5\nMime-Version: 1.0\nContent-Type: text/html; charset=us-ascii\nContent-Transfer-Encoding: 7bit\nX-Mailer: Mozilla 5.0 [en] (Unix; I)\nX-Accept-Language: en\n\n

Error!


\nnewsgroup server responded: Bad article number
\nPerhaps the article has expired
\n <%s> (%d)
\n

%s

\n", "foobar", -1, "news:", m_hostName, group_name, "Click here to remove all expired articles"); + PR_snprintf(outputBuffer,OUTPUT_BUFFER_SIZE,"

Error!


\nnewsgroup server responded: Bad article number
\nPerhaps the article has expired
\n <%s> (%d)
\n

%s

\n", "foobar", -1, kNewsRootURI, m_hostName, group_name, "Click here to remove all expired articles"); #endif } - m_tempArticleFile.Delete(PR_FALSE); + m_tempErrorFile.Delete(PR_FALSE); nsISupports * supports; - NS_NewIOFileStream(&supports, m_tempArticleFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 00700); - m_tempArticleStream = do_QueryInterface(supports); + NS_NewIOFileStream(&supports, m_tempErrorFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 00700); + m_tempErrorStream = do_QueryInterface(supports); NS_IF_RELEASE(supports); - if (m_tempArticleStream) { + if (m_tempErrorStream) { PRUint32 count = 0; - m_tempArticleStream->Write(outputBuffer, PL_strlen(outputBuffer), &count); + m_tempErrorStream->Write(outputBuffer, PL_strlen(outputBuffer), &count); } // and close the article file if it was open.... - if (m_tempArticleStream) - m_tempArticleStream->Close(); + if (m_tempErrorStream) + m_tempErrorStream->Close(); /* cut and paste from below */ if (m_displayConsumer) { - nsFilePath filePath(ARTICLE_PATH); + nsFilePath filePath(ERROR_PATH); nsFileURL fileURL(filePath); - char * article_path_url = PL_strdup(fileURL.GetAsString()); + char * error_path_url = PL_strdup(fileURL.GetAsString()); #ifdef DEBUG_NEWS - printf("load this url to display the message: %s\n", article_path_url); + printf("load this url to display the error message: %s\n", error_path_url); #endif - m_displayConsumer->LoadURL(nsAutoString(article_path_url).GetUnicode(), nsnull, PR_TRUE, nsURLReload, 0); + m_displayConsumer->LoadURL(nsAutoString(error_path_url).GetUnicode(), nsnull, PR_TRUE, nsURLReload, 0); - PR_FREEIF(article_path_url); + PR_FREEIF(error_path_url); } /* cut and paste from below */ /* END OF HACK */ diff --git a/mailnews/news/src/nsNNTPProtocol.h b/mailnews/news/src/nsNNTPProtocol.h index e3b12a65509e..1aa875ca886b 100644 --- a/mailnews/news/src/nsNNTPProtocol.h +++ b/mailnews/news/src/nsNNTPProtocol.h @@ -42,14 +42,17 @@ #ifdef XP_UNIX #define ARTICLE_PATH "/usr/tmp/tempMessage.eml" +#define ERROR_PATH "/usr/tmp/errorMessage.htm" #endif #ifdef XP_PC #define ARTICLE_PATH "c:\\temp\\tempMessage.eml" +#define ERROR_PATH "c:\\temp\\errorMessage.htm" #endif #ifdef XP_MAC -#define ARTICLE_PATH "tempMessage.eml" +#define ARTICLE_PATH "tempMessage.eml" +#define ERROR_PATH "errorMessage.htm" #endif // State Flags (Note, I use the word state in terms of storing @@ -181,6 +184,10 @@ private: // converter interface... nsCOMPtr m_tempArticleStream; nsFileSpec m_tempArticleFile; + // same trick as above, but used for showing error message in the + // message pane. + nsCOMPtr m_tempErrorStream; + nsFileSpec m_tempErrorFile; // News Event Sinks nsCOMPtr m_newsgroupList;