From 5ba9158b81f890ab1f020815b887a92192b35dd7 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Wed, 3 Jan 2001 01:18:50 +0000 Subject: [PATCH] fix for #41146. get news:group urls to work properly. sr=bienvenu --- mailnews/news/src/nsNewsFolder.cpp | 5 ---- mailnews/news/src/nsNntpService.cpp | 45 +++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/mailnews/news/src/nsNewsFolder.cpp b/mailnews/news/src/nsNewsFolder.cpp index c669d5c633a1..9a911d7c9226 100644 --- a/mailnews/news/src/nsNewsFolder.cpp +++ b/mailnews/news/src/nsNewsFolder.cpp @@ -441,14 +441,9 @@ nsMsgNewsFolder::GetCanRename(PRBool *aResult) return NS_OK; } - NS_IMETHODIMP nsMsgNewsFolder::GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *result) { -#ifdef DEBUG_NEWS - printf("nsMsgNewsFolder::GetMessages(%s)\n",mURI); -#endif - nsresult rv = NS_OK; rv = GetDatabase(aMsgWindow); diff --git a/mailnews/news/src/nsNntpService.cpp b/mailnews/news/src/nsNntpService.cpp index 1d13378e6bd1..aa768364b935 100644 --- a/mailnews/news/src/nsNntpService.cpp +++ b/mailnews/news/src/nsNntpService.cpp @@ -953,19 +953,15 @@ nsNntpService::GetProtocolForUri(nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTP nsXPIDLCString hostName; nsXPIDLCString userName; nsXPIDLCString scheme; + nsXPIDLCString path; PRInt32 port = 0; nsresult rv; -#ifdef DEBUG_sspitzer - nsXPIDLCString spec; - rv = aUri->GetSpec(getter_Copies(spec)); - printf("GetProtocolForUri(%s,...)\n",(const char *)spec); -#endif - rv = aUri->GetHost(getter_Copies(hostName)); rv = aUri->GetPreHost(getter_Copies(userName)); rv = aUri->GetScheme(getter_Copies(scheme)); rv = aUri->GetPort(&port); + rv = aUri->GetPath(getter_Copies(path)); nsCOMPtr accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -997,6 +993,14 @@ nsNntpService::GetProtocolForUri(nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTP messengerMigrator->UpgradePrefs(); } + // news:group becomes news://group, so we have three types of urls: + // news://group (autosubscribing without a host) + // news://host/group (autosubscribing with a host) + // news://host (updating the unread message counts on a server) + // + // first, check if hostName is really a server or a group + // by looking for a server with hostName + // // xxx todo what if we have two servers on the same host, but different ports? // or no port, but isSecure (snews:// vs news://) is different? rv = accountManager->FindServer((const char *)userName, @@ -1004,6 +1008,35 @@ nsNntpService::GetProtocolForUri(nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTP "nntp", getter_AddRefs(server)); + // if we didn't find the server, and path was "/", this is a news://group url + if (!server && !(nsCRT::strcmp("/",(const char *)path))) { + // the uri was news://group and we want to turn that into news://host/group + // step 1, set the path to be the hostName; + rv = aUri->SetPath((const char *)hostName); + NS_ENSURE_SUCCESS(rv,rv); + + // until we support default news servers, use the first nntp server we find + rv = accountManager->FindServer("","","nntp", getter_AddRefs(server)); + if (NS_FAILED(rv) || !server) { + // step 2, set the uri's hostName and the local variable hostName + // to be "news" + rv = aUri->SetHost("news"); + NS_ENSURE_SUCCESS(rv,rv); + + rv = aUri->GetHost(getter_Copies(hostName)); + NS_ENSURE_SUCCESS(rv,rv); + } + else { + // step 2, set the uri's hostName and the local variable hostName + // to be the host name of the server we found + rv = server->GetHostName(getter_Copies(hostName)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = aUri->SetHost((const char *)hostName); + NS_ENSURE_SUCCESS(rv,rv); + } + } + if (NS_FAILED(rv) || !server) { PRBool isSecure = PR_FALSE; if (nsCRT::strcasecmp("snews",(const char *)scheme) == 0) {