Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsImapMoveCopyMsgTxn Class Reference

#include <nsImapUndoTxn.h>

Inheritance diagram for nsImapMoveCopyMsgTxn:
Inheritance graph
[legend]
Collaboration diagram for nsImapMoveCopyMsgTxn:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsImapMoveCopyMsgTxn ()
 nsImapMoveCopyMsgTxn (nsIMsgFolder *srcFolder, nsMsgKeyArray *srcKeyArray, const char *srcMsgIdString, nsIMsgFolder *dstFolder, PRBool idsAreUids, PRBool isMove, nsIEventQueue *eventQueue, nsIUrlListener *urlListener)
virtual ~nsImapMoveCopyMsgTxn ()
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD 
UndoTransaction (void)
NS_IMETHOD RedoTransaction (void)
nsresult SetCopyResponseUid (const char *msgIdString)
nsresult GetSrcKeyArray (nsMsgKeyArray &srcKeyArray)
nsresult AddDstKey (nsMsgKey aKey)
nsresult UndoMailboxDelete ()
nsresult RedoMailboxDelete ()
nsresult Init (nsIMsgFolder *srcFolder, nsMsgKeyArray *srcKeyArray, const char *srcMsgIdString, nsIMsgFolder *dstFolder, PRBool idsAreUids, PRBool isMove, nsIEventQueue *eventQueue, nsIUrlListener *urlListener)

Protected Member Functions

nsresult GetImapDeleteModel (nsIMsgFolder *aFolder, nsMsgImapDeleteModel *aDeleteModel)

Protected Attributes

nsWeakPtr m_srcFolder
nsCOMPtr< nsISupportsArraym_srcHdrs
nsMsgKeyArray m_dupKeyArray
nsMsgKeyArray m_srcKeyArray
nsCString m_srcMsgIdString
nsWeakPtr m_dstFolder
nsCString m_dstMsgIdString
nsCOMPtr< nsIEventQueuem_eventQueue
nsCOMPtr< nsIUrlListenerm_urlListener
PRBool m_idsAreUids
PRBool m_isMove
PRBool m_srcIsPop3
nsUInt32Array m_srcSizeArray

Detailed Description

Definition at line 58 of file nsImapUndoTxn.h.


Constructor & Destructor Documentation

nsImapMoveCopyMsgTxn::nsImapMoveCopyMsgTxn ( nsIMsgFolder srcFolder,
nsMsgKeyArray *  srcKeyArray,
const char *  srcMsgIdString,
nsIMsgFolder dstFolder,
PRBool  idsAreUids,
PRBool  isMove,
nsIEventQueue eventQueue,
nsIUrlListener urlListener 
)

Definition at line 118 of file nsImapUndoTxn.cpp.

{
}

Member Function Documentation

Definition at line 341 of file nsImapUndoTxn.cpp.

{
    if (!m_dstMsgIdString.IsEmpty())
        m_dstMsgIdString.Append(",");
    m_dstMsgIdString.AppendInt((PRInt32) aKey);
    return NS_OK;
}

Definition at line 424 of file nsImapUndoTxn.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIMsgIncomingServer> server;
  if (!aFolder)
    return NS_ERROR_NULL_POINTER;
  rv = aFolder->GetServer(getter_AddRefs(server));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIImapIncomingServer> imapServer = do_QueryInterface(server, &rv);
  if (NS_SUCCEEDED(rv) && imapServer)
   rv = imapServer->GetDeleteModel(aDeleteModel);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsImapMoveCopyMsgTxn::GetSrcKeyArray ( nsMsgKeyArray &  srcKeyArray)

Definition at line 334 of file nsImapUndoTxn.cpp.

{
    srcKeyArray.CopyArray(&m_srcKeyArray);
    return NS_OK;
}
nsresult nsImapMoveCopyMsgTxn::Init ( nsIMsgFolder srcFolder,
nsMsgKeyArray *  srcKeyArray,
const char *  srcMsgIdString,
nsIMsgFolder dstFolder,
PRBool  idsAreUids,
PRBool  isMove,
nsIEventQueue eventQueue,
nsIUrlListener urlListener 
)

Definition at line 54 of file nsImapUndoTxn.cpp.

{
  nsresult rv;
  NS_NewISupportsArray(getter_AddRefs(m_srcHdrs));
  m_srcMsgIdString = srcMsgIdString;
  m_idsAreUids = idsAreUids;
  m_isMove = isMove;
  m_srcFolder = do_GetWeakReference(srcFolder);
  m_dstFolder = do_GetWeakReference(dstFolder);
  m_eventQueue = do_QueryInterface(eventQueue, &rv);
  if (urlListener)
    m_urlListener = do_QueryInterface(urlListener, &rv);
  m_srcKeyArray.CopyArray(srcKeyArray);
  m_dupKeyArray.CopyArray(srcKeyArray);
  nsXPIDLCString uri;
  rv = srcFolder->GetURI(getter_Copies(uri));
  nsCString protocolType(uri);
  protocolType.SetLength(protocolType.FindChar(':'));
  // ** jt -- only do this for mailbox protocol
  if (protocolType.LowerCaseEqualsLiteral("mailbox"))
  {
    m_srcIsPop3 = PR_TRUE;
    PRUint32 i, count = m_srcKeyArray.GetSize();
    nsCOMPtr<nsIMsgDatabase> srcDB;
    rv = srcFolder->GetMsgDatabase(nsnull, getter_AddRefs(srcDB));
    if (NS_FAILED(rv)) return rv;
    nsCOMPtr<nsIMsgDBHdr> srcHdr;
    nsCOMPtr<nsIMsgDBHdr> copySrcHdr;
    nsMsgKey pseudoKey;
    
    for (i=0; i<count; i++)
    {
      rv = srcDB->GetMsgHdrForKey(m_srcKeyArray.GetAt(i),
        getter_AddRefs(srcHdr));
      if (NS_SUCCEEDED(rv))
      {
        PRUint32 msgSize;
        rv = srcHdr->GetMessageSize(&msgSize);
        if (NS_SUCCEEDED(rv))
          m_srcSizeArray.Add(msgSize);
        if (isMove)
        {
          srcDB->GetNextPseudoMsgKey(&pseudoKey);
          pseudoKey--;
          m_dupKeyArray.SetAt(i,pseudoKey);
          rv = srcDB->CopyHdrFromExistingHdr(pseudoKey,
            srcHdr, PR_FALSE,
            getter_AddRefs(copySrcHdr));
          if (NS_SUCCEEDED(rv)) 
          {
            nsCOMPtr<nsISupports> supports = do_QueryInterface(copySrcHdr);
            m_srcHdrs->AppendElement(supports);
          }
        }
      }
    }
  }
  return nsMsgTxn::Init();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 401 of file nsImapUndoTxn.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    if (m_srcIsPop3)
    {
        nsCOMPtr<nsIMsgDatabase> srcDB;
        nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
        if (NS_FAILED(rv) || !srcFolder) return rv;
        rv = srcFolder->GetMsgDatabase(nsnull, getter_AddRefs(srcDB));
        if (NS_SUCCEEDED(rv))
        {
            srcDB->DeleteMessages(&m_srcKeyArray, nsnull);
            srcDB->SetSummaryValid(PR_TRUE);
        }
        return NS_OK; // always return NS_OK
    }
    else
    {
        rv = NS_ERROR_FAILURE;
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in nsImapOfflineTxn.

Definition at line 233 of file nsImapUndoTxn.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIImapService> imapService = do_GetService(NS_IMAPSERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);
  
  if (m_isMove || !m_dstFolder)
  {
    if (m_srcIsPop3)
    {
      rv = RedoMailboxDelete();
      if (NS_FAILED(rv)) return rv;
    }
    else
    {
      nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
      if (NS_FAILED(rv) || !srcFolder) 
        return rv;
      nsCOMPtr<nsIUrlListener> srcListener =
        do_QueryInterface(srcFolder, &rv); 
      if (NS_FAILED(rv)) 
        return rv;
      
      PRBool deletedMsgs = PR_FALSE;  //default will be false unless imapDeleteModel;
      nsMsgImapDeleteModel deleteModel;
      rv = GetImapDeleteModel(srcFolder, &deleteModel);
      
      // 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;
      
      if (NS_SUCCEEDED(rv) && deleteModel == nsMsgImapDeleteModels::IMAPDelete)
        rv = CheckForToggleDelete(srcFolder, m_srcKeyArray.GetAt(0), &deletedMsgs);
      
      // ** make sire we are in the selected state; use lite select
      // folder so we won't hit preformace hard
      rv = imapService->LiteSelectFolder(m_eventQueue, srcFolder,
        srcListener, nsnull);
      if (NS_FAILED(rv)) 
        return rv;
      if (deletedMsgs)
        rv = imapService->SubtractMessageFlags(m_eventQueue, srcFolder, 
                                                srcListener, nsnull,
                                                m_srcMsgIdString.get(), kImapMsgDeletedFlag,
                                                m_idsAreUids);
      else
        rv = imapService->AddMessageFlags(m_eventQueue, srcFolder,
                                          srcListener, nsnull, m_srcMsgIdString.get(),
                                          kImapMsgDeletedFlag, m_idsAreUids);
    }
  }
  if (!m_dstMsgIdString.IsEmpty())
  {
    nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
    if (NS_FAILED(rv) || !dstFolder) return rv;
    
    nsCOMPtr<nsIUrlListener> dstListener;
    
    dstListener = do_QueryInterface(dstFolder, &rv); 
    if (NS_FAILED(rv)) 
      return rv;
    // ** make sure we are in the selected state; use lite select
    // folder so we won't hit preformace hard
    rv = imapService->LiteSelectFolder(m_eventQueue, dstFolder,
      dstListener, nsnull);
    if (NS_FAILED(rv)) 
      return rv;
    rv = imapService->SubtractMessageFlags(m_eventQueue, dstFolder,
      dstListener, nsnull,
      m_dstMsgIdString.get(),
      kImapMsgDeletedFlag,
      m_idsAreUids);
    if (NS_FAILED(rv)) 
      return rv;
    nsMsgImapDeleteModel deleteModel;
    rv = GetImapDeleteModel(dstFolder, &deleteModel);
    if (NS_FAILED(rv) || deleteModel == nsMsgImapDeleteModels::MoveToTrash)
      rv = imapService->GetHeaders(m_eventQueue, dstFolder,
      dstListener, nsnull,
      m_dstMsgIdString.get(),
      PR_TRUE);
  }
  return rv;
}

Here is the call graph for this function:

Definition at line 321 of file nsImapUndoTxn.cpp.

{
  if (!aMsgIdString) return NS_ERROR_NULL_POINTER;
  m_dstMsgIdString = aMsgIdString;
  if (m_dstMsgIdString.Last() == ']')
  {
    PRInt32 len = m_dstMsgIdString.Length();
    m_dstMsgIdString.SetLength(len - 1);
  }
  return NS_OK;
}

Definition at line 350 of file nsImapUndoTxn.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    // ** jt -- only do this for mailbox protocol
    if (m_srcIsPop3)
    {
        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;

        nsCOMPtr<nsIMsgDatabase> srcDB;
        nsCOMPtr<nsIMsgDatabase> dstDB;
        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;
        for (i=0; i<count; i++)
        {
           oldHdr = do_QueryElementAt(m_srcHdrs, i);
           NS_ASSERTION(oldHdr, "fatal ... cannot get old msg header\n");
           rv = srcDB->CopyHdrFromExistingHdr(m_srcKeyArray.GetAt(i),
                                              oldHdr,PR_TRUE,
                                              getter_AddRefs(newHdr));
           NS_ASSERTION(newHdr, "fatal ... cannot create new header\n");
                     
           if (NS_SUCCEEDED(rv) && newHdr)
           {
                      if (i < m_srcSizeArray.GetSize())
                newHdr->SetMessageSize(m_srcSizeArray.GetAt(i));
                srcDB->UndoDelete(newHdr);
                 }
        }
        srcDB->SetSummaryValid(PR_TRUE);
        return NS_OK; // always return NS_OK
    }
    else
    {
        rv = NS_ERROR_FAILURE;
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in nsImapOfflineTxn.

Definition at line 147 of file nsImapUndoTxn.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIImapService> imapService = do_GetService(NS_IMAPSERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  if (m_isMove || !m_dstFolder)
  {
    if (m_srcIsPop3)
    {
      rv = UndoMailboxDelete();
      if (NS_FAILED(rv)) return rv;
    }
    else
    {
      nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
      if (NS_FAILED(rv) || !srcFolder) 
        return rv;
      nsCOMPtr<nsIUrlListener> srcListener =
        do_QueryInterface(srcFolder, &rv);
      if (NS_FAILED(rv)) 
        return rv;
      // ** make sure we are in the selected state; use lite select
      // folder so we won't hit performance hard
      rv = imapService->LiteSelectFolder(m_eventQueue, srcFolder,
        srcListener, nsnull);
      if (NS_FAILED(rv)) 
        return rv;
      PRBool deletedMsgs = PR_TRUE; //default is true unless imapDelete model
      nsMsgImapDeleteModel deleteModel;
      rv = GetImapDeleteModel(srcFolder, &deleteModel);

      // 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;

      if (NS_SUCCEEDED(rv) && deleteModel == nsMsgImapDeleteModels::IMAPDelete)
        CheckForToggleDelete(srcFolder, m_srcKeyArray.GetAt(0), &deletedMsgs);

      if (deletedMsgs)
        rv = imapService->SubtractMessageFlags(
             m_eventQueue, srcFolder, srcListener, nsnull,
             m_srcMsgIdString.get(), kImapMsgDeletedFlag,
             m_idsAreUids);
      else
        rv = imapService->AddMessageFlags(m_eventQueue, srcFolder,
                                          srcListener, nsnull,
                                          m_srcMsgIdString.get(),
                                          kImapMsgDeletedFlag,
                                          m_idsAreUids);
      if (NS_FAILED(rv)) 
        return rv;

      if (deleteModel != nsMsgImapDeleteModels::IMAPDelete)
        rv = imapService->GetHeaders(m_eventQueue, srcFolder,
        srcListener, nsnull,
        m_srcMsgIdString.get(),
        PR_TRUE); 
    }
  }
  if (!m_dstMsgIdString.IsEmpty())
  {
    nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
    if (NS_FAILED(rv) || !dstFolder) return rv;
    
    nsCOMPtr<nsIUrlListener> dstListener;
    
    dstListener = do_QueryInterface(dstFolder, &rv);
    if (NS_FAILED(rv)) return rv;
    // ** make sure we are in the selected state; use lite select folder
    // so we won't potentially download a bunch of headers.
    rv = imapService->LiteSelectFolder(m_eventQueue, dstFolder,
      dstListener, nsnull);
    if (NS_FAILED(rv)) return rv;
    rv = imapService->AddMessageFlags(m_eventQueue, dstFolder,
      dstListener, nsnull,
      m_dstMsgIdString.get(),
      kImapMsgDeletedFlag,
      m_idsAreUids);
  }
  return rv;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 95 of file nsImapUndoTxn.h.

Definition at line 96 of file nsImapUndoTxn.h.

nsMsgKeyArray nsImapMoveCopyMsgTxn::m_dupKeyArray [protected]

Definition at line 92 of file nsImapUndoTxn.h.

Definition at line 97 of file nsImapUndoTxn.h.

Definition at line 99 of file nsImapUndoTxn.h.

Definition at line 100 of file nsImapUndoTxn.h.

Definition at line 90 of file nsImapUndoTxn.h.

Definition at line 91 of file nsImapUndoTxn.h.

Definition at line 101 of file nsImapUndoTxn.h.

nsMsgKeyArray nsImapMoveCopyMsgTxn::m_srcKeyArray [protected]

Definition at line 93 of file nsImapUndoTxn.h.

Definition at line 94 of file nsImapUndoTxn.h.

nsUInt32Array nsImapMoveCopyMsgTxn::m_srcSizeArray [protected]

Definition at line 102 of file nsImapUndoTxn.h.

Definition at line 98 of file nsImapUndoTxn.h.


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