Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsLocalMoveCopyMsgTxn Class Reference

#include <nsLocalUndoTxn.h>

Collaboration diagram for nsLocalMoveCopyMsgTxn:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsLocalMoveCopyMsgTxn ()
virtual ~nsLocalMoveCopyMsgTxn ()
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD 
UndoTransaction (void)
NS_IMETHOD RedoTransaction (void)
nsresult AddSrcKey (nsMsgKey aKey)
nsresult AddSrcStatusOffset (PRUint32 statusOffset)
nsresult AddDstKey (nsMsgKey aKey)
nsresult AddDstMsgSize (PRUint32 msgSize)
nsresult SetSrcFolder (nsIMsgFolder *srcFolder)
nsresult GetSrcIsImap (PRBool *isImap)
nsresult SetDstFolder (nsIMsgFolder *dstFolder)
nsresult Init (nsIMsgFolder *srcFolder, nsIMsgFolder *dstFolder, PRBool isMove)
nsresult UndoImapDeleteFlag (nsIMsgFolder *aFolder, nsMsgKeyArray &aKeyArray, PRBool deleteFlag)
nsresult UndoTransactionInternal ()

Private Attributes

nsWeakPtr m_srcFolder
nsMsgKeyArray m_srcKeyArray
nsUInt32Array m_srcStatusOffsetArray
nsWeakPtr m_dstFolder
nsMsgKeyArray m_dstKeyArray
PRBool m_isMove
PRBool m_srcIsImap4
nsUInt32Array m_dstSizeArray
nsLocalUndoFolderListenermUndoFolderListener

Detailed Description

Definition at line 57 of file nsLocalUndoTxn.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsLocalUndoTxn.cpp.

Definition at line 56 of file nsLocalUndoTxn.cpp.

{
}

Member Function Documentation

Definition at line 146 of file nsLocalUndoTxn.cpp.

{
       m_dstKeyArray.Add(aKey);
       return NS_OK;
}

Definition at line 153 of file nsLocalUndoTxn.cpp.

{
    m_dstSizeArray.Add(msgSize);
    return NS_OK;
}

Definition at line 131 of file nsLocalUndoTxn.cpp.

{
       m_srcKeyArray.Add(aKey);
       return NS_OK;
}

Definition at line 138 of file nsLocalUndoTxn.cpp.

{
       m_srcStatusOffsetArray.Add(aStatusOffset);
       return NS_OK;
}

Definition at line 107 of file nsLocalUndoTxn.cpp.

{
  *isImap = m_srcIsImap4;
  return NS_OK;
}
nsresult nsLocalMoveCopyMsgTxn::Init ( nsIMsgFolder srcFolder,
nsIMsgFolder dstFolder,
PRBool  isMove 
)

Definition at line 85 of file nsLocalUndoTxn.cpp.

{
    nsresult rv;
    rv = SetSrcFolder(srcFolder);
    rv = SetDstFolder(dstFolder);
    m_isMove = isMove;

    mUndoFolderListener = nsnull;

    nsXPIDLCString uri;
    if (!srcFolder) return rv;
    rv = srcFolder->GetURI(getter_Copies(uri));
    nsCString protocolType(uri);
    protocolType.SetLength(protocolType.FindChar(':'));
    if (protocolType.LowerCaseEqualsLiteral("imap"))
    {
        m_srcIsImap4 = PR_TRUE;
    }
    return nsMsgTxn::Init();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 351 of file nsLocalUndoTxn.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    nsCOMPtr<nsIMsgDatabase> srcDB;
    nsCOMPtr<nsIMsgDatabase> dstDB;

    nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
    if (NS_FAILED(rv) || !srcFolder) return rv;

    nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
    if (NS_FAILED(rv) || !dstFolder) return rv;
    
    rv = srcFolder->GetMsgDatabase(nsnull, getter_AddRefs(srcDB));
    if(NS_FAILED(rv)) return rv;
    rv = dstFolder->GetMsgDatabase(nsnull, getter_AddRefs(dstDB));
    if (NS_FAILED(rv)) return rv;

    PRUint32 count = m_srcKeyArray.GetSize();
    PRUint32 i;
    nsCOMPtr<nsIMsgDBHdr> oldHdr;
    nsCOMPtr<nsIMsgDBHdr> newHdr;

    nsCOMPtr<nsISupportsArray> srcMessages;
    NS_NewISupportsArray(getter_AddRefs(srcMessages));
    nsCOMPtr <nsISupports> msgSupports;
    
    for (i=0; i<count; i++)
    {
        rv = srcDB->GetMsgHdrForKey(m_srcKeyArray.GetAt(i), 
                                    getter_AddRefs(oldHdr));
        NS_ASSERTION(oldHdr, "fatal ... cannot get old msg header\n");

        if (NS_SUCCEEDED(rv) && oldHdr)
        {
            msgSupports =do_QueryInterface(oldHdr);
            srcMessages->AppendElement(msgSupports);
            
            rv = dstDB->CopyHdrFromExistingHdr(m_dstKeyArray.GetAt(i),
                                               oldHdr, PR_TRUE,
                                               getter_AddRefs(newHdr));
            NS_ASSERTION(newHdr, "fatal ... cannot get new msg header\n");
            if (NS_SUCCEEDED(rv) && newHdr)
            {
                if (m_dstSizeArray.GetSize() > i)
                    rv = newHdr->SetMessageSize(m_dstSizeArray.GetAt(i));
                dstDB->UndoDelete(newHdr);
            }
        }
    }
    dstDB->SetSummaryValid(PR_TRUE);

    if (m_isMove)
    {
        if (m_srcIsImap4)
        {
            // protect against a bogus undo txn without any source keys
            // see bug #179856 for details
            NS_ASSERTION(m_srcKeyArray.GetSize(), "no source keys");
            if (!m_srcKeyArray.GetSize())
              return NS_ERROR_UNEXPECTED;
          
            PRBool deleteFlag = PR_FALSE; //message is un-deleted- we are trying to redo
            CheckForToggleDelete(srcFolder, m_srcKeyArray.GetAt(0), &deleteFlag); // there could have been a toggle
            rv = UndoImapDeleteFlag(srcFolder, m_srcKeyArray, deleteFlag);
        }
        else
        {
            nsCOMPtr <nsIMsgLocalMailFolder> localFolder = do_QueryInterface(srcFolder);
            if (localFolder)
              localFolder->MarkMsgsOnPop3Server(srcMessages, POP3_DELETE /*deleteMsgs*/);

            rv = srcDB->DeleteMessages(&m_srcKeyArray, nsnull);
            srcDB->SetSummaryValid(PR_TRUE);
        }
    }

    return rv;
}

Here is the call graph for this function:

Definition at line 122 of file nsLocalUndoTxn.cpp.

{
       nsresult rv = NS_ERROR_NULL_POINTER;
       if (dstFolder)
          m_dstFolder = do_GetWeakReference(dstFolder, &rv);
       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file nsLocalUndoTxn.cpp.

{
       nsresult rv = NS_ERROR_NULL_POINTER;
       if (srcFolder)
          m_srcFolder = do_GetWeakReference(srcFolder, &rv);
       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsLocalMoveCopyMsgTxn::UndoImapDeleteFlag ( nsIMsgFolder aFolder,
nsMsgKeyArray &  aKeyArray,
PRBool  deleteFlag 
)

Definition at line 160 of file nsLocalUndoTxn.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    if (m_srcIsImap4)
    {
        nsCOMPtr<nsIImapService> imapService = 
                 do_GetService(NS_IMAPSERVICE_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv))
        {
            nsCOMPtr<nsIUrlListener> urlListener;
            nsCString msgIds;
            PRUint32 i, count = keyArray.GetSize();

            urlListener = do_QueryInterface(folder, &rv);

            for (i=0; i < count; i++)
            {
                if (!msgIds.IsEmpty())
                    msgIds.Append(',');
                msgIds.AppendInt((PRInt32) keyArray.GetAt(i));
            }
            nsCOMPtr<nsIEventQueue> eventQueue;
            nsCOMPtr<nsIEventQueueService> pEventQService = 
                     do_GetService(kEventQueueServiceCID, &rv);
            if (NS_SUCCEEDED(rv) && pEventQService)
            {
                pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,
                                              getter_AddRefs(eventQueue));
                if (eventQueue)
                {
                    // This is to make sure that we are in the selected state
                    // when executing the imap url; we don't want to load the
                    // folder so use lite select to do the trick
                    rv = imapService->LiteSelectFolder(eventQueue, folder,
                                                       urlListener, nsnull);
                    if (!deleteFlag)
                        rv =imapService->AddMessageFlags(eventQueue, folder,
                                                        urlListener, nsnull,
                                                        msgIds.get(),
                                                        kImapMsgDeletedFlag,
                                                        PR_TRUE);
                    else
                        rv = imapService->SubtractMessageFlags(eventQueue,
                                                              folder,
                                                         urlListener, nsnull,
                                                         msgIds.get(),
                                                         kImapMsgDeletedFlag,
                                                         PR_TRUE);
                    if (NS_SUCCEEDED(rv) && m_msgWindow)
                        folder->UpdateFolder(m_msgWindow);
                }
            }
        }
        rv = NS_OK; // always return NS_OK to indicate that the src is imap
    }
    else
    {
        rv = NS_ERROR_FAILURE;
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 225 of file nsLocalUndoTxn.cpp.

{
    nsresult rv;
    nsCOMPtr<nsIMsgDatabase> dstDB;
    
    nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
    if (NS_FAILED(rv) || !dstFolder) return rv;
    nsCOMPtr<nsIMsgLocalMailFolder> dstlocalMailFolder = do_QueryReferent(m_dstFolder, &rv);
    if (NS_FAILED(rv) || !dstlocalMailFolder) return rv;
              dstlocalMailFolder->GetDatabaseWOReparse(getter_AddRefs(dstDB));

    if (!dstDB)
    {
      mUndoFolderListener = new nsLocalUndoFolderListener(this, dstFolder);
      if (!mUndoFolderListener)
        return NS_ERROR_OUT_OF_MEMORY; 
      NS_ADDREF(mUndoFolderListener);
      
      nsCOMPtr<nsIMsgMailSession> mailSession = 
        do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); 
      NS_ENSURE_SUCCESS(rv,rv);
      
      rv = mailSession->AddFolderListener(mUndoFolderListener, nsIFolderListener::event);
      NS_ENSURE_SUCCESS(rv,rv);
      
      rv = dstFolder->GetMsgDatabase(nsnull, getter_AddRefs(dstDB));
      NS_ENSURE_SUCCESS(rv,rv);
    }
    else
    {
      rv = UndoTransactionInternal();
    }
    return rv;
}

Here is the call graph for this function:

Definition at line 261 of file nsLocalUndoTxn.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;

    if (mUndoFolderListener)
    {
      nsCOMPtr<nsIMsgMailSession> mailSession = 
        do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); 
      NS_ENSURE_SUCCESS(rv,rv);
      
      rv = mailSession->RemoveFolderListener(mUndoFolderListener);
      NS_ENSURE_SUCCESS(rv,rv);
      
      NS_RELEASE(mUndoFolderListener);
      mUndoFolderListener = nsnull;
    }

    nsCOMPtr<nsIMsgDatabase> srcDB;
    nsCOMPtr<nsIMsgDatabase> dstDB;
    nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
    if (NS_FAILED(rv) || !srcFolder) return rv;
    
    nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
    if (NS_FAILED(rv) || !dstFolder) return rv;
    
    rv = srcFolder->GetMsgDatabase(nsnull, getter_AddRefs(srcDB));
    if(NS_FAILED(rv)) return rv;

    rv = dstFolder->GetMsgDatabase(nsnull, getter_AddRefs(dstDB));
    if (NS_FAILED(rv)) return rv;

    PRUint32 count = m_srcKeyArray.GetSize();
    PRUint32 i;
    nsCOMPtr<nsIMsgDBHdr> oldHdr;
    nsCOMPtr<nsIMsgDBHdr> newHdr;

    // protect against a bogus undo txn without any source keys
    // see bug #179856 for details
    NS_ASSERTION(count, "no source keys");
    if (!count)
      return NS_ERROR_UNEXPECTED;

    if (m_isMove)
    {
        if (m_srcIsImap4)
        {
            PRBool deleteFlag = PR_TRUE;  //message has been deleted -we are trying to undo it
            CheckForToggleDelete(srcFolder, m_srcKeyArray.GetAt(0), &deleteFlag); //there could have been a toggle.
            rv = UndoImapDeleteFlag(srcFolder, m_srcKeyArray, deleteFlag);
        }
        else
        {
            nsCOMPtr<nsISupportsArray> srcMessages;
            NS_NewISupportsArray(getter_AddRefs(srcMessages));
            nsCOMPtr <nsISupports> msgSupports;
            for (i=0; i<count; i++)
            {
                rv = dstDB->GetMsgHdrForKey(m_dstKeyArray.GetAt(i), 
                                            getter_AddRefs(oldHdr));
                NS_ASSERTION(oldHdr, "fatal ... cannot get old msg header\n");
                if (NS_SUCCEEDED(rv) && oldHdr)
                {
                    rv = srcDB->CopyHdrFromExistingHdr(m_srcKeyArray.GetAt(i),
                                                       oldHdr, PR_TRUE,
                                                       getter_AddRefs(newHdr));
                    NS_ASSERTION(newHdr, 
                                 "fatal ... cannot create new msg header\n");
                    if (NS_SUCCEEDED(rv) && newHdr)
                    {
                                                                              newHdr->SetStatusOffset(m_srcStatusOffsetArray.GetAt(i));
                       srcDB->UndoDelete(newHdr);
                       msgSupports = do_QueryInterface(newHdr);
                       srcMessages->AppendElement(msgSupports);
                    }
                }
            }
            nsCOMPtr <nsIMsgLocalMailFolder> localFolder = do_QueryInterface(srcFolder);
            if (localFolder)
              localFolder->MarkMsgsOnPop3Server(srcMessages, POP3_NONE /*deleteMsgs*/);
        }
        srcDB->SetSummaryValid(PR_TRUE);
    }

    dstDB->DeleteMessages(&m_dstKeyArray, nsnull);
    dstDB->SetSummaryValid(PR_TRUE);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 91 of file nsLocalUndoTxn.h.

nsMsgKeyArray nsLocalMoveCopyMsgTxn::m_dstKeyArray [private]

Definition at line 92 of file nsLocalUndoTxn.h.

nsUInt32Array nsLocalMoveCopyMsgTxn::m_dstSizeArray [private]

Definition at line 95 of file nsLocalUndoTxn.h.

Definition at line 93 of file nsLocalUndoTxn.h.

Definition at line 88 of file nsLocalUndoTxn.h.

Definition at line 94 of file nsLocalUndoTxn.h.

nsMsgKeyArray nsLocalMoveCopyMsgTxn::m_srcKeyArray [private]

Definition at line 89 of file nsLocalUndoTxn.h.

Definition at line 90 of file nsLocalUndoTxn.h.

Definition at line 96 of file nsLocalUndoTxn.h.


The documentation for this class was generated from the following files: