nsresult nsMsgOfflineManager::SendUnsentMessages()
{
  nsresult rv;
  nsCOMPtr<nsIMsgSendLater> pMsgSendLater(do_GetService(kMsgSendLaterCID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIMsgAccountManager> accountManager = 
           do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  // now we have to iterate over the identities, finding the *unique* unsent messages folder
  // for each one, determine if they have unsent messages, and if so, add them to the list
  // of identities to send unsent messages from.
  // However, I think there's only ever one unsent messages folder at the moment,
  // so I think we'll go with that for now.
  nsCOMPtr<nsIArray> identities;

  if (NS_SUCCEEDED(rv) && accountManager)
  {
    rv = accountManager->GetAllIdentities(getter_AddRefs(identities));
    NS_ENSURE_SUCCESS(rv, rv);
  }
  nsCOMPtr <nsIMsgIdentity> identityToUse;
  uint32_t numIndentities;
  identities->GetLength(&numIndentities);
  for (uint32_t i = 0; i < numIndentities; i++)
  {
    nsCOMPtr<nsIMsgIdentity> thisIdentity(do_QueryElementAt(identities, i, &rv));
    if (NS_SUCCEEDED(rv) && thisIdentity)
    {
      nsCOMPtr <nsIMsgFolder> outboxFolder;
      pMsgSendLater->GetUnsentMessagesFolder(thisIdentity, getter_AddRefs(outboxFolder));
      if (outboxFolder)
      {
        int32_t numMessages;
        outboxFolder->GetTotalMessages(false, &numMessages);
        if (numMessages > 0)
        {
          identityToUse = thisIdentity;
          break;
        }
      }
    }
  }
  if (identityToUse) 
  { 
#ifdef MOZ_SUITE
    if (m_statusFeedback)
      pMsgSendLater->SetStatusFeedback(m_statusFeedback);
#endif

    pMsgSendLater->AddListener(this);
    rv = pMsgSendLater->SendUnsentMessages(identityToUse);
    ShowStatus("sendingUnsent");
    // if we succeeded, return - we'll run the next operation when the
    // send finishes. Otherwise, advance to the next state.
    if (NS_SUCCEEDED(rv))
      return rv;
  } 
  return AdvanceToNextState(rv);

}
예제 #2
0
NS_IMETHODIMP
nsMsgOfflineManager::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
{
    mOfflineImapSync = nullptr;

    AdvanceToNextState(aExitCode);
    return NS_OK;
}
예제 #3
0
NS_IMETHODIMP
nsMsgOfflineManager::OnStopSending(nsresult aStatus,
                                   const PRUnichar *aMsg, uint32_t aTotalTried,
                                   uint32_t aSuccessful)
{
#ifdef NS_DEBUG
    if (NS_SUCCEEDED(aStatus))
        printf("SendLaterListener::OnStopSending: Tried to send %d messages. %d successful.\n",
               aTotalTried, aSuccessful);
#endif
    return AdvanceToNextState(aStatus);
}
예제 #4
0
nsresult nsMsgOfflineManager::DownloadOfflineNewsgroups()
{
    nsresult rv;
    ShowStatus("downloadingNewsgroups");
    nsCOMPtr<nsINntpService> nntpService(do_GetService(NS_NNTPSERVICE_CONTRACTID, &rv));
    if (NS_SUCCEEDED(rv) && nntpService)
        rv = nntpService->DownloadNewsgroupsForOffline(m_window, this);

    if (NS_FAILED(rv))
        return AdvanceToNextState(rv);
    return rv;
}
예제 #5
0
/* void goOnline (in boolean sendUnsentMessages, in boolean playbackOfflineImapOperations, in nsIMsgWindow aMsgWindow); */
NS_IMETHODIMP nsMsgOfflineManager::GoOnline(bool sendUnsentMessages, bool playbackOfflineImapOperations, nsIMsgWindow *aMsgWindow)
{
    m_sendUnsentMessages = sendUnsentMessages;
    m_playbackOfflineImapOps = playbackOfflineImapOperations;
    m_curOperation = eGoingOnline;
    m_curState = eNoState;
    SetWindow(aMsgWindow);
    SetOnlineState(true);
    if (!m_sendUnsentMessages && !playbackOfflineImapOperations)
        return NS_OK;
    else
        AdvanceToNextState(NS_OK);
    return NS_OK;
}
예제 #6
0
/* void synchronizeForOffline (in boolean downloadNews, in boolean downloadMail, in boolean sendUnsentMessages, in boolean goOfflineWhenDone, in nsIMsgWindow aMsgWindow); */
NS_IMETHODIMP nsMsgOfflineManager::SynchronizeForOffline(bool downloadNews, bool downloadMail, bool sendUnsentMessages, bool goOfflineWhenDone, nsIMsgWindow *aMsgWindow)
{
    m_curOperation = eDownloadingForOffline;
    m_downloadNews = downloadNews;
    m_downloadMail = downloadMail;
    m_sendUnsentMessages = sendUnsentMessages;
    SetWindow(aMsgWindow);
    m_goOfflineWhenDone = goOfflineWhenDone;
    m_curState = eNoState;
    if (!downloadNews && !downloadMail && !sendUnsentMessages)
    {
        if (goOfflineWhenDone)
            return SetOnlineState(false);
    }
    else
        return AdvanceToNextState(NS_OK);
    return NS_OK;
}
예제 #7
0
nsresult nsMsgOfflineManager::AdvanceToNextState(nsresult exitStatus)
{
    // NS_BINDING_ABORTED is used for the user pressing stop, which
    // should cause us to abort the offline process. Other errors
    // should allow us to continue.
    if (exitStatus == NS_BINDING_ABORTED)
    {
        return StopRunning(exitStatus);
    }
    if (m_curOperation == eGoingOnline)
    {
        switch (m_curState)
        {
        case eNoState:

            m_curState = eSendingUnsent;
            if (m_sendUnsentMessages)
            {
                SendUnsentMessages();
            }
            else
                AdvanceToNextState(NS_OK);
            break;
        case eSendingUnsent:

            m_curState = eSynchronizingOfflineImapChanges;
            if (m_playbackOfflineImapOps)
                return SynchronizeOfflineImapChanges();
            else
                AdvanceToNextState(NS_OK); // recurse to next state.
            break;
        case eSynchronizingOfflineImapChanges:
            m_curState = eDone;
            return StopRunning(exitStatus);
        default:
            NS_ASSERTION(false, "unhandled current state when going online");
        }
    }
    else if (m_curOperation == eDownloadingForOffline)
    {
        switch (m_curState)
        {
        case eNoState:
            m_curState = eDownloadingNews;
            if (m_downloadNews)
                DownloadOfflineNewsgroups();
            else
                AdvanceToNextState(NS_OK);
            break;
        case eSendingUnsent:
            if (m_goOfflineWhenDone)
            {
                SetOnlineState(false);
            }
            break;
        case eDownloadingNews:
            m_curState = eDownloadingMail;
            if (m_downloadMail)
                DownloadMail();
            else
                AdvanceToNextState(NS_OK);
            break;
        case eDownloadingMail:
            m_curState = eSendingUnsent;
            if (m_sendUnsentMessages)
                SendUnsentMessages();
            else
                AdvanceToNextState(NS_OK);
            break;
        default:
            NS_ASSERTION(false, "unhandled current state when downloading for offline");
        }

    }
    return NS_OK;
}