void ImapSession::SyncFolder(const MojObject& folderId, SyncParams syncParams) { // TODO: make sure this is the right folder, or switch folders if necessary MojObject status; syncParams.Status(status); MojLogInfo(m_log, "ImapSession::SyncFolder called on %s with sync params %s", AsJsonString(folderId).c_str(), AsJsonString(status).c_str()); // Set bind address for interface to connect to next time we connect. // This won't apply if we're already connected. if(!IsConnected() && !syncParams.GetBindAddress().empty()) { m_connectBindAddress = syncParams.GetBindAddress(); } if(syncParams.GetForceReconnect()) { m_reconnectRequested = true; } // Manual sync of the inbox should resync the folder list if(syncParams.GetForce() && m_account->GetInboxFolderId() == folderId) { syncParams.SetSyncFolderList(true); } // Check if we should re-sync the folder list if(syncParams.GetSyncFolderList() && IsConnected()) { MojRefCountedPtr<SyncFolderListCommand> command(new SyncFolderListCommand(*this)); m_commandManager->QueueCommand(command, false); } MojRefCountedPtr<ImapSyncSessionCommand> syncCommand; syncCommand.reset(new SyncEmailsCommand(*this, folderId, syncParams)); // Check if a similar request has already been queued MojRefCountedPtr<ImapCommand> pendingCommand = FindPendingCommand(syncCommand); if (pendingCommand.get()) { MojLogInfo(m_log, "debouncing sync request; a similar request is already queued"); CheckQueue(); return; } // If we're just syncing local changes, and there's already a sync session, debounce it. if (syncParams.GetSyncChanges() && !syncParams.GetSyncEmails()) { MojRefCountedPtr<SyncSession> syncSession = m_client->GetSyncSession(folderId); if (syncSession.get() && syncSession->IsActive()) { MojLogInfo(m_log, "debouncing sync local changes; a sync session is active"); return; } } if(syncParams.GetSyncChanges() && !syncParams.GetSyncEmails()) { // Just upload changes syncCommand.reset(new SyncLocalChangesCommand(*this, folderId)); m_commandManager->QueueCommand(syncCommand, false); m_recentUserInteraction = true; } else if(syncParams.GetSyncEmails()) { // Sync emails m_commandManager->QueueCommand(syncCommand, false); } else { // just check the queue syncCommand.reset(); } if(syncCommand.get()) { // Start sync session m_client->AddToSyncSession(m_folderId, syncCommand.get()); m_client->StartSyncSession(m_folderId, syncParams.GetSyncActivities()); } CheckQueue(); }