if (actionType == nsMsgFilterAction::MoveToFolder)
if (actionType == nsMsgFilterAction::MoveToFolder || actionType == nsMsgFilterAction::CopyToFolder)
nsresult nsMsgFilterAfterTheFact::ApplyFilter(){  nsresult rv = NS_OK;  if (m_curFilter && m_curFolder)  {    // we're going to log the filter actions before firing them because some actions are async    PRBool loggingEnabled = PR_FALSE;    if (m_filters)      (void)m_filters->GetLoggingEnabled(&loggingEnabled);    nsCOMPtr<nsISupportsArray> actionList;    rv = NS_NewISupportsArray(getter_AddRefs(actionList));    NS_ENSURE_SUCCESS(rv, rv);    rv = m_curFilter->GetSortedActionList(actionList);    NS_ENSURE_SUCCESS(rv, rv);    PRUint32 numActions;    actionList->Count(&numActions);    PRBool applyMoreActions = PR_TRUE;    for (PRUint32 actionIndex =0; actionIndex < numActions && applyMoreActions; actionIndex++)    {      nsCOMPtr<nsIMsgRuleAction> filterAction;      actionList->QueryElementAt(actionIndex, NS_GET_IID(nsIMsgRuleAction), (void **)getter_AddRefs(filterAction));      nsMsgRuleActionType actionType;      if (filterAction)        filterAction->GetType(&actionType);      else        continue;            nsXPIDLCString actionTargetFolderUri;      if (actionType == nsMsgFilterAction::MoveToFolder)      {        filterAction->GetTargetFolderUri(getter_Copies(actionTargetFolderUri));        if (actionTargetFolderUri.IsEmpty())        {          NS_ASSERTION(PR_FALSE, "actionTargetFolderUri is empty");          continue;        }      }      if (loggingEnabled)       {          for (PRUint32 msgIndex = 0; msgIndex < m_searchHits.GetSize(); msgIndex++)          {            nsCOMPtr <nsIMsgDBHdr> msgHdr;            m_searchHitHdrs->QueryElementAt(msgIndex, NS_GET_IID(nsIMsgDBHdr), getter_AddRefs(msgHdr));            if (msgHdr)              (void)m_curFilter->LogRuleHit(filterAction, msgHdr);           }      }      // all actions that pass "this" as a listener in order to chain filter execution      // when the action is finished need to return before reaching the bottom of this      // routine, because we run the next filter at the end of this routine.      switch (actionType)      {      case nsMsgFilterAction::Delete:        // we can't pass ourselves in as a copy service listener because the copy service        // listener won't get called in several situations (e.g., the delete model is imap delete)        // and we rely on the listener getting called to continue the filter application.        // This means we're going to end up firing off the delete, and then subsequently         // issuing a search for the next filter, which will block until the delete finishes.        m_curFolder->DeleteMessages(m_searchHitHdrs, m_msgWindow, PR_FALSE, PR_FALSE, nsnull, PR_FALSE /*allow Undo*/ );        //if we are deleting then we couldn't care less about applying remaining filter actions        applyMoreActions = PR_FALSE;        break;      case nsMsgFilterAction::MoveToFolder:      {        // if moving to a different file, do it.        nsXPIDLCString uri;        rv = m_curFolder->GetURI(getter_Copies(uri));        if ((const char*)actionTargetFolderUri &&            nsCRT::strcmp(uri, actionTargetFolderUri))        {          nsCOMPtr<nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);          nsCOMPtr<nsIRDFResource> res;          rv = rdf->GetResource(actionTargetFolderUri, getter_AddRefs(res));          NS_ENSURE_SUCCESS(rv, rv);          nsCOMPtr<nsIMsgFolder> destIFolder(do_QueryInterface(res, &rv));          NS_ENSURE_SUCCESS(rv, rv);          PRBool canFileMessages = PR_TRUE;          nsCOMPtr<nsIMsgFolder> parentFolder;          destIFolder->GetParent(getter_AddRefs(parentFolder));          if (parentFolder)            destIFolder->GetCanFileMessages(&canFileMessages);          if (!parentFolder || !canFileMessages)          {            m_curFilter->SetEnabled(PR_FALSE);            destIFolder->ThrowAlertMsg("filterDisabled",m_msgWindow);            // we need to explicitly save the filter file.            m_filters->SaveToDefaultFile();            // In the case of applying multiple filters            // we might want to remove the filter from the list, but             // that's a bit evil since we really don't know that we own            // the list. Disabling it doesn't do a lot of good since            // we still apply disabled filters. Currently, we don't            // have any clients that apply filters to multiple folders,            // so this might be the edge case of an edge case.            return RunNextFilter();          }          nsCOMPtr<nsIMsgCopyService> copyService = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID, &rv);          if (copyService)            return copyService->CopyMessages(m_curFolder, m_searchHitHdrs, destIFolder, PR_TRUE, this, m_msgWindow, PR_FALSE);        }        //we have already moved the hdrs so we can't apply more actions        applyMoreActions = PR_FALSE;      }                break;      case nsMsgFilterAction::MarkRead:          // crud, no listener support here - we'll probably just need to go on and apply          // the next filter, and, in the imap case, rely on multiple connection and url          // queueing to stay out of trouble          m_curFolder->MarkMessagesRead(m_searchHitHdrs, PR_TRUE);        break;      case nsMsgFilterAction::MarkFlagged:        m_curFolder->MarkMessagesFlagged(m_searchHitHdrs, PR_TRUE);        break;      case nsMsgFilterAction::KillThread:      case nsMsgFilterAction::WatchThread:        {          for (PRUint32 msgIndex = 0; msgIndex < m_searchHits.GetSize(); msgIndex++)          {            nsCOMPtr <nsIMsgDBHdr> msgHdr;            m_searchHitHdrs->QueryElementAt(msgIndex, NS_GET_IID(nsIMsgDBHdr), getter_AddRefs(msgHdr));            if (msgHdr)            {              nsCOMPtr <nsIMsgThread> msgThread;              nsMsgKey threadKey;              m_curFolderDB->GetThreadContainingMsgHdr(msgHdr, getter_AddRefs(msgThread));              if (msgThread)              {                msgThread->GetThreadKey(&threadKey);                if (actionType == nsMsgFilterAction::KillThread)                  m_curFolderDB->MarkThreadIgnored(msgThread, threadKey, PR_TRUE, nsnull);                else                  m_curFolderDB->MarkThreadWatched(msgThread, threadKey, PR_TRUE, nsnull);              }            }          }        }        break;      case nsMsgFilterAction::ChangePriority:          {              nsMsgPriorityValue filterPriority;              filterAction->GetPriority(&filterPriority);              for (PRUint32 msgIndex = 0; msgIndex < m_searchHits.GetSize(); msgIndex++)              {                nsCOMPtr <nsIMsgDBHdr> msgHdr;                m_searchHitHdrs->QueryElementAt(msgIndex, NS_GET_IID(nsIMsgDBHdr), getter_AddRefs(msgHdr));                if (msgHdr)                  msgHdr->SetPriority(filterPriority);              }          }        break;      case nsMsgFilterAction::Label:        {            nsMsgLabelValue filterLabel;            filterAction->GetLabel(&filterLabel);            m_curFolder->SetLabelForMessages(m_searchHitHdrs, filterLabel);        }      case nsMsgFilterAction::JunkScore:      {        nsCAutoString junkScoreStr;        PRInt32 junkScore;        filterAction->GetJunkScore(&junkScore);        junkScoreStr.AppendInt(junkScore);        m_curFolder->SetJunkScoreForMessages(m_searchHitHdrs, junkScoreStr.get());        break;      }      default:        break;      }    }  }  return RunNextFilter();}