From 1cf067c045428514784bda4de7e3d39761e60ab0 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Tue, 30 Sep 2025 13:34:44 -0300 Subject: [PATCH] feat: Always watch Inbox if MvboxMove is set (#7187) If `OnlyFetchMvbox` is enabled, `MvboxMove` ("Move automatically to DeltaChat folder") makes no sense: useful messages from "Spam" are moved anyway to "DeltaChat" (see `imap::spam_target_folder_cfg()`) and Inbox messages aren't fetched and moved. Then `MvboxMove` can mean "Move Inbox and all scanned folders' messages to DeltaChat", so if it's enabled, Inbox is watched too, so the user can configure fetching only from "Inbox", "DeltaChat" and "Spam" which was unachievable before and helps e.g. for the Gmail case which has many virtual folders and the whole folder scanning process is really slow (and useless for most users): https://github.com/chatmail/core/issues/7178#issuecomment-3266343253. This may also be useful if the user has another messenger, e.g. a Delta Chat fork who moves messages to "ZetaChat": this folder shouldn't be scanned, but Inbox should be. Mvbox is watched anyway, this should just be made clear to users (if not already). For existing users accidentally having both options enabled "MvboxMove" is disabled in a migration to not cause watching Inbox. Having both options disabled means that we don't separate chat messages from non-chat ones, scanning all folders is fine in this case. --- src/config.rs | 4 ++-- src/imap.rs | 9 ++++++--- src/imap/scan_folders.rs | 6 +++++- src/sql/migrations.rs | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9f071c85d..c26e130b3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -165,10 +165,10 @@ pub enum Config { #[strum(props(default = "1"))] MvboxMove, - /// Watch for new messages in the "Mvbox" (aka DeltaChat folder) only. + /// Only watch the mvbox (aka DeltaChat folder) and, if `MvboxMove` is set, Inbox. /// /// This will not entirely disable other folders, e.g. the spam folder will also still - /// be watched for new messages. + /// be scanned for new messages. #[strum(props(default = "0"))] OnlyFetchMvbox, diff --git a/src/imap.rs b/src/imap.rs index 6188fd6f5..bc3213e6c 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -2041,9 +2041,9 @@ async fn spam_target_folder_cfg( } if needs_move_to_mvbox(context, headers).await? - // If OnlyFetchMvbox is set, we don't want to move the message to - // the inbox or sentbox where we wouldn't fetch it again: - || context.get_config_bool(Config::OnlyFetchMvbox).await? + // Don't move the message to Inbox if we won't fetch the message again there. + || (context.get_config_bool(Config::OnlyFetchMvbox).await? + && !context.get_config_bool(Config::MvboxMove).await?) { Ok(Some(Config::ConfiguredMvboxFolder)) } else { @@ -2570,6 +2570,9 @@ async fn should_ignore_folder( // Still respect the SentboxWatch setting. return Ok(!context.get_config_bool(Config::SentboxWatch).await?); } + if context.is_inbox(folder).await? { + return Ok(!context.get_config_bool(Config::MvboxMove).await?); + } Ok(!(context.is_mvbox(folder).await? || folder_meaning == FolderMeaning::Spam)) } diff --git a/src/imap/scan_folders.rs b/src/imap/scan_folders.rs index e500f719e..c6d76b1cf 100644 --- a/src/imap/scan_folders.rs +++ b/src/imap/scan_folders.rs @@ -71,9 +71,13 @@ impl Imap { _ => folder_meaning, }; - // Don't scan folders that are watched anyway if !watched_folders.contains(&folder.name().to_string()) + // Inbox shouldn't be scanned, getting messages from Inbox delayed doesn't make + // sense, the user should enable watching it instead. + && folder_meaning != FolderMeaning::Inbox && folder_meaning != FolderMeaning::Trash + && (folder_meaning != FolderMeaning::Unknown + || !context.get_config_bool(Config::OnlyFetchMvbox).await?) { self.fetch_move_delete(context, session, folder.name(), folder_meaning) .await diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 6bd56c91c..116a2a0ef 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -1328,6 +1328,20 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint); .await?; } + inc_and_check(&mut migration_version, 138)?; + if dbversion < migration_version { + // `MvboxMove` now means "watch Inbox also and move chat messages from it". Preserve the old + // behavior for `OnlyFetchMvbox` users. + sql.execute_migration( + "INSERT OR REPLACE INTO config (keyname, value) + SELECT 'mvbox_move', '0' + FROM config WHERE keyname='only_fetch_mvbox' AND value!='0' + ", + migration_version, + ) + .await?; + } + let new_version = sql .get_raw_config_int(VERSION_CFG) .await?