From 488569cbfc4cd94873b146e0cac2571376568bf2 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Sun, 26 Nov 2006 19:55:57 +0000 Subject: [PATCH] work for 290057 integrating with Spotlight - this allows us to open spotlight search results in TB, sr=mscott --- mailnews/base/src/nsMessenger.cpp | 2 +- mailnews/base/src/nsMessengerBootstrap.cpp | 53 ++++++++++++++++- mailnews/base/util/nsMsgUtils.cpp | 67 +++++++++++++++++++++ mailnews/base/util/nsMsgUtils.h | 2 + mailnews/local/src/nsMailboxUrl.cpp | 69 ++-------------------- 5 files changed, 126 insertions(+), 67 deletions(-) diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index eef0688d6a51..bb67dda9d885 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -2816,7 +2816,7 @@ nsresult nsDelAttachListener::DeleteOriginalMessage() messageArray, // messages mMsgWindow, // msgWindow PR_TRUE, // deleteStorage - PR_TRUE, // isMove + PR_FALSE, // isMove listenerCopyService, // listener PR_FALSE); // allowUndo } diff --git a/mailnews/base/src/nsMessengerBootstrap.cpp b/mailnews/base/src/nsMessengerBootstrap.cpp index e8cddae59702..f98694dd7ded 100644 --- a/mailnews/base/src/nsMessengerBootstrap.cpp +++ b/mailnews/base/src/nsMessengerBootstrap.cpp @@ -56,12 +56,18 @@ #include "nsIURI.h" #include "nsIDialogParamBlock.h" #include "nsUnicharUtils.h" + #ifdef MOZ_XUL_APP #include "nsICommandLine.h" #include "nsILocalFile.h" #include "nsNetUtil.h" #include "nsIFileURL.h" -#endif +#include "nsNativeCharsetUtils.h" +#include "nsIRDFResource.h" +#include "nsIRDFService.h" +#include "nsIMsgHdr.h" +#include "nsMsgUtils.h" +#endif // MOZ_XUL_APP NS_IMPL_THREADSAFE_ADDREF(nsMessengerBootstrap) NS_IMPL_THREADSAFE_RELEASE(nsMessengerBootstrap) @@ -134,6 +140,51 @@ nsMessengerBootstrap::Handle(nsICommandLine* aCmdLine) { nsAutoString arg; aCmdLine->GetArgument(0, arg); +#ifdef XP_MACOSX + if (StringEndsWith(arg, NS_LITERAL_STRING(".mozeml"), nsCaseInsensitiveStringComparator())) + { + // parse file name - get path to containing folder, and message-id of message we're looking for + // Then, open that message (in a 3-pane window?) + // We're going to have a native path file url: + // file://.mozmsgs/.mozeml + PRInt32 mozmsgsIndex = arg.Find(NS_LITERAL_STRING(".mozmsgs")); + // take off the file:// part + nsString folderPath; + arg.Left(folderPath, mozmsgsIndex); + // need to convert to 8 bit chars...i.e., a local path. + nsCAutoString nativeArg; + NS_CopyUnicodeToNative(folderPath, nativeArg); + nsCString folderUri; + rv = MsgMailboxGetURI(nativeArg.get(), folderUri); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr rdf(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr res; + rv = rdf->GetResource(folderUri, getter_AddRefs(res)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr containingFolder; + containingFolder = do_QueryInterface(res, &rv); + NS_ENSURE_SUCCESS(rv, rv); + // once we have the folder uri, open the db and search for the message id. + nsAutoString unicodeMessageid; + // strip off .mozeml at the end as well + arg.Mid(unicodeMessageid, mozmsgsIndex + 9, arg.Length() - (mozmsgsIndex + 9 + 7)); + nsCAutoString messageId; + NS_CopyUnicodeToNative(unicodeMessageid, messageId); + nsCOMPtr msgDB; + containingFolder->GetMsgDatabase(nsnull, getter_AddRefs(msgDB)); + nsCOMPtr msgHdr; + if (msgDB) + msgDB->GetMsgHdrForMessageID(messageId.get(), getter_AddRefs(msgHdr)); + if (msgHdr) + { + nsMsgKey msgKey; + msgHdr->GetMessageKey(&msgKey); + rv = OpenMessengerWindowWithUri("mail:3pane", folderUri.get(), msgKey); + return rv; + } + } +#endif if (StringEndsWith(arg, NS_LITERAL_STRING(".eml"), nsCaseInsensitiveStringComparator())) { nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); diff --git a/mailnews/base/util/nsMsgUtils.cpp b/mailnews/base/util/nsMsgUtils.cpp index a3170f30fa75..e1faccc56763 100644 --- a/mailnews/base/util/nsMsgUtils.cpp +++ b/mailnews/base/util/nsMsgUtils.cpp @@ -76,6 +76,7 @@ #include "nsIRssIncomingServer.h" #include "nsIMsgFolder.h" #include "nsIMsgMessageService.h" +#include "nsIMsgAccountManager.h" #include "nsIOutputStream.h" static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID); @@ -1382,3 +1383,69 @@ PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains) } while (*end); return domainIsTrusted; } + +nsresult MsgMailboxGetURI(const char *nativepath, nsCString &mailboxUri) +{ + + nsresult rv; + + nsCOMPtr accountManager = + do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); + + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr serverArray; + accountManager->GetAllServers(getter_AddRefs(serverArray)); + + // do a char*->fileSpec->char* conversion to normalize the path + nsFilePath filePath(nativepath); + + PRUint32 cnt; + rv = serverArray->Count(&cnt); + NS_ENSURE_SUCCESS(rv, rv); + PRInt32 count = cnt; + PRInt32 i; + for (i=0; i server = do_QueryElementAt(serverArray, i); + + if (!server) continue; + + // get the path string, convert it to an nsFilePath + nsCOMPtr nativeServerPath; + rv = server->GetLocalPath(getter_AddRefs(nativeServerPath)); + if (NS_FAILED(rv)) continue; + + nsFileSpec spec; + nativeServerPath->GetFileSpec(&spec); + nsFilePath serverPath(spec); + + // check if filepath begins with serverPath + PRInt32 len = PL_strlen(serverPath); + if (PL_strncasecmp(serverPath, filePath, len) == 0) + { + nsXPIDLCString serverURI; + rv = server->GetServerURI(getter_Copies(serverURI)); + if (NS_FAILED(rv)) continue; + + // the relpath is just past the serverpath + const char *relpath = nativepath + len; + // skip past leading / if any + while (*relpath == '/') + relpath++; + + nsCAutoString pathStr(relpath); + PRInt32 sbdIndex; + while((sbdIndex = pathStr.Find(".sbd", PR_TRUE)) != -1) + pathStr.Cut(sbdIndex, 4); + + mailboxUri = serverURI; + mailboxUri.Append('/'); + mailboxUri.Append(pathStr); + break; + } + } + return mailboxUri.IsEmpty() ? NS_ERROR_FAILURE : NS_OK; +} + + diff --git a/mailnews/base/util/nsMsgUtils.h b/mailnews/base/util/nsMsgUtils.h index 47338ff79440..3f379b0ecb99 100644 --- a/mailnews/base/util/nsMsgUtils.h +++ b/mailnews/base/util/nsMsgUtils.h @@ -192,5 +192,7 @@ NS_MSG_BASE PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keyword NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains); +NS_MSG_BASE nsresult MsgMailboxGetURI(const char *nativepath, nsCString &mailboxUri); + #endif diff --git a/mailnews/local/src/nsMailboxUrl.cpp b/mailnews/local/src/nsMailboxUrl.cpp index 1936634dc2f0..e4806362f491 100644 --- a/mailnews/local/src/nsMailboxUrl.cpp +++ b/mailnews/local/src/nsMailboxUrl.cpp @@ -70,68 +70,6 @@ static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID); #include "nsIMsgAccountManager.h" #include "nsMsgUtils.h" -static char *nsMailboxGetURI(const char *nativepath) -{ - - nsresult rv; - char *uri = nsnull; - - nsCOMPtr accountManager = - do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return nsnull; - - nsCOMPtr serverArray; - accountManager->GetAllServers(getter_AddRefs(serverArray)); - - // do a char*->fileSpec->char* conversion to normalize the path - nsFilePath filePath(nativepath); - - PRUint32 cnt; - rv = serverArray->Count(&cnt); - if (NS_FAILED(rv)) return nsnull; - PRInt32 count = cnt; - PRInt32 i; - for (i=0; i server = do_QueryElementAt(serverArray, i); - - if (!server) continue; - - // get the path string, convert it to an nsFilePath - nsCOMPtr nativeServerPath; - rv = server->GetLocalPath(getter_AddRefs(nativeServerPath)); - if (NS_FAILED(rv)) continue; - - nsFileSpec spec; - nativeServerPath->GetFileSpec(&spec); - nsFilePath serverPath(spec); - - // check if filepath begins with serverPath - PRInt32 len = PL_strlen(serverPath); - if (PL_strncasecmp(serverPath, filePath, len) == 0) { - nsXPIDLCString serverURI; - rv = server->GetServerURI(getter_Copies(serverURI)); - if (NS_FAILED(rv)) continue; - - // the relpath is just past the serverpath - const char *relpath = nativepath + len; - // skip past leading / if any - while (*relpath == '/') relpath++; - nsCAutoString pathStr(relpath); - PRInt32 sbdIndex; - while((sbdIndex = pathStr.Find(".sbd", PR_TRUE)) != -1) - { - pathStr.Cut(sbdIndex, 4); - } - - uri = PR_smprintf("%s/%s", (const char*)serverURI, pathStr.get()); - - break; - } - } - return uri; -} - // helper function for parsing the search field of a url char * extractAttributeValue(const char * searchString, const char * attributeName); @@ -252,14 +190,15 @@ NS_IMETHODIMP nsMailboxUrl::GetUri(char ** aURI) GetFileSpec(&filePath); if (filePath) { - char * baseuri = nsMailboxGetURI(m_file); + nsCAutoString baseUri; + nsresult rv = MsgMailboxGetURI(m_file, baseUri); + NS_ENSURE_SUCCESS(rv, rv); char * baseMessageURI; - nsCreateLocalBaseMessageURI(baseuri, &baseMessageURI); + nsCreateLocalBaseMessageURI(baseUri.get(), &baseMessageURI); char * uri = nsnull; nsCAutoString uriStr; nsFileSpec folder = *filePath; nsBuildLocalMessageURI(baseMessageURI, m_messageKey, uriStr); - PL_strfree(baseuri); nsCRT::free(baseMessageURI); uri = ToNewCString(uriStr); *aURI = uri;