From 0958a14458ae6dc64072bbbd07ee12debdbb5183 Mon Sep 17 00:00:00 2001 From: "putterman%netscape.com" Date: Sat, 24 Apr 1999 20:36:00 +0000 Subject: [PATCH] Removed protocol dependent uri utilities. git-svn-id: svn://10.0.0.236/trunk@29071 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/base/public/msgCore.h | 44 +- mozilla/mailnews/base/util/nsMsgFolder.cpp | 466 --------------------- 2 files changed, 1 insertion(+), 509 deletions(-) diff --git a/mozilla/mailnews/base/public/msgCore.h b/mozilla/mailnews/base/public/msgCore.h index 9586dcd992d..5a3db875faa 100644 --- a/mozilla/mailnews/base/public/msgCore.h +++ b/mozilla/mailnews/base/public/msgCore.h @@ -126,53 +126,11 @@ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MAILNEWS, value) #endif /* XP_MAC */ //////////////////////////////////////////////////////////////////////////////// -// URI Utilities for RDF - -static const char kMailboxRootURI[] = "mailbox:/"; -static const char kMailboxMessageRootURI[] = "mailbox_message:/"; - -static const char kNewsRootURI[] = "news:/"; -static const char kNewsMessageRootURI[] = "news_message:/"; - -static const char kImapRootURI[] = "imap:/"; -static const char kImapMessageRootURI[] = "imap_message:/"; - -extern nsresult -nsGetMailboxRoot(nsFileSpec &result); - -extern nsresult -nsGetNewsRoot(nsFileSpec &result); - -extern nsresult -nsGetImapRoot(nsFileSpec &result); +// Utilities extern nsresult nsGetMailFolderSeparator(nsString& result); -extern nsresult -nsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult); - -extern nsresult -nsPath2URI(const char* rootURI, const nsFileSpec& path, char* *uri); - -extern nsresult -nsURI2Name(const char* rootURI, char* uriStr, nsString& name); - -extern nsresult -nsParseMessageURI(const char* uri, nsString& folderURI, PRUint32 *key); - -extern nsresult -nsBuildLocalMessageURI(const nsFileSpec& path, PRUint32 key, char** uri); - -extern nsresult -nsBuildNewsMessageURI(const nsFileSpec& path, PRUint32 key, char **uri); - -extern nsresult -nsBuildImapMessageURI(const nsFileSpec& path, PRUint32 key, char **uri); - -extern nsresult -nsGetFolderFromMessage(nsIMessage *message, nsIMsgFolder** folder); - //////////////////////////////////////////////////////////////////////////////// #endif diff --git a/mozilla/mailnews/base/util/nsMsgFolder.cpp b/mozilla/mailnews/base/util/nsMsgFolder.cpp index 232044a0296..7fbfe1ea23b 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgFolder.cpp @@ -31,17 +31,6 @@ #include "nsRDFCID.h" #include "nsXPIDLString.h" -// stuff for temporary root folder hack -#include "nsIMsgMailSession.h" -#include "nsIMsgIncomingServer.h" -#include "nsIPop3IncomingServer.h" -#include "nsINntpIncomingServer.h" - -#ifdef DEBUG_jefft -#include "nsIImapIncomingServer.h" -#endif - -static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); @@ -1479,129 +1468,9 @@ nsresult nsMsgFolder::NotifyItemDeleted(nsISupports *item) } -//////////////////////////////////////////////////////////////////////////////// -// URI Utilities for RDF - -#include "prprf.h" -#include "prsystem.h" - -static char *gMailboxRoot = nsnull; -static char *gNewsRoot = nsnull; -static char *gImapRoot = nsnull; nsresult -nsGetNewsRoot(nsFileSpec &result) -{ - nsresult rv = NS_OK; - if (gNewsRoot == nsnull) { - nsIMsgMailSession *session; - rv = nsServiceManager::GetService(kMsgMailSessionCID, - nsIMsgMailSession::GetIID(), - (nsISupports **)&session); - - if (NS_SUCCEEDED(rv)) { - nsIMsgIncomingServer *server; - rv = session->GetCurrentServer(&server); - if (NS_FAILED(rv)) printf("nsGetNewsRoot: Couldn't get current server\n"); - if (NS_SUCCEEDED(rv)) { - nsINntpIncomingServer *nntpServer; - rv = server->QueryInterface(nsINntpIncomingServer::GetIID(), - (void **)&nntpServer); - if (NS_FAILED(rv)) printf("nsGetNewsRoot: Couldn't get nntp server\n"); - if (NS_SUCCEEDED(rv)) { - rv = nntpServer->GetRootFolderPath(&gNewsRoot); - if (NS_FAILED(rv)) printf("nsGetNewsRoot: Couldn't get root\n"); - NS_RELEASE(nntpServer); - } - NS_RELEASE(server); - - } - nsServiceManager::ReleaseService(kMsgMailSessionCID, session); - } - } /* if (gNewsRoot == nsnull) .. */ - result = gNewsRoot; - return rv; -} - -nsresult -nsGetImapRoot(nsFileSpec &result) -{ - nsresult rv = NS_OK; - - // temporary stuff. for now - should get everything from the mail session - if (gImapRoot == nsnull) { -#ifdef DEBUG_jefft - nsIMsgMailSession *session; - rv = nsServiceManager::GetService(kMsgMailSessionCID, - nsIMsgMailSession::GetIID(), - (nsISupports **)&session); - - if (NS_SUCCEEDED(rv)) { - nsIMsgIncomingServer *server; - rv = session->GetCurrentServer(&server); - if (NS_FAILED(rv)) printf("nsGetImapRoot: Couldn't get current server\n"); - if (NS_SUCCEEDED(rv)) { - nsIImapIncomingServer *imapServer; - rv = server->QueryInterface(nsIImapIncomingServer::GetIID(), - (void **)&imapServer); - if (NS_FAILED(rv)) printf("nsGetImapRoot: Couldn't get imap server\n"); - if (NS_SUCCEEDED(rv)) { - rv = imapServer->GetRootFolderPath(&gImapRoot); - if (NS_FAILED(rv)) printf("nsGetImapRoot: Couldn't get root\n"); - NS_RELEASE(imapServer); - } - NS_RELEASE(server); - - } - nsServiceManager::ReleaseService(kMsgMailSessionCID, session); - } -#else - gImapRoot = PL_strdup("/tmp/"); -#endif - } - result = gImapRoot; - return rv; - -} - -nsresult -nsGetMailboxRoot(nsFileSpec &result) -{ - nsresult rv = NS_OK; - - // temporary stuff. for now get everything from the mail session - if (gMailboxRoot == nsnull) { - nsIMsgMailSession *session; - rv = nsServiceManager::GetService(kMsgMailSessionCID, - nsIMsgMailSession::GetIID(), - (nsISupports **)&session); - - if (NS_SUCCEEDED(rv)) { - nsIMsgIncomingServer *server; - rv = session->GetCurrentServer(&server); - if (NS_FAILED(rv)) printf("nsGetMailboxRoot: Couldn't get current server\n"); - if (NS_SUCCEEDED(rv)) { - nsIPop3IncomingServer *popServer; - rv = server->QueryInterface(nsIPop3IncomingServer::GetIID(), - (void **)&popServer); - if (NS_FAILED(rv)) printf("nsGetMailboxRoot: Couldn't get pop3 server\n"); - if (NS_SUCCEEDED(rv)) { - rv = popServer->GetRootFolderPath(&gMailboxRoot); - if (NS_FAILED(rv)) printf("nsGetMailboxRoot: Couldn't get root\n"); - NS_RELEASE(popServer); - } - NS_RELEASE(server); - - } - nsServiceManager::ReleaseService(kMsgMailSessionCID, session); - } - } /* if (gMailboxRoot == nsnull) .. */ - result = gMailboxRoot; - return rv; -} - -nsresult nsGetMailFolderSeparator(nsString& result) { static char* gMailFolderSep = nsnull; // never freed @@ -1615,338 +1484,3 @@ nsGetMailFolderSeparator(nsString& result) return NS_OK; } -nsresult -nsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult) -{ - nsresult rv; - -#ifdef DEBUG_sspitzer - /* examples: */ - /* nsURI2Path(mailbox:/, mailbox:/, ??)->/home/sspitzer/mozillamail */ - /* nsURI2Path(mailbox:/, mailbox://Drafts, ??)->/home/sspitzer/mozillamail/Drafts */ - /* nsURI2Path(news:/, news:/, ??)->/home/sspitzer/mozillanews */ - printf("nsURI2Path(%s, %s, ??)", rootURI, uriStr); -#endif - - nsAutoString sep; - sep += PR_GetDirectorySeparator(); - - nsAutoString sbdSep; - /* sspitzer: is this ok for mail and news? */ - rv = nsGetMailFolderSeparator(sbdSep); - if (NS_FAILED(rv)) return rv; - - nsAutoString uri = uriStr; - if (uri.Find(rootURI) != 0) // if doesn't start with rootURI - return NS_ERROR_FAILURE; - - /* sspitzer: yes, this is inefficent. it may be going away - * if not, I'll make it more efficient later. */ - if ((strcmp(rootURI, kMailboxRootURI) == 0) || - (strcmp(rootURI, kMailboxMessageRootURI) == 0)) { - // local mail case - rv = nsGetMailboxRoot(pathResult); - } - else if ((strcmp(rootURI, kNewsMessageRootURI) == 0) || - (strcmp(rootURI, kNewsRootURI) == 0)) { - // news case - rv = nsGetNewsRoot(pathResult); - } - else if ((strcmp(rootURI, kImapMessageRootURI) == 0) || - (strcmp(rootURI, kImapRootURI) == 0)) { - rv = nsGetImapRoot(pathResult); - } - else { - rv = NS_ERROR_FAILURE; - } - - if (NS_FAILED(rv)) { - pathResult = nsnull; - return rv; - } - - nsAutoString path=""; - uri.Cut(0, nsCRT::strlen(rootURI)); - - PRInt32 uriLen = uri.Length(); - PRInt32 pos; - while(uriLen > 0) { - nsAutoString folderName; - - PRInt32 leadingPos; - // if it's the first character then remove it. - while ((leadingPos = uri.Find('/')) == 0) { - uri.Cut(0, 1); - uriLen--; - } - - if (uriLen == 0) - break; - - pos = uri.Find('/'); - if (pos < 0) - pos = uriLen; - - - PRInt32 leftRes = uri.Left(folderName, pos); - - NS_ASSERTION(leftRes == pos, - "something wrong with nsString"); - //We only want to add this after the first time around. - if(path.Length() > 0) - { - path += sep; - path += PR_GetDirectorySeparator(); - } - // the first time around the separator is special because - // the root mail folder doesn't end with .sbd - sep = sbdSep; - - path += folderName; - uri.Cut(0, pos); - uriLen -= pos; - } - - if(path.Length() > 0) - pathResult +=path; - -#ifdef DEBUG_sspitzer - printf("->%s\n", (const char *)pathResult); -#endif - return NS_OK; -} - -nsresult -nsPath2URI(const char* rootURI, const nsFileSpec& spec, char **uri) -{ - nsresult rv; - -#ifdef DEBUG_sspitzer - /* examples: */ - /* nsPath2URI(mailbox_message:/, /home/sspitzer/mozillamail/Drafts, ??)->mailbox_message://Drafts */ - /* nsPath2URI(news_message:/, /tmp/mozillanews/news.mozilla.org/netscape.public.mozilla.unix, ??)->news_message://news.mozilla.org/netscape.public.mozilla.unix */ - printf("nsPath2URI(%s, %s, ??)", rootURI, (const char *)spec); -#endif - - nsAutoString sep; - /* sspitzer: is this ok for mail and news? */ - rv = nsGetMailFolderSeparator(sep); - if (NS_FAILED(rv)) return rv; - - PRUint32 sepLen = sep.Length(); - - nsFileSpec root; - if (strcmp(rootURI, kNewsMessageRootURI) == 0) { - rv = nsGetNewsRoot(root); - } - else if (strcmp(rootURI, kImapMessageRootURI) == 0) { - rv = nsGetImapRoot(root); - } - else { - // local mail case - rv = nsGetMailboxRoot(root); - } - if (NS_FAILED(rv)) return rv; - - const char *path = spec; - nsAutoString pathStr(path); - path = root; - nsAutoString rootStr(path); - - PRInt32 pos = pathStr.Find(rootStr); - if (pos != 0) // if doesn't start with root path - return NS_ERROR_FAILURE; - - nsAutoString uriStr(rootURI); - - PRUint32 rootStrLen = rootStr.Length(); - pathStr.Cut(0, rootStrLen); - PRInt32 pathStrLen = pathStr.Length(); - - char dirSep = PR_GetDirectorySeparator(); - - while (pathStrLen > 0) { - nsAutoString folderName; - - PRInt32 leadingPos; - // if it's the first character then remove it. - while ((leadingPos = pathStr.Find(dirSep)) == 0) { - pathStr.Cut(0, 1); - pathStrLen--; - } - if (pathStrLen == 0) - break; - - pos = pathStr.Find(sep); - if (pos < 0) - pos = pathStrLen; - - PRInt32 leftRes = pathStr.Left(folderName, pos); - NS_ASSERTION(leftRes == pos, - "something wrong with nsString"); - - pathStr.Cut(0, pos + sepLen); - pathStrLen -= pos + sepLen; - - uriStr += '/'; - uriStr += folderName; - } - *uri = uriStr.ToNewCString(); -#ifdef DEBUG_sspitzer - printf("->%s\n", *uri); -#endif - return NS_OK; -} - -nsresult -nsURI2Name(const char* rootURI, char* uriStr, nsString& name) -{ - nsAutoString uri = uriStr; - if (uri.Find(rootURI) != 0) // if doesn't start with rootURI - return NS_ERROR_FAILURE; - PRInt32 pos = uri.RFind("/"); - PRInt32 length = uri.Length(); - PRInt32 count = length - (pos + 1); - return uri.Right(name, count); -} - -/* parses LocalMessageURI, NewsMessageURI, and ImapMessageURI */ -nsresult nsParseMessageURI(const char* uri, nsString& folderURI, PRUint32 *key) -{ - if(!key) - return NS_ERROR_NULL_POINTER; - - nsAutoString uriStr = uri; - PRInt32 keySeparator = uriStr.Find('#'); - if(keySeparator != -1) - { - nsAutoString folderPath; - uriStr.Left(folderURI, keySeparator); - - nsAutoString keyStr; - uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1)); - PRInt32 errorCode; - *key = keyStr.ToInteger(&errorCode); - - return errorCode; - } - return NS_ERROR_FAILURE; - -} - -nsresult nsBuildLocalMessageURI(const nsFileSpec& path, PRUint32 key, char** uri) -{ - - if(!uri) - return NS_ERROR_NULL_POINTER; - - char *folderURI; - - nsPath2URI(kMailboxMessageRootURI, path, &folderURI); - - *uri = PR_smprintf("%s#%d", folderURI, key); - - delete[] folderURI; - - return NS_OK; - - -} - -nsresult nsBuildNewsMessageURI(const nsFileSpec& path, PRUint32 key, char** uri) -{ - - if(!uri) - return NS_ERROR_NULL_POINTER; - - char *folderURI; - - nsPath2URI(kNewsMessageRootURI, path, &folderURI); - - *uri = PR_smprintf("%s#%d", folderURI, key); - - delete[] folderURI; - - return NS_OK; - - -} - -nsresult nsBuildImapMessageURI(const nsFileSpec& path, PRUint32 key, char** uri) -{ - - if(!uri) - return NS_ERROR_NULL_POINTER; - - char *folderURI = nsnull; - - nsPath2URI(kImapMessageRootURI, path, &folderURI); - - *uri = PR_smprintf("%s#%d", folderURI, key); - - delete[] folderURI; - - return NS_OK; - - -} - -nsresult nsGetFolderFromMessage(nsIMessage *message, nsIMsgFolder** folder) -{ - nsresult rv; - - nsXPIDLCString uri; - nsIRDFResource *resource; - if(NS_SUCCEEDED( rv = message->QueryInterface(nsIRDFResource::GetIID(), (void**)&resource))) - { - resource->GetValue( getter_Copies(uri) ); - nsString messageFolderURIStr; - nsMsgKey key; - nsParseMessageURI(uri, messageFolderURIStr, &key); - nsString folderOnly, folderURIStr; - - if (messageFolderURIStr.Find(kMailboxMessageRootURI) != ((PRInt32)-1)) - { - messageFolderURIStr.Right(folderOnly, messageFolderURIStr.Length() -nsCRT::strlen(kMailboxMessageRootURI)); - folderURIStr = kMailboxRootURI; - folderURIStr+= folderOnly; - } - else if (messageFolderURIStr.Find(kNewsMessageRootURI) != ((PRInt32)-1)) - { - messageFolderURIStr.Right(folderOnly, messageFolderURIStr.Length() -nsCRT::strlen(kNewsMessageRootURI)); - folderURIStr = kMailboxRootURI; - folderURIStr+= folderOnly; - } - else if (messageFolderURIStr.Find(kImapMessageRootURI) != ((PRInt32)-1)) - { - messageFolderURIStr.Right(folderOnly, messageFolderURIStr.Length() -nsCRT::strlen(kImapMessageRootURI)); - folderURIStr = kMailboxRootURI; - folderURIStr+= folderOnly; - } - - nsIRDFResource *folderResource; - char *folderURI = folderURIStr.ToNewCString(); - - - nsIRDFService* rdfService; - nsresult rv = nsServiceManager::GetService(kRDFServiceCID, - nsIRDFService::GetIID(), - (nsISupports**) &rdfService); - if(NS_SUCCEEDED(rv)) - { - rdfService->GetResource(folderURI, &folderResource); - nsServiceManager::ReleaseService(kRDFServiceCID, rdfService); - } - - delete[] folderURI; - - rv = NS_SUCCEEDED(folderResource->QueryInterface(nsIMsgFolder::GetIID(), (void**)folder)); - - NS_RELEASE(resource); - NS_RELEASE(folderResource); - } - return rv; - -} - -////////////////////////////////////////////////////////////////////////////////