Back to index

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

#include <nsMsgCopy.h>

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

List of all members.

Public Member Functions

 nsMsgCopy ()
virtual ~nsMsgCopy ()
NS_DECL_ISUPPORTS
NS_DECL_NSIURLLISTENER
nsresult 
StartCopyOperation (nsIMsgIdentity *aUserIdentity, nsIFileSpec *aFileSpec, nsMsgDeliverMode aMode, nsIMsgSend *aMsgSendObj, const char *aSavePref, nsIMsgDBHdr *aMsgToReplace)
nsresult DoCopy (nsIFileSpec *aDiskFile, nsIMsgFolder *dstFolder, nsIMsgDBHdr *aMsgToReplace, PRBool aIsDraft, nsIMsgWindow *msgWindow, nsIMsgSend *aMsgSendObj)
nsresult GetUnsentMessagesFolder (nsIMsgIdentity *userIdentity, nsIMsgFolder **msgFolder, PRBool *waitForUrl)
nsresult GetDraftsFolder (nsIMsgIdentity *userIdentity, nsIMsgFolder **msgFolder, PRBool *waitForUrl)
nsresult GetTemplatesFolder (nsIMsgIdentity *userIdentity, nsIMsgFolder **msgFolder, PRBool *waitForUrl)
nsresult GetSentFolder (nsIMsgIdentity *userIdentity, nsIMsgFolder **msgFolder, PRBool *waitForUrl)
nsresult CreateIfMissing (nsIMsgFolder **folder, PRBool *waitForUrl)
void OnStartRunningUrl (in nsIURI url)
void OnStopRunningUrl (in nsIURI url, in nsresult aExitCode)

Public Attributes

nsIFileSpecmFileSpec
nsMsgDeliverMode mMode
nsCOMPtr< CopyListenermCopyListener
nsCOMPtr< nsIMsgFoldermDstFolder
nsCOMPtr< nsIMsgDBHdrmMsgToReplace
PRBool mIsDraft
nsCOMPtr< nsIMsgSendmMsgSendObj
char * mSavePref

Detailed Description

Definition at line 93 of file nsMsgCopy.h.


Constructor & Destructor Documentation

nsMsgCopy::~nsMsgCopy ( ) [virtual]

Definition at line 184 of file nsMsgCopy.cpp.


Member Function Documentation

nsresult nsMsgCopy::CreateIfMissing ( nsIMsgFolder **  folder,
PRBool waitForUrl 
)

Definition at line 390 of file nsMsgCopy.cpp.

{
  nsresult ret = NS_OK;
  if (folder && *folder)
  {
    nsCOMPtr <nsIMsgFolder> parent;
    (*folder)->GetParent(getter_AddRefs(parent));
    if (!parent)
    {
      nsCOMPtr <nsIFileSpec> folderPath;
      // for local folders, path is to the berkeley mailbox. 
      // for imap folders, path needs to have .msf appended to the name
      (*folder)->GetPath(getter_AddRefs(folderPath));
        PRBool isImapFolder = !nsCRT::strncasecmp(mSavePref, "imap:", 5);
      // if we can't get the path from the folder, then try to create the storage.
      // for imap, it doesn't matter if the .msf file exists - it still might not
      // exist on the server, so we should try to create it
      PRBool exists = PR_FALSE;
      if (!isImapFolder && folderPath)
        folderPath->Exists(&exists);
        if (!exists)
        {
          (*folder)->CreateStorageIfMissing(this);
          if (isImapFolder)
            *waitForUrl = PR_TRUE;
 
          ret = NS_OK;
        }
      }
    }
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgCopy::DoCopy ( nsIFileSpec aDiskFile,
nsIMsgFolder dstFolder,
nsIMsgDBHdr aMsgToReplace,
PRBool  aIsDraft,
nsIMsgWindow msgWindow,
nsIMsgSend aMsgSendObj 
)

Definition at line 268 of file nsMsgCopy.cpp.

{
  nsresult rv = NS_OK;

  // Check sanity
  if ((!aDiskFile) || (!dstFolder))
    return NS_ERROR_INVALID_ARG;

  //Call copyservice with dstFolder, disk file, and txnManager
  if(NS_SUCCEEDED(rv))
  {
    CopyListener    *tPtr = new CopyListener();
    if (!tPtr)
      return NS_ERROR_OUT_OF_MEMORY;

    mCopyListener = do_QueryInterface(tPtr, &rv);
    if (NS_FAILED(rv) || !mCopyListener)
      return NS_ERROR_OUT_OF_MEMORY;

    mCopyListener->SetMsgComposeAndSendObject(aMsgSendObj);
    nsCOMPtr<nsIEventQueue> eventQueue;

    if (aIsDraft)
    {
        nsCOMPtr<nsIMsgImapMailFolder> imapFolder =
            do_QueryInterface(dstFolder);
        nsCOMPtr<nsIMsgAccountManager> accountManager = 
                 do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
        if (NS_FAILED(rv)) return rv;
        PRBool shutdownInProgress = PR_FALSE;
        rv = accountManager->GetShutdownInProgress(&shutdownInProgress);
        
        if (NS_SUCCEEDED(rv) && shutdownInProgress && imapFolder)
        { 
          // set the following only when we were in the middle of shutdown
          // process
            mCopyListener->mCopyObject = do_QueryInterface(tPtr);
            mCopyListener->mCopyInProgress = PR_TRUE;
            nsCOMPtr<nsIEventQueueService> pEventQService = 
                     do_GetService(kEventQueueServiceCID, &rv);
            if (NS_FAILED(rv)) return rv;
            pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,
                                                getter_AddRefs(eventQueue)); 
        }
    }
    // ** make sure we have a valid copy listener while waiting for copy
    // server to finish
    nsCOMPtr<CopyListener> aCopyListener = do_QueryInterface(tPtr);
    nsCOMPtr<nsIMsgCopyService> copyService = do_GetService(NS_MSGCOPYSERVICE_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = copyService->CopyFileMessage(aDiskFile, dstFolder, aMsgToReplace, 
                                      aIsDraft, MSG_FLAG_READ, mCopyListener, msgWindow);
    // aCopyListener->mCopyInProgress can only be set when we are in the
    // middle of the shutdown process
    while (aCopyListener->mCopyInProgress)
    {
        PR_CEnterMonitor(aCopyListener);
        PR_CWait(aCopyListener, PR_MicrosecondsToInterval(1000UL));
        PR_CExitMonitor(aCopyListener);
        if (eventQueue)
            eventQueue->ProcessPendingEvents();
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgCopy::GetDraftsFolder ( nsIMsgIdentity userIdentity,
nsIMsgFolder **  msgFolder,
PRBool waitForUrl 
)

Definition at line 366 of file nsMsgCopy.cpp.

{
  nsresult ret = LocateMessageFolder(userIdentity, nsIMsgSend::nsMsgSaveAsDraft, mSavePref, folder);
  CreateIfMissing(folder, waitForUrl);
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgCopy::GetSentFolder ( nsIMsgIdentity userIdentity,
nsIMsgFolder **  msgFolder,
PRBool waitForUrl 
)

Definition at line 382 of file nsMsgCopy.cpp.

{
  nsresult ret = LocateMessageFolder(userIdentity, nsIMsgSend::nsMsgDeliverNow, mSavePref, folder);
  CreateIfMissing(folder, waitForUrl);
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgCopy::GetTemplatesFolder ( nsIMsgIdentity userIdentity,
nsIMsgFolder **  msgFolder,
PRBool waitForUrl 
)

Definition at line 374 of file nsMsgCopy.cpp.

{
  nsresult ret = LocateMessageFolder(userIdentity, nsIMsgSend::nsMsgSaveAsTemplate, mSavePref, folder);
  CreateIfMissing(folder, waitForUrl);
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgCopy::GetUnsentMessagesFolder ( nsIMsgIdentity userIdentity,
nsIMsgFolder **  msgFolder,
PRBool waitForUrl 
)

Definition at line 358 of file nsMsgCopy.cpp.

{
  nsresult ret = LocateMessageFolder(userIdentity, nsIMsgSend::nsMsgQueueForLater, mSavePref, folder);
  CreateIfMissing(folder, waitForUrl);
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Here is the caller graph for this function:

void nsIUrlListener::OnStopRunningUrl ( in nsIURI  url,
in nsresult  aExitCode 
) [inherited]

Here is the caller graph for this function:

nsresult nsMsgCopy::StartCopyOperation ( nsIMsgIdentity aUserIdentity,
nsIFileSpec aFileSpec,
nsMsgDeliverMode  aMode,
nsIMsgSend aMsgSendObj,
const char *  aSavePref,
nsIMsgDBHdr aMsgToReplace 
)

Definition at line 190 of file nsMsgCopy.cpp.

{
  nsCOMPtr<nsIMsgFolder>  dstFolder;
  PRBool                  isDraft = PR_FALSE;
  PRBool                  waitForUrl = PR_FALSE;
  nsresult                rv;

  if (!aMsgSendObj)
    return NS_ERROR_INVALID_ARG;

  // Store away the server location...
  if (aSavePref)
    mSavePref = PL_strdup(aSavePref);

  //
  // Vars for implementation...
  //
  if (aMode == nsIMsgSend::nsMsgQueueForLater)       // QueueForLater (Outbox)
  {
    rv = GetUnsentMessagesFolder(aUserIdentity, getter_AddRefs(dstFolder), &waitForUrl);
    isDraft = PR_FALSE;
    if (!dstFolder || NS_FAILED(rv)) {
      return NS_MSG_UNABLE_TO_SEND_LATER;
    } 
  }
  else if (aMode == nsIMsgSend::nsMsgSaveAsDraft)    // SaveAsDraft (Drafts)
  {
    rv = GetDraftsFolder(aUserIdentity, getter_AddRefs(dstFolder), &waitForUrl);
    isDraft = PR_TRUE;
    if (!dstFolder || NS_FAILED(rv))
      return NS_MSG_UNABLE_TO_SAVE_DRAFT;
  }
  else if (aMode == nsIMsgSend::nsMsgSaveAsTemplate) // SaveAsTemplate (Templates)
  {
    rv = GetTemplatesFolder(aUserIdentity, getter_AddRefs(dstFolder), &waitForUrl);
    isDraft = PR_FALSE;
    if (!dstFolder || NS_FAILED(rv) || CHECK_SIMULATED_ERROR(SIMULATED_SEND_ERROR_5))
           return NS_MSG_UNABLE_TO_SAVE_TEMPLATE;
  }
  else // SaveInSentFolder (Sent) -  nsMsgDeliverNow or nsMsgSendUnsent
  {
    rv = GetSentFolder(aUserIdentity, getter_AddRefs(dstFolder), &waitForUrl);
    isDraft = PR_FALSE;
    if (!dstFolder || NS_FAILED(rv)) 
      return NS_MSG_COULDNT_OPEN_FCC_FOLDER;
  }

  nsCOMPtr <nsIMsgWindow> msgWindow;

  if (aMsgSendObj)
  {
    nsCOMPtr <nsIMsgProgress> progress;
    aMsgSendObj->GetProgress(getter_AddRefs(progress));
    if (progress)
      progress->GetMsgWindow(getter_AddRefs(msgWindow));
  }

  mMode = aMode;
  mFileSpec = aFileSpec;
  mDstFolder = dstFolder;
  mMsgToReplace = aMsgToReplace;
  mIsDraft = isDraft;
  mMsgSendObj = aMsgSendObj;
  if (!waitForUrl)
  {
    // cache info needed for DoCopy and call DoCopy when OnStopUrl is called.
    rv = DoCopy(aFileSpec, dstFolder, aMsgToReplace, isDraft, msgWindow, aMsgSendObj);
    // N.B. "this" may be deleted when this call returns.
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 134 of file nsMsgCopy.h.

Definition at line 135 of file nsMsgCopy.h.

Definition at line 132 of file nsMsgCopy.h.

Definition at line 137 of file nsMsgCopy.h.

Definition at line 133 of file nsMsgCopy.h.

Definition at line 138 of file nsMsgCopy.h.

Definition at line 136 of file nsMsgCopy.h.

Definition at line 139 of file nsMsgCopy.h.


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