diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index fa53bf93eeca..516f731b794c 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -7040,28 +7040,6 @@ nsImapFolderCopyState::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) case nsIImapUrl::nsImapEnsureExistsFolder: { - nsCOMPtr messages; - rv = m_srcFolder->GetMessages(m_msgWindow, getter_AddRefs(messages)); - - nsCOMPtr msgSupportsArray; - NS_NewISupportsArray(getter_AddRefs(msgSupportsArray)); - - PRBool hasMoreElements; - nsCOMPtr aSupport; - - if (messages) - messages->HasMoreElements(&hasMoreElements); - - if (!hasMoreElements) - return StartNextCopy(); - - while (hasMoreElements && NS_SUCCEEDED(rv)) - { - rv = messages->GetNext(getter_AddRefs(aSupport)); - rv = msgSupportsArray->AppendElement(aSupport); - messages->HasMoreElements(&hasMoreElements); - } - nsCOMPtr newMsgFolder; nsXPIDLString folderName; @@ -7087,6 +7065,28 @@ nsImapFolderCopyState::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) } } + nsCOMPtr messages; + rv = m_srcFolder->GetMessages(m_msgWindow, getter_AddRefs(messages)); + + nsCOMPtr msgSupportsArray; + NS_NewISupportsArray(getter_AddRefs(msgSupportsArray)); + + PRBool hasMoreElements; + nsCOMPtr aSupport; + + if (messages) + messages->HasMoreElements(&hasMoreElements); + + if (!hasMoreElements) + return AdvanceToNextFolder(NS_OK); + + while (hasMoreElements && NS_SUCCEEDED(rv)) + { + rv = messages->GetNext(getter_AddRefs(aSupport)); + rv = msgSupportsArray->AppendElement(aSupport); + messages->HasMoreElements(&hasMoreElements); + } + nsCOMPtr copyService = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) rv = copyService->CopyMessages(m_srcFolder,