rv = ConvertToUnicode(NS_LITERAL_STRING("UTF-8"), unescapedName, tempStr); if (NS_FAILED(rv)) goto done; rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), tempStr,
rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), NS_ConvertUTF8toUCS2(unescapedName),
nsSaveMsgListener::OnStopRequest(nsIRequest* request, nsISupports* aSupport,                                nsresult status){  nsresult    rv = NS_OK;  // rhp: If we are doing the charset conversion magic, this is different  // processing, otherwise, its just business as usual.  //  if ( (m_doCharsetConversion) && (m_fileSpec) )  {    char        *conBuf = nsnull;    PRUint32    conLength = 0;     // If we need text/plain, then we need to convert the HTML and then convert    // to the systems charset    //    if (m_outputFormat.EqualsWithConversion(TEXT_PLAIN))    {      ConvertBufToPlainText(m_msgBuffer);      rv = nsMsgI18NSaveAsCharset(TEXT_PLAIN, NS_LossyConvertUCS2toASCII(nsMsgI18NFileSystemCharset()).get(),                                   m_msgBuffer.get(), &conBuf);       if ( NS_SUCCEEDED(rv) && (conBuf) )        conLength = nsCRT::strlen(conBuf);    }    if ( (NS_SUCCEEDED(rv)) && (conBuf) )    {      PRUint32      writeCount;      rv = m_outputStream->Write(conBuf, conLength, &writeCount);      if (conLength != writeCount)        rv = NS_ERROR_FAILURE;    }    PR_FREEIF(conBuf);  }  // close down the file stream and release ourself  if (m_fileSpec)  {    m_fileSpec->Flush();    m_fileSpec->CloseStream();    m_outputStream = nsnull;  }    if (m_saveAllAttachmentsState)  {      m_saveAllAttachmentsState->m_curIndex++;      if (m_saveAllAttachmentsState->m_curIndex <          m_saveAllAttachmentsState->m_count)      {          char * unescapedUrl = nsnull, * unescapedName = nsnull,                * tempCStr = nsnull;          nsAutoString tempStr;          nsSaveAllAttachmentsState *state = m_saveAllAttachmentsState;          PRUint32 i = state->m_curIndex;          nsCOMPtr<nsIFileSpec> fileSpec;          nsFileSpec aFileSpec ((const char *) state->m_directoryName);          rv = NS_NewFileSpec(getter_AddRefs(fileSpec));          if (NS_FAILED(rv)) goto done;          unescapedUrl = PL_strdup(state->m_urlArray[i]);          nsUnescape(unescapedUrl);          unescapedName = PL_strdup(state->m_displayNameArray[i]);          nsUnescape(unescapedName);          rv = ConvertToUnicode(NS_LITERAL_STRING("UTF-8"), unescapedName, tempStr);          if (NS_FAILED(rv)) goto done;          rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), tempStr,                                  &tempCStr);          if (NS_FAILED(rv)) goto done;          PR_FREEIF(unescapedName);          unescapedName = tempCStr;          aFileSpec += unescapedName;          rv = m_messenger->PromptIfFileExists(aFileSpec);          if (NS_FAILED(rv)) goto done;          fileSpec->SetFromFileSpec(aFileSpec);          rv = m_messenger->SaveAttachment(fileSpec,                                           unescapedUrl,                                           state->m_messageUriArray[i],                                           state->m_contentTypeArray[i],                                           (void *)state);      done:          if (NS_FAILED(rv))          {              delete state;              m_saveAllAttachmentsState = nsnull;          }          PR_FREEIF(unescapedUrl);          PR_FREEIF(unescapedName);      }      else      {          delete m_saveAllAttachmentsState;          m_saveAllAttachmentsState = nsnull;      }  }  Release(); // all done kill ourself  return NS_OK;}