diff --git a/mailnews/base/public/nsIMessenger.idl b/mailnews/base/public/nsIMessenger.idl index 382ac2140b8..5940ffbb2a1 100644 --- a/mailnews/base/public/nsIMessenger.idl +++ b/mailnews/base/public/nsIMessenger.idl @@ -79,7 +79,7 @@ interface nsIMessenger : nsISupports { void SendUnsentMessages(in nsIMsgIdentity aIdentity); void SetDocumentCharset(in wstring characterSet); void saveAs(in string url, in boolean asFile, in nsIMsgIdentity identity, in nsIMsgWindow aMsgWindow); - void openAttachment(in string url, in string displayName, in string messageUri); + void openAttachment(in string contentTpe, in string url, in string displayName, in string messageUri); void saveAttachment(in string url, in string displayName, in string messageUri); void saveAllAttachments(in unsigned long count, [array, size_is(count)] in string urlArray, [array, size_is(count)] in string displayNameArray, [array, size_is(count)] in string messageUriArray); void find(); diff --git a/mailnews/base/resources/content/msgHdrViewOverlay.js b/mailnews/base/resources/content/msgHdrViewOverlay.js index 2f0b6ce9e7e..b966f59fd1e 100644 --- a/mailnews/base/resources/content/msgHdrViewOverlay.js +++ b/mailnews/base/resources/content/msgHdrViewOverlay.js @@ -153,11 +153,11 @@ var messageHeaderSink = { }, - handleAttachment: function(url, displayName, uri, notDownloaded) + handleAttachment: function(contentType, url, displayName, uri, notDownloaded) { // be sure to escape the display name before we insert it into the // method - var commandString = "OpenAttachURL('" + url + "', '" + escape(displayName) + "', '" + uri + "')"; + var commandString = "OpenAttachURL('" + contentType + "', '" + url + "', '" + escape(displayName) + "', '" + uri + "')"; if (notDownloaded) { displayName += " " + Bundle.GetStringFromName("notDownloaded"); @@ -209,14 +209,14 @@ function AddSenderToAddressBook() } } -function OpenAttachURL(url, displayName, messageUri) +function OpenAttachURL(contentType, url, displayName, messageUri) { var args = {dspname: displayName, opval: 0}; window.openDialog("chrome://messenger/content/openSaveAttachment.xul", "openSaveAttachment", "chrome,modal", args); if (args.opval == 1) - messenger.openAttachment(url, displayName, messageUri); + messenger.openAttachment(contentType, url, displayName, messageUri); else if (args.opval == 2) messenger.saveAttachment(url, displayName, messageUri); } diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 4b2bbae3396..282e93f6d48 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -575,96 +575,16 @@ done: } NS_IMETHODIMP -nsMessenger::OpenAttachment(const char * url, const char * displayName, - const char * messageUri) +nsMessenger::OpenAttachment(const char * contentType, const char * url, const + char * displayName, const char * messageUri) { - nsIMsgMessageService * messageService = nsnull; - nsAutoString from, to; - nsCOMPtr channelSupport; - nsCOMPtr convertedListener; - nsAutoString urlString; - char *urlCString = nsnull; - char *unescapedUrl = nsnull; - nsCOMPtr aURL; - PRBool canFetchMimeParts = PR_FALSE; - nsCAutoString fullMessageUri = messageUri; - nsresult rv = NS_ERROR_NULL_POINTER; - nsCOMPtr channel; - - NS_WITH_SERVICE(nsIStreamConverterService, - streamConverterService, - kIStreamConverterServiceCID, &rv); - if (NS_FAILED(rv)) goto done; - - if (!url) return NS_ERROR_NULL_POINTER; - - unescapedUrl = PL_strdup(url); - if (!unescapedUrl) return NS_ERROR_OUT_OF_MEMORY; - - nsUnescape(unescapedUrl); - - urlString.AssignWithConversion(unescapedUrl); - - urlString.ReplaceSubstring(NS_ConvertASCIItoUCS2("/;section"), NS_ConvertASCIItoUCS2("?section")); - urlCString = urlString.ToNewCString(); - - rv = CreateStartupUrl(urlCString, getter_AddRefs(aURL)); - nsCRT::free(urlCString); - - if (NS_FAILED(rv)) goto done; - - rv = GetMessageServiceFromURI(messageUri, &messageService); - if (NS_FAILED(rv)) goto done; - - messageService->GetCanFetchMimeParts(&canFetchMimeParts); - - if (canFetchMimeParts) - { - PRInt32 sectionPos = urlString.Find("?section"); - nsString mimePart; - - urlString.Right(mimePart, urlString.Length() - sectionPos); - fullMessageUri.AppendWithConversion(mimePart); - - messageUri = fullMessageUri.GetBuffer(); - } - { - rv = NS_NewInputStreamChannel(getter_AddRefs(channel), - aURL, - nsnull, // inputStream - nsnull, // contentType - -1); - if (NS_FAILED(rv)) goto done; - - from.AssignWithConversion(MESSAGE_RFC822); - to.AssignWithConversion("text/xul"); - - channelSupport = do_QueryInterface(channel); - - // *** this isn't working yet needs to come back for it - // *** We need to use the mime stream coverter to pull out the part stream - // *** and then pass it to the display consumer - rv = streamConverterService->AsyncConvertData( - from.GetUnicode(), to.GetUnicode(), nsnull, - channelSupport, getter_AddRefs(convertedListener)); - if (NS_FAILED(rv)) goto done; - - if (canFetchMimeParts) - rv = messageService->OpenAttachment(aURL, messageUri, convertedListener, - mMsgWindow, nsnull,nsnull); - else - rv = messageService->DisplayMessage(messageUri, - convertedListener,mMsgWindow, - nsnull, nsnull); - } - -done: - if (messageService) - ReleaseMessageServiceFromURI(unescapedUrl, messageService); - - PR_FREEIF(unescapedUrl); - - return rv; + nsCString partMsgUrl = messageUri; + partMsgUrl += "?"; + const char *part = PL_strstr(url, "part="); + partMsgUrl += part; + partMsgUrl += "&type="; + partMsgUrl += contentType; + return OpenURL(partMsgUrl.GetBuffer()); } NS_IMETHODIMP diff --git a/mailnews/base/util/nsMsgProtocol.cpp b/mailnews/base/util/nsMsgProtocol.cpp index 66f98b9395b..a22c9dc0060 100644 --- a/mailnews/base/util/nsMsgProtocol.cpp +++ b/mailnews/base/util/nsMsgProtocol.cpp @@ -199,7 +199,12 @@ NS_IMETHODIMP nsMsgProtocol::OnStartRequest(nsIChannel * aChannel, nsISupports * // so pass in ourself as the channel and not the underlying socket or file channel the protocol // happens to be using if (m_channelListener) + { + if (!m_channelContext) + m_channelContext = do_QueryInterface(ctxt); + rv = m_channelListener->OnStartRequest(this, m_channelContext); + } return rv; } diff --git a/mailnews/local/src/nsMailboxProtocol.cpp b/mailnews/local/src/nsMailboxProtocol.cpp index 6b18d204aea..8b81773a299 100644 --- a/mailnews/local/src/nsMailboxProtocol.cpp +++ b/mailnews/local/src/nsMailboxProtocol.cpp @@ -125,7 +125,6 @@ NS_IMETHODIMP nsMailboxProtocol::OnStartRequest(nsIChannel * aChannel, nsISuppor // extract the appropriate event sinks from the url and initialize them in our protocol data // the URL should be queried for a nsINewsURL. If it doesn't support a news URL interface then // we have an error. - if (m_nextState == MAILBOX_READ_FOLDER && m_mailboxParser) { // we need to inform our mailbox parser that it's time to start... diff --git a/mailnews/local/src/nsMailboxService.cpp b/mailnews/local/src/nsMailboxService.cpp index 123197db477..15635af34a7 100644 --- a/mailnews/local/src/nsMailboxService.cpp +++ b/mailnews/local/src/nsMailboxService.cpp @@ -37,7 +37,12 @@ #include "nsMsgBaseCID.h" #include "nsIDocShell.h" #include "nsIPop3Service.h" +#include "nsMsgUtils.h" +#include "nsIStreamConverterService.h" +#include "nsNetUtil.h" +static NS_DEFINE_CID(kIStreamConverterServiceCID, + NS_STREAMCONVERTERSERVICE_CID); static NS_DEFINE_CID(kCMailboxUrl, NS_MAILBOXURL_CID); static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID); static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID); @@ -153,7 +158,9 @@ nsresult nsMailboxService::DisplayMessage(const char* aMessageURI, nsIUrlListener * aUrlListener, nsIURI ** aURL) { - return FetchMessage(aMessageURI, aDisplayConsumer, aMsgWindow,aUrlListener, nsIMailboxUrl::ActionDisplayMessage, aURL); + return FetchMessage(aMessageURI, aDisplayConsumer, + aMsgWindow,aUrlListener, + nsIMailboxUrl::ActionDisplayMessage, aURL); } /* void OpenAttachment (in nsIURI aURI, in nsISupports aDisplayConsumer, in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener, out nsIURI aURL); */ @@ -265,6 +272,7 @@ nsresult nsMailboxService::PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsI nsCAutoString folderURI; nsFileSpec folderPath; nsMsgKey msgKey; + const char *part = PL_strstr(aSrcMsgMailboxURI, "part="); rv = nsParseLocalMessageURI(aSrcMsgMailboxURI, folderURI, &msgKey); rv = nsLocalURI2Path(kMailboxMessageRootURI, folderURI, folderPath); @@ -274,11 +282,14 @@ nsresult nsMailboxService::PrepareMessageUrl(const char * aSrcMsgMailboxURI, nsI // set up the url spec and initialize the url with it. nsFilePath filePath(folderPath); // convert to file url representation... - if (mPrintingOperation) - urlSpec = PR_smprintf("mailbox://%s?number=%d&header=print", (const char *) filePath, msgKey); - else - urlSpec = PR_smprintf("mailbox://%s?number=%d", (const char *) filePath, msgKey); - + if (mPrintingOperation) + urlSpec = PR_smprintf("mailbox://%s?number=%d&header=print", (const char *) filePath, msgKey); + else if (part) + urlSpec = PR_smprintf("mailbox://%s?number=%d&%s", (const char *) + filePath, msgKey, part); + else + urlSpec = PR_smprintf("mailbox://%s?number=%d", (const char *) filePath, msgKey); + nsCOMPtr url = do_QueryInterface(*aMailboxUrl); url->SetSpec(urlSpec); PR_FREEIF(urlSpec); diff --git a/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp b/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp index 91c1c6f2048..1733527aa6d 100644 --- a/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp +++ b/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp @@ -254,7 +254,7 @@ nsMimeHtmlDisplayEmitter::StartAttachment(const char *name, const char *contentT nsXPIDLString::Copy(attachmentName.GetUnicode()); } - headerSink->HandleAttachment(url /* was escapedUrl */, unicodeHeaderValue, uriString, aNotDownloaded); + headerSink->HandleAttachment(contentType, url /* was escapedUrl */, unicodeHeaderValue, uriString, aNotDownloaded); nsCRT::free(escapedUrl); mSkipAttachment = PR_TRUE; diff --git a/mailnews/mime/public/nsIMimeMiscStatus.idl b/mailnews/mime/public/nsIMimeMiscStatus.idl index 040c1fe31ce..66678b44e86 100644 --- a/mailnews/mime/public/nsIMimeMiscStatus.idl +++ b/mailnews/mime/public/nsIMimeMiscStatus.idl @@ -51,7 +51,7 @@ interface nsIMsgHeaderSink : nsISupports{ // make a sandwhich around header processing..... void onStartHeaders(); void onEndHeaders(); - void handleAttachment(in string url, in wstring displayName, in string + void handleAttachment(in string contentType, in string url, in wstring displayName, in string uri, in boolean aNotDownloaded); void onEndAllAttachments(); };