From 4bd03fe287bfd7f5530ad04ad4f29a61cef85c80 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Fri, 22 Oct 1999 01:02:08 +0000 Subject: [PATCH] start to consolidate URL and URI parsing into the base classes: remove a whole bunch of protocol-specific code in favor of generalization basically, more fixes for #14437 r=scottip --- mailnews/base/util/nsMsgFolder.cpp | 99 +++++++++++++----------- mailnews/base/util/nsMsgFolder.h | 26 +++---- mailnews/imap/src/nsImapMailFolder.cpp | 77 ------------------ mailnews/imap/src/nsImapMailFolder.h | 2 - mailnews/imap/src/nsImapUtils.cpp | 36 --------- mailnews/imap/src/nsImapUtils.h | 11 --- mailnews/local/src/nsLocalMailFolder.cpp | 61 --------------- mailnews/local/src/nsLocalMailFolder.h | 4 - mailnews/local/src/nsLocalUtils.cpp | 60 -------------- mailnews/local/src/nsLocalUtils.h | 6 -- mailnews/news/src/nsNNTPProtocol.cpp | 17 +++- mailnews/news/src/nsNewsFolder.cpp | 35 +-------- mailnews/news/src/nsNewsFolder.h | 5 +- mailnews/news/src/nsNewsUtils.cpp | 61 +-------------- mailnews/news/src/nsNewsUtils.h | 9 --- 15 files changed, 81 insertions(+), 428 deletions(-) diff --git a/mailnews/base/util/nsMsgFolder.cpp b/mailnews/base/util/nsMsgFolder.cpp index f91fbf259b2e..62cdf16e9b4f 100644 --- a/mailnews/base/util/nsMsgFolder.cpp +++ b/mailnews/base/util/nsMsgFolder.cpp @@ -45,7 +45,6 @@ static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID); nsMsgFolder::nsMsgFolder(void) : nsRDFResource(), - mName(""), mFlags(0), mParent(nsnull), mNumUnreadMessages(-1), @@ -114,29 +113,55 @@ NS_IMETHODIMP nsMsgFolder::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_IMETHODIMP nsMsgFolder::Init(const char* aURI) { + // for now, just initialize everything during Init() - // this parsing is totally hacky. we really should generalize this, - // but I'm not going to do this until we can eliminate the - // nsXXX2Name/etc routines - // -alecf + nsresult rv; + + rv = nsRDFResource::Init(aURI); + + nsCOMPtr url; + rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, + NS_GET_IID(nsIURL), + (void **)getter_AddRefs(url)); + if (NS_FAILED(rv)) return rv; - // do initial parsing of the URI - const char *cp=aURI; + rv = url->SetSpec(aURI); + if (NS_FAILED(rv)) return rv; + + // empty path => server + nsXPIDLCString path; + rv = url->GetPath(getter_Copies(path)); + if (NS_SUCCEEDED(rv)) { + if (!nsCRT::strcmp(path, "/")) + mIsServer = PR_TRUE; + else + mIsServer = PR_FALSE; + } - // skip to initial // - while (*cp && (*cp != '/')) - cp++; + // mUsername: + nsXPIDLCString userName; + rv = url->GetPreHost(getter_Copies(userName)); + if (NS_SUCCEEDED(rv)) { + mUsername = userName; + } - // skip past // - while (*cp && (*cp == '/')) - cp++; + // mHostname + nsXPIDLCString hostName; + rv = url->GetHost(getter_Copies(hostName)); + if (NS_SUCCEEDED(rv)) { + mHostname = hostName; + } + + // mName: + // the name is the trailing directory in the path + nsXPIDLCString fileName; + rv = url->GetFileName(getter_Copies(fileName)); + if (NS_SUCCEEDED(rv)) { + // XXX conversion to unicode here? is fileName in UTF8? + mName = fileName; + } - if (PL_strchr(cp, '/')) - mIsServer = PR_FALSE; - else - mIsServer = PR_TRUE; - - return nsRDFResource::Init(aURI); + return NS_OK; } @@ -252,6 +277,7 @@ nsMsgFolder::FindSubFolder(const char *subFolderName, nsIFolder **aFolder) if(NS_FAILED(rv)) return rv; + // XXX use necko here nsCAutoString uri; uri.Append(mURI); uri.Append('/'); @@ -468,21 +494,6 @@ NS_IMETHODIMP nsMsgFolder::GetName(PRUnichar **name) if (!name) return NS_ERROR_NULL_POINTER; - *name = nsnull; - - // cache the name in mName - if (mName.IsEmpty()) { - // return the leaf of this URI - char *lastSlash = PL_strrchr(mURI, '/'); - if (lastSlash) { - lastSlash++; - mName = lastSlash; - } else { - // no slashes, return the whole URI - mName = mURI; - } - } - *name = mName.ToNewUnicode(); if (!(*name)) return NS_ERROR_OUT_OF_MEMORY; @@ -1414,25 +1425,20 @@ NS_IMETHODIMP nsMsgFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, return NS_OK; } -#if 0 NS_IMETHODIMP nsMsgFolder::GetUsername(char **userName) { - nsCOMPtr server; - nsresult rv = GetServer(getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - return server->GetUsername(userName); + NS_ENSURE_ARG_POINTER(userName); + + *userName = mUsername.ToNewCString(); + return NS_OK; } NS_IMETHODIMP nsMsgFolder::GetHostname(char **hostName) { - nsCOMPtr server; - nsresult rv = GetServer(getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - return server->GetHostname(hostName); + NS_ENSURE_ARG_POINTER(hostName); + *hostName = mHostname.ToNewCString(); + return NS_OK; } -#endif NS_IMETHODIMP nsMsgFolder::GetNewMessages() { @@ -1742,7 +1748,6 @@ nsresult nsMsgFolder::NotifyFolderLoaded() return NS_OK; } - nsresult nsGetMailFolderSeparator(nsString& result) { diff --git a/mailnews/base/util/nsMsgFolder.h b/mailnews/base/util/nsMsgFolder.h index ff3a260049fd..df758cad400b 100644 --- a/mailnews/base/util/nsMsgFolder.h +++ b/mailnews/base/util/nsMsgFolder.h @@ -32,7 +32,7 @@ #include "nsIMsgDatabase.h" #include "nsIMsgIncomingServer.h" #include "nsCOMPtr.h" - +#include "nsIURL.h" /* * MsgFolder */ @@ -103,8 +103,8 @@ public: NS_IMETHOD RememberPassword(const char *password); NS_IMETHOD GetRememberedPassword(char * *aRememberedPassword); NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *_retval); - // NS_IMETHOD GetUsername(char * *aUsername); - // NS_IMETHOD GetHostname(char * *aHostname); + NS_IMETHOD GetUsername(char * *aUsername); + NS_IMETHOD GetHostname(char * *aHostname); NS_IMETHOD SetFlag(PRUint32 flag); NS_IMETHOD ClearFlag(PRUint32 flag); NS_IMETHOD GetFlag(PRUint32 flag, PRBool *_retval); @@ -205,19 +205,9 @@ public: void UpdateMoveCopyStatus(MWContext *context, PRBool isMove, int32 curMsgCount, int32 totMessages); #endif -#if 0 - NS_IMETHOD GetUsername(char **userName); - NS_IMETHOD GetHostname(char **hostName); -#endif - virtual nsresult GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgDatabase **db) = 0; - - - - - NS_IMETHOD MatchName(nsString *name, PRBool *matches); @@ -236,7 +226,6 @@ protected: virtual const char* GetIncomingServerType() = 0; protected: - nsString mName; PRUint32 mFlags; nsIFolder *mParent; //This won't be refcounted for ownership reasons. PRInt32 mNumUnreadMessages; /* count of unread messages (-1 means @@ -266,7 +255,16 @@ protected: PRInt32 mNumNewBiffMessages; PRBool mIsCachable; + + // + // stuff from the uri + // + PRBool mIsServer; + nsCString mUsername; + nsCString mHostname; + nsString mName; + }; #endif diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 368493123258..62ad62a7947e 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -798,83 +798,6 @@ nsresult nsImapMailFolder::GetServerKey(char **serverKey) return rv; } -NS_IMETHODIMP nsImapMailFolder::GetUsername(char** userName) -{ - nsresult rv = NS_ERROR_NULL_POINTER; - NS_PRECONDITION (userName, "Oops ... null userName pointer"); - if (!userName) - return rv; - - *userName = nsnull; - - char *uri = nsnull; - rv = GetURI(&uri); - if (NS_FAILED(rv)) return rv; - - nsAutoString aName = uri; - PR_FREEIF(uri); - if (aName.Find(kImapRootURI) != 0) - return NS_ERROR_FAILURE; - - aName.Cut(0, PL_strlen(kImapRootURI)); - while (aName[0] == '/') - aName.Cut(0, 1); - PRInt32 userEnd = aName.FindChar('@'); - if (userEnd < 1) - return NS_ERROR_NULL_POINTER; - - aName.SetLength(userEnd); - char *tmpCString = aName.ToNewCString(); - if (tmpCString && *tmpCString) - { - *userName = PL_strdup(tmpCString); - rv = NS_OK; - nsAllocator::Free(tmpCString); - } - return rv; -} - -NS_IMETHODIMP nsImapMailFolder::GetHostname(char** hostName) -{ - nsresult rv = NS_ERROR_NULL_POINTER; - - NS_PRECONDITION (hostName, "Oops ... null hostName pointer"); - if (!hostName) - return rv; - else - *hostName = nsnull; - - nsCOMPtr aFolder = do_QueryInterface((nsIMsgFolder *) this, &rv); - if (NS_FAILED(rv)) return rv; - char *uri = nsnull; - rv = aFolder->GetURI(&uri); - if (NS_FAILED(rv)) return rv; - nsAutoString aName = uri; - PR_FREEIF(uri); - if (aName.Find(kImapRootURI) == 0) - aName.Cut(0, PL_strlen(kImapRootURI)); - else - return NS_ERROR_FAILURE; - while (aName[0] == '/') - aName.Cut(0, 1); - // cut out user name ### alec, when you clean up url parsing, please get this too! - PRInt32 userNameEnd = aName.FindChar('@'); - if (userNameEnd > 0) - aName.Cut(0, userNameEnd + 1); - - PRInt32 hostEnd = aName.FindChar('/'); - if (hostEnd > 0) // must have at least one valid charater - aName.SetLength(hostEnd); - char *tmpCString = aName.ToNewCString(); - if (tmpCString && *tmpCString) - { - *hostName = PL_strdup(tmpCString); - rv = NS_OK; - nsAllocator::Free(tmpCString); - } - return rv; -} - NS_IMETHODIMP nsImapMailFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index 37990ae47a04..c9e10db40dbb 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -129,8 +129,6 @@ public: NS_IMETHOD GetSizeOnDisk(PRUint32 * size); - NS_IMETHOD GetUsername(char** userName); - NS_IMETHOD GetHostname(char** hostName); NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate); NS_IMETHOD RememberPassword(const char *password); NS_IMETHOD GetRememberedPassword(char ** password); diff --git a/mailnews/imap/src/nsImapUtils.cpp b/mailnews/imap/src/nsImapUtils.cpp index 68396b225f5f..8dfa47328ea8 100644 --- a/mailnews/imap/src/nsImapUtils.cpp +++ b/mailnews/imap/src/nsImapUtils.cpp @@ -184,42 +184,6 @@ nsImapURI2FullName(const char* rootURI, const char* hostname, char* uriStr, return NS_OK; } -nsresult -nsImapURI2UserName(const char* rootURI, const char* uriStr, - nsString& username) -{ - nsAutoString uri = uriStr; - if (uri.Find(rootURI) != 0) return NS_ERROR_FAILURE; - PRInt32 userStart = PL_strlen(rootURI); - while (uri[userStart] == '/') userStart++; - uri.Cut(0, userStart); - PRInt32 userEnd = uri.FindChar('@'); - if (userEnd < 1) - return NS_ERROR_FAILURE; - uri.SetLength(userEnd); - username = uri; - return NS_OK; -} - -nsresult -nsImapURI2HostName(const char* rootURI, const char* uriStr, - nsString& hostname) -{ - nsAutoString uri = uriStr; - if (uri.Find(rootURI) != 0) return NS_ERROR_FAILURE; - PRInt32 hostStart = PL_strlen(rootURI); - while (uri[hostStart] == '/') hostStart++; - uri.Cut(0, hostStart); - hostStart = uri.FindChar('@'); // skip username - if (hostStart > 0) - uri.Cut(0, hostStart+1); - PRInt32 hostEnd = uri.FindChar('/'); - if (hostEnd > 0) - uri.SetLength(hostEnd); - hostname = uri; - return NS_OK; -} - nsresult nsURI2ProtocolType(const char* uriStr, nsString& type) { diff --git a/mailnews/imap/src/nsImapUtils.h b/mailnews/imap/src/nsImapUtils.h index debef14169ed..0660b281509d 100644 --- a/mailnews/imap/src/nsImapUtils.h +++ b/mailnews/imap/src/nsImapUtils.h @@ -34,21 +34,10 @@ extern nsresult nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult); -extern nsresult -nsPath2ImapURI(const char* rootURI, const nsFileSpec& path, char* *uri); - extern nsresult nsImapURI2FullName(const char* rootURI, const char* hostname, char* uriStr, nsString& name); -extern nsresult -nsImapURI2HostName(const char *rootURI, const char* uriStr, - nsString& hostname); - -extern nsresult -nsImapURI2UserName(const char *rootURI, const char* uriStr, - nsString& username); - extern nsresult nsURI2ProtocolType(const char* uriStr, nsString& type); diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index e65fc2304655..407b8c3620fa 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -1003,28 +1003,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetSizeOnDisk(PRUint32* size) return NS_OK; } -NS_IMETHODIMP nsMsgLocalMailFolder::GetUsername(char** userName) -{ - return nsGetMailboxUserName(kMailboxRootURI, mURI, userName); -} - -NS_IMETHODIMP nsMsgLocalMailFolder::GetHostname(char** hostName) -{ - nsresult rv; - char *host; - rv = nsGetMailboxHostName(kMailboxRootURI, 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); - PL_strfree(host); - if(!*hostName) - return NS_ERROR_OUT_OF_MEMORY; - } - return rv; -} - NS_IMETHODIMP nsMsgLocalMailFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate) { #ifdef HAVE_PORT @@ -1116,44 +1094,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetPath(nsIFileSpec ** aPathName) return rv; } -// OK, this is kind of silly, but for now, we'll just tack the subFolderName -// onto our URI, and ask RDF to find it for us. -NS_IMETHODIMP -nsMsgLocalMailFolder::FindSubFolder(const char *subFolderName, nsIFolder **aFolder) -{ - return nsMsgFolder::FindSubFolder(subFolderName, aFolder); - -/* nsresult rv = NS_OK; - NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); - - if(NS_FAILED(rv)) - return rv; - - nsCString uri; - uri.Append(mURI); - uri.Append('/'); - - uri.Append(subFolderName); - - nsCOMPtr res; - rv = rdf->GetResource(uri.GetBuffer(), getter_AddRefs(res)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr folder(do_QueryInterface(res, &rv)); - if (NS_FAILED(rv)) - return rv; - if (aFolder) - { - *aFolder = folder; - NS_ADDREF(*aFolder); - return NS_OK; - } - else - return NS_ERROR_NULL_POINTER; -*/ -} - nsresult nsMsgLocalMailFolder::GetTrashFolder(nsIMsgFolder** result) { @@ -1650,7 +1590,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::CopyData(nsIInputStream *aIStream, PRInt32 a { char* start = mCopyState->m_dataBuffer; char* end = nsnull; - char* strPtr = nsnull; PRUint32 linebreak_len = 1; end = PL_strstr(mCopyState->m_dataBuffer, "\r"); if (!end) diff --git a/mailnews/local/src/nsLocalMailFolder.h b/mailnews/local/src/nsLocalMailFolder.h index 056b3ddd57fd..c745fd451935 100644 --- a/mailnews/local/src/nsLocalMailFolder.h +++ b/mailnews/local/src/nsLocalMailFolder.h @@ -107,8 +107,6 @@ public: NS_IMETHOD GetSizeOnDisk(PRUint32* size); - NS_IMETHOD GetUsername(char** userName); - NS_IMETHOD GetHostname(char** hostName); NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate); NS_IMETHOD RememberPassword(const char *password); NS_IMETHOD GetRememberedPassword(char ** password); @@ -131,8 +129,6 @@ public: // nsIMsgMailFolder NS_IMETHOD GetPath(nsIFileSpec ** aPathName); - NS_IMETHOD FindSubFolder(const char *subFolderName, nsIFolder **folder); - // overriding nsMsgDBFolder::GetMsgDatabase() method NS_IMETHOD GetMsgDatabase(nsIMsgDatabase **aMsgDatabase); diff --git a/mailnews/local/src/nsLocalUtils.cpp b/mailnews/local/src/nsLocalUtils.cpp index 47ec6497d26b..3c0c8a8bb913 100644 --- a/mailnews/local/src/nsLocalUtils.cpp +++ b/mailnews/local/src/nsLocalUtils.cpp @@ -271,63 +271,3 @@ nsresult nsBuildLocalMessageURI(const char *baseURI, PRUint32 key, char** uri) *uri = PR_smprintf("%s%s#%u", kMailboxMessageRootURI, tailURI.GetBuffer(), key); return NS_OK; } - -nsresult -nsGetMailboxHostName(const char *rootURI, const char *uriStr, char **hostName) -{ - - if(!hostName) - return NS_ERROR_NULL_POINTER; - - nsresult rv; - - // verify that rootURI starts with "mailbox:/" or "mailbox_message:/" - if ((PL_strcmp(rootURI, kMailboxRootURI) != 0) && - (PL_strcmp(rootURI, kMailboxMessageRootURI) != 0)) { - return NS_ERROR_FAILURE; - } - - // verify that uristr starts with rooturi - nsAutoString uri = uriStr; - if (uri.Find(rootURI) != 0) - return NS_ERROR_FAILURE; - - nsCOMPtr server; - rv = nsLocalURI2Server(uriStr, getter_AddRefs(server)); - - if (NS_FAILED(rv)) - return rv; - - return server->GetHostName(hostName); -} - - -nsresult nsGetMailboxUserName(const char *rootURI, const char* uriStr, - char **userName) -{ - - - if(!userName) - return NS_ERROR_NULL_POINTER; - - nsresult rv; - - // verify that rootURI starts with "mailbox:/" or "mailbox_message:/" - if ((PL_strcmp(rootURI, kMailboxRootURI) != 0) && - (PL_strcmp(rootURI, kMailboxMessageRootURI) != 0)) { - return NS_ERROR_FAILURE; - } - - // verify that uristr starts with rooturi - nsAutoString uri = uriStr; - if (uri.Find(rootURI) != 0) - return NS_ERROR_FAILURE; - - nsCOMPtr server; - rv = nsLocalURI2Server(uriStr, getter_AddRefs(server)); - - if (NS_FAILED(rv)) - return rv; - - return server->GetUsername(userName); -} diff --git a/mailnews/local/src/nsLocalUtils.h b/mailnews/local/src/nsLocalUtils.h index 984d9d383fa6..b92ba83e98cd 100644 --- a/mailnews/local/src/nsLocalUtils.h +++ b/mailnews/local/src/nsLocalUtils.h @@ -38,10 +38,4 @@ nsParseLocalMessageURI(const char* uri, nsCString& folderURI, PRUint32 *key); nsresult nsBuildLocalMessageURI(const char* baseURI, PRUint32 key, char** uri); -nsresult -nsGetMailboxHostName(const char *rootURI, const char *uriStr, char **hostName); - -nsresult -nsGetMailboxUserName(const char *rootURI, const char *uriStr, char **userName); - #endif //NS_LOCALUTILS_H diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index eb755466207f..08f3d0bea59a 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -470,9 +470,20 @@ nsresult nsNNTPProtocol::Initialize(nsIURI * aURL) rv = aURL->GetPreHost(getter_Copies(m_userName)); if (NS_FAILED(rv)) return rv; - nsCOMPtr server; - - rv = nsGetNewsServer((const char *)m_userName, (const char *)m_hostName, getter_AddRefs(server)); + // retrieve the AccountManager + NS_WITH_SERVICE(nsIMsgMailSession, session, kCMsgMailSessionCID, &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr accountManager; + rv = session->GetAccountManager(getter_AddRefs(accountManager)); + if (NS_FAILED(rv)) return rv; + + // find the news host + nsCOMPtr server; + rv = accountManager->FindServer(m_userName, + m_hostName, + "nntp", + getter_AddRefs(server)); + if (NS_SUCCEEDED(rv) && server) { nsCOMPtr nntpServer = do_QueryInterface(server, &rv); if (NS_SUCCEEDED(rv) && nntpServer) { diff --git a/mailnews/news/src/nsNewsFolder.cpp b/mailnews/news/src/nsNewsFolder.cpp index ed44efe49ede..9aa4b189e87f 100644 --- a/mailnews/news/src/nsNewsFolder.cpp +++ b/mailnews/news/src/nsNewsFolder.cpp @@ -75,7 +75,7 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); nsMsgNewsFolder::nsMsgNewsFolder(void) : nsMsgLineBuffer(nsnull, PR_FALSE), mPath(nsnull), mExpungedBytes(0), mGettingNews(PR_FALSE), - mInitialized(PR_FALSE), mOptionLines(nsnull), mHostname(nsnull) + mInitialized(PR_FALSE), mOptionLines(nsnull) { /* we're parsing the newsrc file, and the line breaks are platform specific. * if MSG_LINEBREAK != CRLF, then we aren't looking for CRLF @@ -93,12 +93,6 @@ nsMsgNewsFolder::~nsMsgNewsFolder(void) mPath = nsnull; } - // mHostname allocated in nsGetNewsHostName() with new char[] - if (mHostname) { - delete [] mHostname; - mHostname = nsnull; - } - PR_FREEIF(mOptionLines); mOptionLines = nsnull; } @@ -813,33 +807,6 @@ NS_IMETHODIMP nsMsgNewsFolder::GetSizeOnDisk(PRUint32 *size) return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsMsgNewsFolder::GetUsername(char** userName) -{ - return nsGetNewsUsername(kNewsRootURI, mURI, userName); -} - -NS_IMETHODIMP nsMsgNewsFolder::GetHostname(char** hostName) -{ - nsresult rv = NS_OK; - - if (!mHostname) { - // mHostname gets freed in the destructor - rv = nsGetNewsHostName(kNewsRootURI, mURI, &mHostname); - if (NS_FAILED(rv)) return rv; - } - - if (mHostname) { - *hostName = PL_strdup(mHostname); - if(!*hostName) - return NS_ERROR_OUT_OF_MEMORY; - } - else { - return NS_ERROR_FAILURE; - } - - return rv; -} - NS_IMETHODIMP nsMsgNewsFolder::UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate) { return NS_OK; diff --git a/mailnews/news/src/nsNewsFolder.h b/mailnews/news/src/nsNewsFolder.h index 5e8f67cdaad9..b6a9bd6cef30 100644 --- a/mailnews/news/src/nsNewsFolder.h +++ b/mailnews/news/src/nsNewsFolder.h @@ -79,8 +79,6 @@ public: NS_IMETHOD GetSizeOnDisk(PRUint32 *size); - NS_IMETHOD GetUsername(char** userName); - NS_IMETHOD GetHostname(char** hostName); NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *authenticate); NS_IMETHOD RememberPassword(const char *password); NS_IMETHOD GetRememberedPassword(char ** password); @@ -122,8 +120,7 @@ protected: PRBool mInitialized; nsISupportsArray *mMessages; char *mOptionLines; - char *mHostname; - + // cache this until we open the db. nsCString m_unreadSet; diff --git a/mailnews/news/src/nsNewsUtils.cpp b/mailnews/news/src/nsNewsUtils.cpp index 555ab510ba49..8ffbc6859e9f 100644 --- a/mailnews/news/src/nsNewsUtils.cpp +++ b/mailnews/news/src/nsNewsUtils.cpp @@ -34,7 +34,7 @@ static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID); -nsresult +static nsresult nsGetNewsServer(const char* username, const char *hostname, nsIMsgIncomingServer** aResult) { @@ -64,65 +64,6 @@ nsGetNewsServer(const char* username, const char *hostname, 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 *atPos = PL_strchr(curPos, '@'); - if (atPos) curPos = atPos+1; - - 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 -nsGetNewsUsername(const char *rootURI, const char *uriStr, char **userName) -{ - const char *curPos = uriStr; - while (*curPos != ':') curPos++; - curPos++; - while (*curPos == '/') curPos++; - - char *atPos = PL_strchr(curPos, '@'); - - if (atPos) { - *userName = PL_strndup(curPos, (atPos - curPos)); - } else { - *userName = PL_strdup(""); - } - - return NS_OK; -} nsresult nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult) diff --git a/mailnews/news/src/nsNewsUtils.h b/mailnews/news/src/nsNewsUtils.h index e7069f257017..6c4af4e42d7c 100644 --- a/mailnews/news/src/nsNewsUtils.h +++ b/mailnews/news/src/nsNewsUtils.h @@ -29,15 +29,6 @@ static const char kNewsMessageRootURI[] = "news_message:/"; #define kNewsRootURILen 6 #define kNewsMessageRootURILen 14 -extern nsresult -nsGetNewsServer(const char* username, const char *hostname, nsIMsgIncomingServer** aResult); - -extern nsresult -nsGetNewsHostName(const char *rootURI, const char *uriStr, char **hostName); - -extern nsresult -nsGetNewsUsername(const char *rootURI, const char *uriStr, char **userName); - extern nsresult nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult);