Back to index

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

#include <nsImapUndoTxn.h>

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

List of all members.

Public Member Functions

 nsImapOfflineTxn (nsIMsgFolder *srcFolder, nsMsgKeyArray *srcKeyArray, nsIMsgFolder *dstFolder, PRBool isMove, nsOfflineImapOperationType opType, nsIMsgDBHdr *srcHdr, nsIEventQueue *eventQueue, nsIUrlListener *urlListener)
virtual ~nsImapOfflineTxn ()
NS_IMETHOD UndoTransaction (void)
NS_IMETHOD RedoTransaction (void)
void SetAddFlags (PRBool addFlags)
void SetFlags (PRUint32 flags)
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

nsOfflineImapOperationType m_opType
nsCOMPtr< nsIMsgDBHdrm_header
PRBool m_addFlags
PRUint32 m_flags
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 107 of file nsImapUndoTxn.h.


Constructor & Destructor Documentation

nsImapOfflineTxn::nsImapOfflineTxn ( nsIMsgFolder srcFolder,
nsMsgKeyArray *  srcKeyArray,
nsIMsgFolder dstFolder,
PRBool  isMove,
nsOfflineImapOperationType  opType,
nsIMsgDBHdr srcHdr,
nsIEventQueue eventQueue,
nsIUrlListener urlListener 
)

Definition at line 438 of file nsImapUndoTxn.cpp.

{
  Init(srcFolder, srcKeyArray, nsnull, dstFolder, PR_TRUE,
       isMove, eventQueue, urlListener);

  m_opType = opType; 
  m_flags = 0;
  m_addFlags = PR_FALSE;
  m_header = srcHdr;
  if (opType == nsIMsgOfflineImapOperation::kDeletedMsg)
  {
    nsCOMPtr <nsIMsgDatabase> srcDB;
    nsCOMPtr <nsIDBFolderInfo> folderInfo;

    nsresult rv = srcFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(srcDB));
    if (NS_SUCCEEDED(rv) && srcDB)
    {
      nsMsgKey pseudoKey;
      nsCOMPtr <nsIMsgDBHdr> copySrcHdr;

      srcDB->GetNextPseudoMsgKey(&pseudoKey);
      pseudoKey--;
      m_dupKeyArray.SetAt(0, 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);
      }
    }
  }
}

Here is the call graph for this function:

Definition at line 474 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;
}
nsresult nsImapMoveCopyMsgTxn::GetImapDeleteModel ( nsIMsgFolder aFolder,
nsMsgImapDeleteModel aDeleteModel 
) [protected, inherited]

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) [inherited]

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 
) [inherited]

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 from nsImapMoveCopyMsgTxn.

Definition at line 549 of file nsImapUndoTxn.cpp.

{
  nsresult rv;
  
  nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
  if (NS_FAILED(rv) || !srcFolder) 
    return rv;
  nsCOMPtr <nsIMsgOfflineImapOperation> op;
  nsCOMPtr <nsIDBFolderInfo> folderInfo;
  nsCOMPtr <nsIMsgDatabase> srcDB;
  nsCOMPtr <nsIMsgDatabase> destDB;
  rv = srcFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(srcDB));
  NS_ENSURE_SUCCESS(rv, rv);
  nsMsgKey hdrKey = nsMsgKey_None;

  if (m_header)
    m_header->GetMessageKey(&hdrKey);

  switch (m_opType)
  {
  case nsIMsgOfflineImapOperation::kMsgMoved:
  case nsIMsgOfflineImapOperation::kMsgCopy:
    rv = srcDB->GetOfflineOpForKey(hdrKey, PR_FALSE, getter_AddRefs(op));
    if (NS_SUCCEEDED(rv) && op)
    {
      nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
      if (dstFolder)
      {
        nsXPIDLCString folderURI;
        dstFolder->GetURI(getter_Copies(folderURI));


        if (m_opType == nsIMsgOfflineImapOperation::kMsgMoved)
        {
          op->SetDestinationFolderURI(folderURI); // offline move
        }
        if (m_opType == nsIMsgOfflineImapOperation::kMsgCopy)
        {
          op->SetOperation(nsIMsgOfflineImapOperation::kMsgMoved);
          op->AddMessageCopyOperation(folderURI); // offline copy
        }
        dstFolder->SummaryChanged();
      }
    }
    break;
  case nsIMsgOfflineImapOperation::kAddedHeader:
    {
      nsCOMPtr <nsIMsgDBHdr> restoreHdr;
      nsMsgKey msgKey;
      m_header->GetMessageKey(&msgKey);
      nsCOMPtr<nsIMsgFolder> dstFolder = do_QueryReferent(m_dstFolder, &rv);
      rv = srcFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(destDB));
      NS_ENSURE_SUCCESS(rv, rv);
      if (m_header)
        destDB->CopyHdrFromExistingHdr (msgKey, m_header, PR_TRUE, getter_AddRefs(restoreHdr));
      destDB->Close(PR_TRUE);
      dstFolder->SummaryChanged();
      rv = destDB->GetOfflineOpForKey(hdrKey, PR_TRUE, getter_AddRefs(op));
      if (NS_SUCCEEDED(rv) && op)
      {
        nsXPIDLCString folderURI;
        srcFolder->GetURI(getter_Copies(folderURI));
        op->SetSourceFolderURI(folderURI);
      }
      dstFolder->SummaryChanged();
      destDB->Close(PR_TRUE);
    }
    break;
  case nsIMsgOfflineImapOperation::kDeletedMsg:
    srcDB->DeleteMessage(hdrKey, nsnull, PR_TRUE);
    break;
  case nsIMsgOfflineImapOperation::kMsgMarkedDeleted:
    srcDB->MarkImapDeleted(hdrKey, PR_TRUE, nsnull);
    break;
  case nsIMsgOfflineImapOperation::kFlagsChanged:
    rv = srcDB->GetOfflineOpForKey(hdrKey, PR_TRUE, getter_AddRefs(op));
    if (NS_SUCCEEDED(rv) && op)
    {
      imapMessageFlagsType newMsgFlags;
      op->GetNewFlags(&newMsgFlags);
      if (m_addFlags)
        op->SetFlagOperation(newMsgFlags | m_flags);
      else
        op->SetFlagOperation(newMsgFlags & ~m_flags);
    }
    break;
  default:
    break;
  }
  srcDB->Close(PR_TRUE);
  srcDB = nsnull;
  srcFolder->SummaryChanged();
  return NS_OK;
}

Here is the call graph for this function:

void nsImapOfflineTxn::SetAddFlags ( PRBool  addFlags) [inline]

Definition at line 121 of file nsImapUndoTxn.h.

{m_addFlags = addFlags;}
nsresult nsImapMoveCopyMsgTxn::SetCopyResponseUid ( const char *  msgIdString) [inherited]

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 122 of file nsImapUndoTxn.h.

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 from nsImapMoveCopyMsgTxn.

Definition at line 481 of file nsImapUndoTxn.cpp.

{
  nsresult rv;
  
  nsCOMPtr<nsIMsgFolder> srcFolder = do_QueryReferent(m_srcFolder, &rv);
  if (NS_FAILED(rv) || !srcFolder) 
    return rv;
  nsCOMPtr <nsIMsgOfflineImapOperation> op;
  nsCOMPtr <nsIDBFolderInfo> folderInfo;
  nsCOMPtr <nsIMsgDatabase> srcDB;
  nsCOMPtr <nsIMsgDatabase> destDB;

  nsMsgKey hdrKey = nsMsgKey_None;

  if (m_header)
    m_header->GetMessageKey(&hdrKey);

  rv = srcFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(srcDB));
  NS_ENSURE_SUCCESS(rv, rv);
  switch (m_opType)
  {
    case nsIMsgOfflineImapOperation::kMsgMoved:
    case nsIMsgOfflineImapOperation::kMsgCopy:
    case nsIMsgOfflineImapOperation::kAddedHeader:
    case nsIMsgOfflineImapOperation::kFlagsChanged:
      rv = srcDB->GetOfflineOpForKey(hdrKey, PR_FALSE, getter_AddRefs(op));
      if (NS_SUCCEEDED(rv) && op)
      {
        srcDB->RemoveOfflineOp(op);
        op = nsnull;
      }
      if (m_header && (m_opType == nsIMsgOfflineImapOperation::kAddedHeader))
      {
        nsCOMPtr <nsIMsgDBHdr> mailHdr;
        nsMsgKey msgKey;
        m_header->GetMessageKey(&msgKey);
        rv = srcDB->GetMsgHdrForKey(msgKey, getter_AddRefs(mailHdr));
        if (mailHdr)
          srcDB->DeleteHeader(mailHdr, nsnull, PR_TRUE, PR_FALSE);
      }
      break;
    case nsIMsgOfflineImapOperation::kDeletedMsg:
      {
        nsMsgKey msgKey;
        m_header->GetMessageKey(&msgKey);
       nsCOMPtr<nsIMsgDBHdr> undeletedHdr;
        m_srcHdrs->QueryElementAt(0, NS_GET_IID(nsIMsgDBHdr), getter_AddRefs(undeletedHdr));
        if (undeletedHdr)
        {
          nsCOMPtr <nsIMsgDBHdr> newHdr;

          srcDB->CopyHdrFromExistingHdr (msgKey, undeletedHdr, PR_TRUE, getter_AddRefs(newHdr));
        }
        srcDB->Close(PR_TRUE);
        srcFolder->SummaryChanged();
      }
      break;
    case nsIMsgOfflineImapOperation::kMsgMarkedDeleted:
      srcDB->MarkImapDeleted(hdrKey, PR_FALSE, nsnull);
      break;
    default:
      break;
  }
  srcDB->Close(PR_TRUE);
  srcFolder->SummaryChanged();
  return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 127 of file nsImapUndoTxn.h.

Definition at line 95 of file nsImapUndoTxn.h.

Definition at line 96 of file nsImapUndoTxn.h.

nsMsgKeyArray nsImapMoveCopyMsgTxn::m_dupKeyArray [protected, inherited]

Definition at line 92 of file nsImapUndoTxn.h.

Definition at line 97 of file nsImapUndoTxn.h.

Definition at line 128 of file nsImapUndoTxn.h.

Definition at line 125 of file nsImapUndoTxn.h.

Definition at line 99 of file nsImapUndoTxn.h.

PRBool nsImapMoveCopyMsgTxn::m_isMove [protected, inherited]

Definition at line 100 of file nsImapUndoTxn.h.

Definition at line 124 of file nsImapUndoTxn.h.

Definition at line 90 of file nsImapUndoTxn.h.

Definition at line 91 of file nsImapUndoTxn.h.

PRBool nsImapMoveCopyMsgTxn::m_srcIsPop3 [protected, inherited]

Definition at line 101 of file nsImapUndoTxn.h.

nsMsgKeyArray nsImapMoveCopyMsgTxn::m_srcKeyArray [protected, inherited]

Definition at line 93 of file nsImapUndoTxn.h.

Definition at line 94 of file nsImapUndoTxn.h.

nsUInt32Array nsImapMoveCopyMsgTxn::m_srcSizeArray [protected, inherited]

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: