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);   } } if (NS_SUCCEEDED(rv)) messageService->SaveMessageToDisk(url, aSpec, PR_TRUE, urlListener, nsnull); }
saveListener->m_outputFormat = nsSaveMsgListener::ePlainText; saveListener->m_doCharsetConversion = PR_TRUE; urlString += NS_LITERAL_CSTRING("?header=print");
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;}