From d8235fe21a14bfed2f0d5092f492b5310ddc5cad Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Sat, 14 Apr 2001 15:30:19 +0000 Subject: [PATCH] fix 75912 downloading news msgs for offline use stops if article not found, also 71581 hang going offline if you have no newsgroups configured for offline use sr=sspitzer --- mailnews/news/src/nsNNTPProtocol.cpp | 13 +++++++--- mailnews/news/src/nsNewsDownloader.cpp | 35 ++++++++++++++++++-------- mailnews/news/src/nsNewsDownloader.h | 4 +-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 2297c0b01992..8a5045f3b278 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -2214,7 +2214,11 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommandResponse() else m_nextState = NNTP_ERROR; - if (NS_SUCCEEDED(rv) && group_name) { + PRBool savingArticleOffline = PR_FALSE; + if (m_newsFolder) + m_newsFolder->GetSaveArticleOffline(&savingArticleOffline); + + if (NS_SUCCEEDED(rv) && group_name && !savingArticleOffline) { nsXPIDLString titleStr; rv = GetNewsStringByName("htmlNewsErrorTitle", getter_Copies(titleStr)); NS_ENSURE_SUCCESS(rv,rv); @@ -5242,8 +5246,11 @@ nsresult nsNNTPProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp m_nextState = NEWS_FREE; break; case NEWS_ERROR: - NNTP_LOG_NOTE("NEWS_ERROR"); - mailnewsurl->SetUrlState(PR_FALSE, NS_ERROR_FAILURE); + NNTP_LOG_NOTE("NEWS_ERROR"); + if (m_responseCode == MK_NNTP_RESPONSE_ARTICLE_NOTFOUND || m_responseCode == MK_NNTP_RESPONSE_ARTICLE_NONEXIST) + mailnewsurl->SetUrlState(PR_FALSE, NS_MSG_NEWS_ARTICLE_NOT_FOUND); + else + mailnewsurl->SetUrlState(PR_FALSE, NS_ERROR_FAILURE); m_nextState = NEWS_FREE; break; case NNTP_ERROR: diff --git a/mailnews/news/src/nsNewsDownloader.cpp b/mailnews/news/src/nsNewsDownloader.cpp index 68b7bc8298ee..0acc5e0a8c86 100644 --- a/mailnews/news/src/nsNewsDownloader.cpp +++ b/mailnews/news/src/nsNewsDownloader.cpp @@ -92,7 +92,7 @@ NS_IMETHODIMP nsNewsDownloader::OnStartRunningUrl(nsIURI* url) NS_IMETHODIMP nsNewsDownloader::OnStopRunningUrl(nsIURI* url, nsresult exitCode) { nsresult rv = exitCode; - if (NS_SUCCEEDED(exitCode)) + if (NS_SUCCEEDED(exitCode) || exitCode == NS_MSG_NEWS_ARTICLE_NOT_FOUND) rv = DownloadNext(PR_FALSE); return rv; @@ -367,7 +367,7 @@ NS_IMETHODIMP nsMsgDownloadAllNewsgroups::OnStopRunningUrl(nsIURI* url, nsresult exitCode) { nsresult rv = exitCode; - if (NS_SUCCEEDED(exitCode)) + if (NS_SUCCEEDED(exitCode) || exitCode == NS_MSG_NEWS_ARTICLE_NOT_FOUND) rv = ProcessNextGroup(); else if (m_listener) // notify main observer. m_listener->OnStopRunningUrl(url, exitCode); @@ -379,10 +379,14 @@ nsMsgDownloadAllNewsgroups::OnStopRunningUrl(nsIURI* url, nsresult exitCode) // might have folders to download for offline use. If no more servers, // m_currentServer will be left at nsnull. // Also, sets up m_serverEnumerator to enumerate over the server -nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer() +// If no servers found, m_serverEnumerator will be left at null, +nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer(PRBool *done) { nsresult rv; + NS_ENSURE_ARG(done); + + *done = PR_TRUE; if (!m_allServers) { NS_WITH_SERVICE(nsIMsgAccountManager, accountManager, @@ -407,7 +411,7 @@ nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer() nsCOMPtr server = do_QueryInterface(serverSupports); NS_RELEASE(serverSupports); nsCOMPtr newsServer = do_QueryInterface(server); - if (!newsServer) // news servers aren't involved in offline imap + if (!newsServer) // we're only looking for news servers continue; if (server) { @@ -423,7 +427,10 @@ nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer() { rv = m_serverEnumerator->First(); if (NS_SUCCEEDED(rv)) + { + *done = PR_FALSE; break; + } } } } @@ -431,9 +438,11 @@ nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer() return rv; } -nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextGroup() +nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextGroup(PRBool *done) { nsresult rv; + NS_ENSURE_ARG(done); + *done = PR_TRUE; if (m_currentFolder) { @@ -444,18 +453,21 @@ nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextGroup() m_currentFolder = nsnull; } + *done = PR_FALSE; + if (!m_currentServer) - rv = AdvanceToNextServer(); + rv = AdvanceToNextServer(done); else rv = m_serverEnumerator->Next(); if (!NS_SUCCEEDED(rv)) - rv = AdvanceToNextServer(); + rv = AdvanceToNextServer(done); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv) && !*done && m_serverEnumerator) { nsCOMPtr supports; rv = m_serverEnumerator->CurrentItem(getter_AddRefs(supports)); m_currentFolder = do_QueryInterface(supports); + *done = PR_FALSE; } return rv; } @@ -478,10 +490,11 @@ nsresult DownloadMatchingNewsArticlesToNewsDB::RunSearch(nsIMsgFolder *folder, n nsresult nsMsgDownloadAllNewsgroups::ProcessNextGroup() { nsresult rv = NS_OK; + PRBool done = PR_FALSE; - while (NS_SUCCEEDED(rv)) + while (NS_SUCCEEDED(rv) && !done) { - rv = AdvanceToNextGroup(); + rv = AdvanceToNextGroup(&done); if (m_currentFolder) { PRUint32 folderFlags; @@ -490,7 +503,7 @@ nsresult nsMsgDownloadAllNewsgroups::ProcessNextGroup() break; } } - if (!NS_SUCCEEDED(rv)) + if (!NS_SUCCEEDED(rv) || done) { if (m_listener) return m_listener->OnStopRunningUrl(nsnull, NS_OK); diff --git a/mailnews/news/src/nsNewsDownloader.h b/mailnews/news/src/nsNewsDownloader.h index a687e709f044..ab88da15f793 100644 --- a/mailnews/news/src/nsNewsDownloader.h +++ b/mailnews/news/src/nsNewsDownloader.h @@ -118,8 +118,8 @@ public: nsresult ProcessNextGroup(); protected: - nsresult AdvanceToNextServer(); - nsresult AdvanceToNextGroup(); + nsresult AdvanceToNextServer(PRBool *done); + nsresult AdvanceToNextGroup(PRBool *done); DownloadMatchingNewsArticlesToNewsDB *m_downloaderForGroup;