PR_FREEIF(templateUri);
nsSaveAsListener::OnStopRunningUrl(nsIURI* url, nsresult exitCode){  nsresult rv = exitCode;  char *templateUri = nsnull;  if (m_fileSpec)  {    m_fileSpec->Flush();    m_fileSpec->CloseStream();    if (NS_FAILED(rv)) goto done;    NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);    if (NS_FAILED(rv)) goto done;    prefs->CopyCharPref("mail.default_templates_uri", &templateUri);    if (!templateUri || !*templateUri)     {      rv = NS_ERROR_FAILURE;      goto done;    }    NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);    if (NS_FAILED(rv)) goto done;    nsCOMPtr<nsIRDFResource> res;    rv = rdf->GetResource(templateUri, getter_AddRefs(res));    if (NS_FAILED(rv)) goto done;    nsCOMPtr<nsIMsgFolder> templateFolder;    templateFolder = do_QueryInterface(res, &rv);    if (NS_FAILED(rv)) goto done;    NS_WITH_SERVICE(nsIMsgCopyService, copyService, kMsgCopyServiceCID, &rv);    if (NS_FAILED(rv)) goto done;    rv = copyService->CopyFileMessage(m_fileSpec, templateFolder, nsnull,                                      PR_TRUE, this, nsnull);  }done:  if (NS_FAILED(rv))  {    if (m_fileSpec)    {      nsFileSpec realSpec;      m_fileSpec->GetFileSpec(&realSpec);      realSpec.Delete(PR_FALSE);      Release(); // no more work to be done; kill ourself    }  }  PR_FREEIF(templateUri);  return rv;}