Skip to content

Commit

Permalink
allow full sync more than once per session
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Aug 10, 2024
1 parent bb061d4 commit 705fb8f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 34 deletions.
14 changes: 11 additions & 3 deletions src/imapmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down
61 changes: 41 additions & 20 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -4356,9 +4355,33 @@ void Ui::StatusHandler(const StatusUpdate& p_StatusUpdate)
std::lock_guard<std::mutex> 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;
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -280,10 +287,10 @@ class Ui
std::map<std::string, std::map<SortFilter, uint64_t>> m_DisplayUidsVersion;
std::map<std::string, uint64_t> m_HeaderUidsVersion;

SyncState m_SyncState = SyncStateIdle;
bool m_HasRequestedFolders = false;
bool m_HasPrefetchRequestedFolders = false;
std::map<std::string, bool> m_HasRequestedUids;
std::map<std::string, bool> m_HasPrefetchRequestedUids;
std::map<std::string, std::set<uint32_t>> m_PrefetchedHeaders;
std::map<std::string, std::set<uint32_t>> m_RequestedHeaders;

Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "5.1.10"
#define NMAIL_VERSION "5.1.11"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit 705fb8f

Please sign in to comment.