mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
work for 290057 integrating with Spotlight - this allows us to open spotlight search results in TB, sr=mscott
This commit is contained in:
parent
6fcb4bf108
commit
488569cbfc
@ -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
|
||||
}
|
||||
|
@ -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://<folder path>.mozmsgs/<message-id>.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<nsIRDFService> rdf(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIRDFResource> res;
|
||||
rv = rdf->GetResource(folderUri, getter_AddRefs(res));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIMsgFolder> 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 <nsIMsgDatabase> msgDB;
|
||||
containingFolder->GetMsgDatabase(nsnull, getter_AddRefs(msgDB));
|
||||
nsCOMPtr<nsIMsgDBHdr> 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<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
|
@ -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<nsIMsgAccountManager> accountManager =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsISupportsArray> 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<count; i++)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(serverArray, i);
|
||||
|
||||
if (!server) continue;
|
||||
|
||||
// get the path string, convert it to an nsFilePath
|
||||
nsCOMPtr<nsIFileSpec> 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<nsIMsgAccountManager> accountManager =
|
||||
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> 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<count; i++) {
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(serverArray, i);
|
||||
|
||||
if (!server) continue;
|
||||
|
||||
// get the path string, convert it to an nsFilePath
|
||||
nsCOMPtr<nsIFileSpec> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user