From 5d610310956fda883efbfbca5e744db67c90ec0d Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Tue, 18 May 1999 21:46:56 +0000 Subject: [PATCH] changes to get news to work at the same time as imap and pop. the news part of the fix for #6405 git-svn-id: svn://10.0.0.236/trunk@32098 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mailnews/local/src/nsLocalMailFolder.cpp | 4 +- mozilla/mailnews/news/src/nsNewsFolder.cpp | 25 ++++++++---- mozilla/mailnews/news/src/nsNewsUtils.cpp | 38 +++++++++++++++++++ mozilla/mailnews/news/src/nsNewsUtils.h | 3 ++ 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp index ccb0b2c2428..aeb148eab4d 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp @@ -1083,8 +1083,8 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetNewMessages() NS_WITH_SERVICE(nsIPop3Service, pop3Service, kCPop3ServiceCID, &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr server; - rv = GetServer(getter_AddRefs(server)); + nsCOMPtr server; + rv = GetServer(getter_AddRefs(server)); nsCOMPtr popServer; rv = server->QueryInterface(nsIPop3IncomingServer::GetIID(), diff --git a/mozilla/mailnews/news/src/nsNewsFolder.cpp b/mozilla/mailnews/news/src/nsNewsFolder.cpp index 24cca2c91d9..75314bb78f3 100644 --- a/mozilla/mailnews/news/src/nsNewsFolder.cpp +++ b/mozilla/mailnews/news/src/nsNewsFolder.cpp @@ -1013,7 +1013,19 @@ NS_IMETHODIMP nsMsgNewsFolder::GetUsersName(char** userName) NS_IMETHODIMP nsMsgNewsFolder::GetHostName(char** hostName) { - return NS_OK; + nsresult rv; + char *host = nsnull; + rv = nsGetNewsHostName(kNewsRootURI, mURI, &host); + //I'm recopying it because otherwise we'll have a free mismatched memory. + //We should really be using allocators to do all of this. + if(NS_SUCCEEDED(rv) && host) + { + *hostName = PL_strdup(host); + delete[] host; + if(!*hostName) + return NS_ERROR_OUT_OF_MEMORY; + } + return rv; } NS_IMETHODIMP nsMsgNewsFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate) @@ -1090,16 +1102,13 @@ NS_IMETHODIMP nsMsgNewsFolder::GetNewMessages() printf("sorry, can't get news for entire news server yet. try it on a newsgroup by newsgroup level\n"); return NS_OK; } - - NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kMsgMailSessionCID, &rv); - if (NS_FAILED(rv)) return rv; - + NS_WITH_SERVICE(nsINntpService, nntpService, kNntpServiceCID, &rv); if (NS_FAILED(rv)) return rv; //Are we assured this is the server for this folder? nsCOMPtr server; - rv = mailSession->GetCurrentServer(getter_AddRefs(server)); + rv = GetServer(getter_AddRefs(server)); if (NS_FAILED(rv)) return rv; nsCOMPtr nntpServer; @@ -1111,8 +1120,8 @@ NS_IMETHODIMP nsMsgNewsFolder::GetNewMessages() #endif rv = nntpService->GetNewNews(nsnull,nntpServer,nsnull,mURI); } - - return rv; + return rv; + } NS_IMETHODIMP nsMsgNewsFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **message) diff --git a/mozilla/mailnews/news/src/nsNewsUtils.cpp b/mozilla/mailnews/news/src/nsNewsUtils.cpp index 141164c59f1..f17bcf9035a 100644 --- a/mozilla/mailnews/news/src/nsNewsUtils.cpp +++ b/mozilla/mailnews/news/src/nsNewsUtils.cpp @@ -75,6 +75,44 @@ nsGetNewsRoot(const char *hostname, nsFileSpec &result) return rv; } +// copy-and-paste from nsGetMailboxHostName() +// we could probably combine them in a common place to save +// space. +nsresult nsGetNewsHostName(const char *rootURI, const char *uriStr, char **hostName) +{ + if(!hostName) + return NS_ERROR_NULL_POINTER; + + nsAutoString uri = uriStr; + if (uri.Find(rootURI) != 0) // if doesn't start with rootURI + return NS_ERROR_FAILURE; + + // start parsing the uriStr + const char* curPos = uriStr; + + // skip past schema + while (*curPos != ':') curPos++; + curPos++; + while (*curPos == '/') curPos++; + + char *slashPos = PL_strchr(curPos, '/'); + int length; + + // if there are no more /'s then we just copy the rest of the string + if (slashPos) + length = (slashPos - curPos) + 1; + else + length = PL_strlen(curPos) + 1; + + *hostName = new char[length]; + if(!*hostName) + return NS_ERROR_OUT_OF_MEMORY; + + PL_strncpyz(*hostName, curPos, length); + + return NS_OK; +} + nsresult nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult) { diff --git a/mozilla/mailnews/news/src/nsNewsUtils.h b/mozilla/mailnews/news/src/nsNewsUtils.h index 108eac5e577..7d5f711c17d 100644 --- a/mozilla/mailnews/news/src/nsNewsUtils.h +++ b/mozilla/mailnews/news/src/nsNewsUtils.h @@ -53,6 +53,9 @@ static const char kNewsMessageRootURI[] = "news_message:/"; extern nsresult nsGetNewsRoot(const char* hostname, nsFileSpec &result); +extern nsresult +nsGetNewsHostName(const char *rootURI, const char *uriStr, char **hostName); + extern nsresult nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult);