} return rv;
else { saveListener->m_outputFormat = nsSaveMsgListener::eHTML; saveListener->m_doCharsetConversion = PR_FALSE; urlString += NS_LITERAL_CSTRING("?header=saveas"); }  rv = CreateStartupUrl(urlString.get(), getter_AddRefs(url)); NS_ASSERTION(NS_SUCCEEDED(rv), "CreateStartupUrl failed"); if (NS_FAILED(rv)) goto done;  const nsAFlatCString& empty = EmptyCString();  saveListener->m_channel = nsnull; rv = NS_NewInputStreamChannel(getter_AddRefs(saveListener->m_channel), url, nsnull, empty, empty); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewInputStreamChannel failed"); if (NS_FAILED(rv)) goto done;  nsCOMPtr<nsIStreamConverterService> streamConverterService = do_GetService("@mozilla.org/streamConverters;1"); nsCOMPtr<nsISupports> channelSupport = do_QueryInterface(saveListener->m_channel);     rv = streamConverterService->AsyncConvertData(NS_LITERAL_STRING(MESSAGE_RFC822).get(), NS_LITERAL_STRING(TEXT_HTML).get(), saveListener, channelSupport, getter_AddRefs(convertedListener)); NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncConvertData failed"); if (NS_FAILED(rv)) goto done;  rv = messageService->DisplayMessage(urlString.get(), convertedListener, mMsgWindow, nsnull, nsnull, nsnull); } } else {  nsCOMPtr<nsIFileSpec> fileSpec; nsFileSpec tmpFileSpec("nsmail.tmp"); rv = NS_NewFileSpecWithSpec(tmpFileSpec, getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) goto done;    saveListener = new nsSaveMsgListener(fileSpec, this); if (!saveListener) { rv = NS_ERROR_OUT_OF_MEMORY; goto done; } NS_ADDREF(saveListener);  if (aIdentity) rv = aIdentity->GetStationeryFolder(getter_Copies(saveListener->m_templateUri)); if (NS_FAILED(rv)) goto done;  PRBool needDummyHeader = PL_strcasestr(saveListener->m_templateUri, "mailbox: != nsnull; PRBool canonicalLineEnding = PL_strcasestr(saveListener->m_templateUri, "imap: != nsnull;  rv = saveListener->QueryInterface( NS_GET_IID(nsIUrlListener), getter_AddRefs(urlListener)); if (NS_FAILED(rv)) goto done;  rv = messageService->SaveMessageToDisk(aURI, fileSpec, needDummyHeader, urlListener, nsnull, canonicalLineEnding, mMsgWindow); }  done: if (NS_FAILED(rv)) {   NS_IF_RELEASE(saveListener); Alert("saveMessageFailed"); } return rv;
nsMessenger::SaveAs(const char* url, PRBool asFile){	nsresult rv = NS_OK;        if (url)    {      nsIMsgMessageService* messageService = nsnull;      rv = GetMessageServiceFromURI(url, &messageService);      if (NS_SUCCEEDED(rv) && messageService)      {        nsCOMPtr<nsIFileSpec> aSpec;        if (asFile)        {          nsCOMPtr<nsIFileSpecWithUI>            fileSpec(getter_AddRefs(NS_CreateFileSpecWithUI()));          if (!fileSpec) return NS_ERROR_FAILURE;          rv = fileSpec->ChooseOutputFile("Save Message", "",                                nsIFileSpecWithUI::eAllMailOutputFilters);          aSpec = do_QueryInterface(fileSpec, &rv);        }        else        {          nsFileSpec tmpFileSpec("msgTemp.eml");          rv = NS_NewFileSpecWithSpec(tmpFileSpec, getter_AddRefs(aSpec));        }        if (NS_SUCCEEDED(rv))        {          nsCOMPtr<nsIUrlListener> urlListener;          if (!asFile && aSpec)          {            nsSaveAsListener *aListener = new nsSaveAsListener(aSpec);            if (aListener)            {              rv = aListener->QueryInterface(                nsCOMTypeInfo<nsIUrlListener>::GetIID(),                getter_AddRefs(urlListener));              if (NS_FAILED(rv))              {                delete aListener;                return rv;              }              NS_ADDREF(aListener); // nsUrlListenerManager uses nsVoidArray                                    // to keep trach of all listeners we have                                    // to manually add refs ourself            }          }          if (NS_SUCCEEDED(rv))            messageService->SaveMessageToDisk(url, aSpec, PR_TRUE,                                              urlListener, nsnull);        }      }    }	return rv;}