if (url) { #ifdef DEBUG_MESSENGER printf("nsMessenger::OpenAttachment(%s)\n",url); #endif unescapedUrl = PL_strdup(url); if (unescapedUrl) { nsUnescape(unescapedUrl);  nsCOMPtr<nsIFileSpec> aSpec; nsCOMPtr<nsIFileSpecWithUI> fileSpec(getter_AddRefs(NS_CreateFileSpecWithUI()));  if (!fileSpec) goto done;
if (aIsExternalAttachment) rv = OpenURL(aURL); else { nsCOMPtr <nsIMsgMessageService> messageService; rv = GetMessageServiceFromURI(aMessageUri, getter_AddRefs(messageService)); if (messageService) rv = messageService->OpenAttachment(aContentType, aDisplayName, aURL, aMessageUri, mDocShell, mMsgWindow, nsnull); }
nsMessenger::OpenAttachment(const char * url, const char * displayName,                             const char * messageUri){  nsresult rv = NS_ERROR_FAILURE;  char *unescapedUrl = nsnull;  nsIMsgMessageService * messageService = nsnull;	if (url)	{#ifdef DEBUG_MESSENGER		printf("nsMessenger::OpenAttachment(%s)\n",url);#endif            unescapedUrl = PL_strdup(url);        if (unescapedUrl)        {          nsUnescape(unescapedUrl);                    nsCOMPtr<nsIFileSpec> aSpec;          nsCOMPtr<nsIFileSpecWithUI>            fileSpec(getter_AddRefs(NS_CreateFileSpecWithUI()));                    if (!fileSpec) goto done;          rv = fileSpec->ChooseOutputFile("Save Attachment", displayName,                                          nsIFileSpecWithUI::eAllFiles);          if (NS_FAILED(rv)) goto done;                      aSpec = do_QueryInterface(fileSpec, &rv);          if (NS_FAILED(rv)) goto done;          nsSaveAsListener *aListener = new nsSaveAsListener(aSpec);          if (aListener)          {            NS_ADDREF(aListener);            nsCOMPtr<nsIURI> aURL;            nsString urlString = unescapedUrl;            char *urlCString = urlString.ToNewCString();            rv = CreateStartupUrl(urlCString, getter_AddRefs(aURL));            nsCRT::free(urlCString);            if (NS_FAILED(rv))             {              NS_RELEASE(aListener);              goto done;            }            aListener->m_channel = null_nsCOMPtr();            NS_WITH_SERVICE(nsIIOService, netService, kIOServiceCID, &rv);            rv = netService->NewInputStreamChannel(aURL,                                                   nsnull,      // contentType                                                   -1,          // contentLength                                                   nsnull,      // inputStream                                                   nsnull,      // loadGroup                                                   getter_AddRefs(aListener->m_channel));            nsAutoString from, to;            from = "message/rfc822";            to = "text/xul";            NS_WITH_SERVICE(nsIStreamConverterService,                            streamConverterService,                              kIStreamConverterServiceCID, &rv);            nsCOMPtr<nsISupports> channelSupport =              do_QueryInterface(aListener->m_channel);            nsCOMPtr<nsIStreamListener> convertedListener;            rv = streamConverterService->AsyncConvertData(              from.GetUnicode(), to.GetUnicode(), aListener,              channelSupport, getter_AddRefs(convertedListener));            rv = GetMessageServiceFromURI(messageUri, &messageService);                        if (NS_SUCCEEDED(rv) && messageService)            {              rv = messageService->DisplayMessage(messageUri,                                                  convertedListener,                                                  nsnull, nsnull);             }          }          else          {            rv = NS_ERROR_OUT_OF_MEMORY;          }        }        else        {          rv =  NS_ERROR_OUT_OF_MEMORY;        }	}done:    if (messageService)      ReleaseMessageServiceFromURI(unescapedUrl, messageService);    PR_FREEIF(unescapedUrl);	return rv;}