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; nsFileURL fileUrl(state->m_directoryName); nsFilePath dirPath(fileUrl); nsCOMPtr<nsIFileSpec> fileSpec; nsFileSpec aFileSpec;  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("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 = dirPath; aFileSpec += unescapedName; fileSpec->SetFromFileSpec(aFileSpec); rv = m_messenger->SaveAttachment(fileSpec, unescapedUrl, state->m_messageUriArray[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; } }
nsSaveAsListener::OnStopRequest(nsIChannel* aChannel, nsISupports* aSupport,                                nsresult status, const PRUnichar* aMsg){  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.Equals(TEXT_PLAIN))    {      ConvertBufToPlainText(m_msgBuffer);      rv = nsMsgI18NSaveAsCharset(TEXT_PLAIN, (const char *)nsAutoCString(nsMsgI18NFileSystemCharset()),                                   m_msgBuffer.GetUnicode(), &conBuf);       if ( NS_SUCCEEDED(rv) && (conBuf) )        conLength = m_msgBuffer.Length();    }    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 = null_nsCOMPtr();  }    Release(); // all done kill ourself  return NS_OK;}