From 5fc7d2ab7577b3ead4e5bedc11579ad9ad10052e Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Tue, 14 Mar 2000 07:21:44 +0000 Subject: [PATCH] fix for #31715. pass the nsIMsgWindow when trying to post a message. (we may need it, if we have to authenticate the use for posting.) also, clean up the code to handle NS_ERROR_* properly. --- mailnews/compose/src/nsMsgSend.cpp | 14 +++++++++- mailnews/news/public/nsINntpService.idl | 2 +- mailnews/news/src/nsNNTPProtocol.cpp | 37 +++++++++++++++++++------ mailnews/news/src/nsNewsFolder.cpp | 2 +- mailnews/news/src/nsNntpService.cpp | 5 ++-- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/mailnews/compose/src/nsMsgSend.cpp b/mailnews/compose/src/nsMsgSend.cpp index 6fe625b1c5e..61f0b7838d4 100644 --- a/mailnews/compose/src/nsMsgSend.cpp +++ b/mailnews/compose/src/nsMsgSend.cpp @@ -2869,7 +2869,19 @@ nsMsgComposeAndSend::DeliverFileAsNews() SetStatusMessage( msg ); PR_FREEIF(msg); - rv = nntpService->PostMessage(fileToPost, mCompFields->GetNewsgroups(), mNewsPostListener, nsnull); + nsCOMPtr mailSession = do_GetService(kMsgMailSessionCID, &rv); + if (NS_FAILED(rv)) return rv; + + if (!mailSession) return NS_ERROR_FAILURE; + + nsCOMPtr msgWindow; + rv = mailSession->GetTemporaryMsgWindow(getter_AddRefs(msgWindow)); + if (NS_FAILED(rv)) return rv; + + if (!msgWindow) return NS_ERROR_FAILURE; + + rv = nntpService->PostMessage(fileToPost, mCompFields->GetNewsgroups(), mNewsPostListener, msgWindow, nsnull); + if (NS_FAILED(rv)) return rv; } return rv; diff --git a/mailnews/news/public/nsINntpService.idl b/mailnews/news/public/nsINntpService.idl index 109d80c9001..78a33ab9192 100644 --- a/mailnews/news/public/nsINntpService.idl +++ b/mailnews/news/public/nsINntpService.idl @@ -36,7 +36,7 @@ interface nsINntpService : nsISupports { string convertNewsgroupsString(in string newsgroupsStr); - nsIURI postMessage (in nsIFileSpec fileToPost, in string newsgroupNames, in nsIUrlListener aUrlListener); + nsIURI postMessage (in nsIFileSpec fileToPost, in string newsgroupNames, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow); nsIURI getNewNews (in nsINntpIncomingServer nntpServer, in string uri, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow); diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 9b6dd751198..f73f8ebe5b7 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -1174,7 +1174,7 @@ PRInt32 nsNNTPProtocol::NewsResponse(nsIInputStream * inputStream, PRUint32 leng ((m_responseCode != MK_NNTP_RESPONSE_AUTHINFO_REQUIRE) && (m_responseCode != MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_REQUIRE))) { nsresult rv; - NS_WITH_SERVICE(nsIPrompt, dialog, kCNetSupportDialogCID, &rv); + nsCOMPtr dialog = do_GetService(kCNetSupportDialogCID, &rv); if (NS_SUCCEEDED(rv) || dialog) { nsXPIDLString errorText; GetNewsStringByName("errorFromServer", getter_Copies(errorText)); @@ -2366,6 +2366,7 @@ PRInt32 nsNNTPProtocol::BeginAuthorization() } if (NS_FAILED(rv) || !cachedUsername) { + rv = NS_OK; #ifdef DEBUG_NEWS printf("ask for the news username\n"); #endif /* DEBUG_NEWS */ @@ -2373,14 +2374,23 @@ PRInt32 nsNNTPProtocol::BeginAuthorization() nsXPIDLString usernamePromptText; GetNewsStringByName("enterUsername", getter_Copies(usernamePromptText)); if (m_newsFolder) { - if (!m_msgWindow) { nsCOMPtr mailnewsurl = do_QueryInterface(m_runningURL); if (mailnewsurl) { rv = mailnewsurl->GetMsgWindow(getter_AddRefs(m_msgWindow)); } - } - rv = m_newsFolder->GetGroupUsernameWithUI(usernamePromptText, nsnull, m_msgWindow, getter_Copies(username)); + } + + if (!m_msgWindow) { +#ifdef DEBUG_NEWS + printf("unable to get the msg window\n"); +#endif /* DEBUG_NEWS */ + rv = NS_ERROR_NULL_POINTER; + } + + if (NS_SUCCEEDED(rv)) { + rv = m_newsFolder->GetGroupUsernameWithUI(usernamePromptText, nsnull, m_msgWindow, getter_Copies(username)); + } } else { printf("we don't know the folder\n"); @@ -2486,6 +2496,8 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse() rv = m_newsFolder->GetGroupPassword(getter_Copies(cachedPassword)); } if (NS_FAILED(rv) || !cachedPassword) { + rv = NS_OK; + #ifdef DEBUG_NEWS printf("ask for the news password\n"); #endif /* DEBUG_NEWS */ @@ -2502,7 +2514,17 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse() rv = mailnewsurl->GetMsgWindow(getter_AddRefs(m_msgWindow)); } } - rv = m_newsFolder->GetGroupPasswordWithUI(passwordPromptText, passwordPromptTitleText, m_msgWindow, getter_Copies(password)); + + if (!m_msgWindow) { + rv = NS_ERROR_NULL_POINTER; +#ifdef DEBUG_NEWS + printf("unable to get the msg window\n"); +#endif /* DEBUG_NEWS */ + } + + if (NS_SUCCEEDED(rv)) { + rv = m_newsFolder->GetGroupPasswordWithUI(passwordPromptText, passwordPromptTitleText, m_msgWindow, getter_Copies(password)); + } } else { printf("we don't know the folder\n"); @@ -3746,7 +3768,7 @@ PRInt32 nsNNTPProtocol::DoCancel() cancelInfo.old_from = m_cancelFromHdr; cancelInfo.from = nsnull; - NS_WITH_SERVICE(nsIPrompt, dialog, kCNetSupportDialogCID, &rv); + nsCOMPtr dialog = do_GetService(kCNetSupportDialogCID, &rv); if (NS_FAILED(rv) || !dialog) return -1; /* unable to get the dialog service */ NS_ASSERTION (id && newsgroups, "null ptr"); @@ -4795,9 +4817,6 @@ nsresult nsNNTPProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp break; case NNTP_ERROR: -#ifdef DEBUG_NEWS - printf("NNTP_ERROR!\n"); -#endif #if 0 // mscott 01/04/99. This should be temporary until I figure out what to do with this code..... if(cd->stream) { diff --git a/mailnews/news/src/nsNewsFolder.cpp b/mailnews/news/src/nsNewsFolder.cpp index 4cf79e9d42a..3ae203c3fe9 100644 --- a/mailnews/news/src/nsNewsFolder.cpp +++ b/mailnews/news/src/nsNewsFolder.cpp @@ -1311,7 +1311,7 @@ nsMsgNewsFolder::GetGroupUsernameWithUI(const PRUnichar * aPromptMessage, const nsIMsgWindow* aMsgWindow, char **aGroupUsername) { - nsresult rv = NS_OK; + nsresult rv = NS_ERROR_FAILURE;; NS_ENSURE_ARG_POINTER(aMsgWindow); NS_ENSURE_ARG_POINTER(aGroupUsername); diff --git a/mailnews/news/src/nsNntpService.cpp b/mailnews/news/src/nsNntpService.cpp index 8f91470a527..0b596e44e0a 100644 --- a/mailnews/news/src/nsNntpService.cpp +++ b/mailnews/news/src/nsNntpService.cpp @@ -723,11 +723,12 @@ nsresult nsNntpService::ConvertNewsgroupsString(const char *newsgroupsNames, cha return NS_OK; } -nsresult nsNntpService::PostMessage(nsIFileSpec *fileToPost, const char *newsgroupsNames, nsIUrlListener * aUrlListener, nsIURI **_retval) +nsresult nsNntpService::PostMessage(nsIFileSpec *fileToPost, const char *newsgroupsNames, nsIUrlListener * aUrlListener, nsIMsgWindow *aMsgWindow, nsIURI **_retval) { #ifdef DEBUG_NEWS printf("nsNntpService::PostMessage(??,%s,??,??)\n",newsgroupsNames); #endif + if (!aMsgWindow) return NS_ERROR_NULL_POINTER; if (!newsgroupsNames) return NS_ERROR_NULL_POINTER; if (PL_strlen(newsgroupsNames) == 0) return NS_ERROR_FAILURE; @@ -756,7 +757,7 @@ nsresult nsNntpService::PostMessage(nsIFileSpec *fileToPost, const char *newsgro // almost there...now create a nntp protocol instance to run the url in... nsNNTPProtocol *nntpProtocol = nsnull; - nntpProtocol = new nsNNTPProtocol(mailnewsurl, nsnull); + nntpProtocol = new nsNNTPProtocol(mailnewsurl, aMsgWindow); if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;; rv = nntpProtocol->Initialize();