diff --git a/src/imapmanager.cpp b/src/imapmanager.cpp index ff37b86..e2cebe0 100644 --- a/src/imapmanager.cpp +++ b/src/imapmanager.cpp @@ -621,10 +621,14 @@ void ImapManager::Process() } } + const bool isRequestsEmpty = m_Requests.empty(); m_QueueMutex.unlock(); - ClearStatus(Status::FlagFetching); - m_QueueMutex.lock(); + if (isRequestsEmpty) + { + ClearStatus(Status::FlagFetching); + } + m_QueueMutex.lock(); progress = 0; while (m_Actions.empty() && m_Requests.empty() && !m_PrefetchRequests.empty() && m_Running && isConnected && !authRefreshNeeded) @@ -682,8 +686,12 @@ void ImapManager::Process() } } + const bool isPrefetchRequestsEmpty = m_PrefetchRequests.empty(); m_QueueMutex.unlock(); - ClearStatus(Status::FlagPrefetching); + if (isPrefetchRequestsEmpty) + { + ClearStatus(Status::FlagPrefetching); + } if (!isConnected) { diff --git a/src/nmail.1 b/src/nmail.1 index 6898ea9..35245d1 100644 --- a/src/nmail.1 +++ b/src/nmail.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NMAIL "1" "August 2024" "nmail 5.1.10" "User Commands" +.TH NMAIL "1" "August 2024" "nmail 5.1.11" "User Commands" .SH NAME nmail \- ncurses mail .SH SYNOPSIS diff --git a/src/status.cpp b/src/status.cpp index c243acc..7421fbe 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -62,18 +62,10 @@ std::string Status::ToString() { str = "Checking"; } - else if (m_Flags & FlagFetching) - { - str = "Fetching" + GetProgressString(); - } else if (m_Flags & FlagSending) { str = "Sending"; } - else if (m_Flags & FlagPrefetching) - { - str = "Pre-fetching" + GetProgressString(); - } else if (m_Flags & FlagMoving) { str = "Moving"; @@ -90,6 +82,14 @@ std::string Status::ToString() { str = "Saving"; } + else if (m_Flags & FlagFetching) + { + str = "Fetching" + GetProgressString(); + } + else if (m_Flags & FlagPrefetching) + { + str = "Pre-fetching" + GetProgressString(); + } else if (m_Flags & FlagIndexing) { str = "Indexing" + GetProgressString(); diff --git a/src/ui.cpp b/src/ui.cpp index 217e885..63ab9f3 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -3978,14 +3978,13 @@ void Ui::ResponseHandler(const ImapManager::Request& p_Request, const ImapManage break; } - if (!m_HasPrefetchRequestedUids[folder]) + // Allow re-fetching folder uids, to enable full sync more than once per session { ImapManager::Request request; request.m_PrefetchLevel = PrefetchLevelFullSync; request.m_Folder = folder; request.m_GetUids = true; LOG_DEBUG_VAR("prefetch req uids =", folder); - m_HasPrefetchRequestedUids[folder] = true; m_ImapManager->PrefetchRequest(request); } } @@ -4356,9 +4355,33 @@ void Ui::StatusHandler(const StatusUpdate& p_StatusUpdate) std::lock_guard lock(m_Mutex); m_Status.Update(p_StatusUpdate); + // Update sync state + if (m_SyncState != SyncStateIdle) + { + if (m_SyncState == SyncStateStarted) + { + if (m_Status.IsSet(Status::FlagPrefetching)) + { + m_SyncState = SyncStateInProgress; + } + } + else if (m_SyncState == SyncStateInProgress) + { + if (!m_Status.IsSet(Status::FlagPrefetching)) + { + LOG_DEBUG("sync completed"); + m_SyncState = SyncStateIdle; + } + } + } + + // Auto-start full sync on connected, if configured for full sync if (!m_HasRequestedFolders && !m_HasPrefetchRequestedFolders && (m_PrefetchLevel >= PrefetchLevelFullSync) && (p_StatusUpdate.SetFlags & Status::FlagConnected)) { + LOG_DEBUG("sync started (auto)"); + m_SyncState = SyncStateStarted; + ImapManager::Request request; request.m_PrefetchLevel = PrefetchLevelFullSync; request.m_GetFolders = true; @@ -5974,29 +5997,27 @@ int Ui::GetCurrentHeaderField() void Ui::StartSync() { - if (IsConnected()) + if (m_SyncState != SyncStateIdle) { - if (m_PrefetchLevel < PrefetchLevelFullSync) - { - LOG_DEBUG("manual full sync started"); - m_PrefetchLevel = PrefetchLevelFullSync; - - ImapManager::Request request; - request.m_PrefetchLevel = PrefetchLevelFullSync; - request.m_GetFolders = true; - LOG_DEBUG("prefetch req folders"); - m_HasPrefetchRequestedFolders = true; - m_ImapManager->PrefetchRequest(request); - } - else - { - SetDialogMessage("Sync already enabled", true /* p_Warn */); - } + SetDialogMessage("Sync already in progress", true /* p_Warn */); + return; } - else + + if (!IsConnected()) { SetDialogMessage("Cannot sync while offline", true /* p_Warn */); + return; } + + LOG_DEBUG("sync started (manual)"); + m_SyncState = SyncStateStarted; + + ImapManager::Request request; + request.m_PrefetchLevel = PrefetchLevelFullSync; + request.m_GetFolders = true; + LOG_DEBUG("prefetch req folders"); + m_HasPrefetchRequestedFolders = true; + m_ImapManager->PrefetchRequest(request); } std::string Ui::MakeHtmlPart(const std::string& p_Text) diff --git a/src/ui.h b/src/ui.h index a9e15ce..d4d62b2 100644 --- a/src/ui.h +++ b/src/ui.h @@ -94,6 +94,13 @@ class Ui LineWrapHardWrap = 2, }; + enum SyncState + { + SyncStateIdle = 0, + SyncStateStarted = 1, + SyncStateInProgress = 2, + }; + Ui(const std::string& p_Inbox, const std::string& p_Address, const std::string& p_Name, uint32_t p_PrefetchLevel, bool p_PrefetchAllHeaders); virtual ~Ui(); @@ -280,10 +287,10 @@ class Ui std::map> m_DisplayUidsVersion; std::map m_HeaderUidsVersion; + SyncState m_SyncState = SyncStateIdle; bool m_HasRequestedFolders = false; bool m_HasPrefetchRequestedFolders = false; std::map m_HasRequestedUids; - std::map m_HasPrefetchRequestedUids; std::map> m_PrefetchedHeaders; std::map> m_RequestedHeaders; diff --git a/src/version.cpp b/src/version.cpp index fb6dc80..e825d78 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -7,7 +7,7 @@ #include "version.h" -#define NMAIL_VERSION "5.1.10" +#define NMAIL_VERSION "5.1.11" std::string Version::GetBuildOs() {