From ca5227f535dd9d5932e3f3d23066e3cccdacc236 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Tue, 6 Aug 2024 13:29:22 -0300 Subject: [PATCH] refactor: Make `MvboxMove` a dependent setting of `IsChatmail` This makes the code more straightforward in some places and also allows to keep `MvboxMove` unset for chatmail case and thus know that the user hasn't modified it. --- src/config.rs | 20 ++++++++++++++++++-- src/configure.rs | 1 - src/imap.rs | 9 ++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 08c884589a..8fca2931bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -137,7 +137,6 @@ pub enum Config { /// True if chat messages should be moved to a separate folder. Auto-sent messages like sync /// ones are moved there anyway. - #[strum(props(default = "1"))] MvboxMove, /// Watch for new messages in the "Mvbox" (aka DeltaChat folder) only. @@ -491,9 +490,17 @@ impl Context { Ok(self.get_config_bool_opt(key).await?.unwrap_or_default()) } + /// Returns true if chat messages should be moved to the mvbox ("DeltaChat" folder). + pub(crate) async fn should_move_to_mvbox(&self) -> Result { + match self.get_config_bool_opt(Config::MvboxMove).await? { + Some(val) => Ok(val), + None => Ok(!self.get_config_bool(Config::IsChatmail).await?), + } + } + /// Returns true if movebox ("DeltaChat" folder) should be watched. pub(crate) async fn should_watch_mvbox(&self) -> Result { - Ok(self.get_config_bool(Config::MvboxMove).await? + Ok(self.should_move_to_mvbox().await? || self.get_config_bool(Config::OnlyFetchMvbox).await? || !self.get_config_bool(Config::IsChatmail).await?) } @@ -990,6 +997,15 @@ mod tests { Ok(()) } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_should_move_to_mvbox() -> Result<()> { + let alice = &TestContext::new_alice().await; + assert!(alice.should_move_to_mvbox().await?); + alice.set_config_bool(Config::IsChatmail, true).await?; + assert!(!alice.should_move_to_mvbox().await?); + Ok(()) + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_sync() -> Result<()> { let alice0 = TestContext::new_alice().await; diff --git a/src/configure.rs b/src/configure.rs index 9103c90be5..804daa8bfd 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -433,7 +433,6 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> { }; if is_chatmail { ctx.set_config(Config::SentboxWatch, None).await?; - ctx.set_config(Config::MvboxMove, Some("0")).await?; ctx.set_config(Config::OnlyFetchMvbox, None).await?; ctx.set_config(Config::ShowEmails, None).await?; ctx.set_config(Config::E2eeEnabled, Some("1")).await?; diff --git a/src/imap.rs b/src/imap.rs index c189c00dde..01133063c3 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -437,7 +437,10 @@ impl Imap { false => session.is_chatmail(), true => context.get_config_bool(Config::IsChatmail).await?, }; - let create_mvbox = !is_chatmail || context.get_config_bool(Config::MvboxMove).await?; + let create_mvbox = context + .get_config_bool_opt(Config::MvboxMove) + .await? + .unwrap_or(!is_chatmail); self.configure_folders(context, &mut session, create_mvbox) .await?; } @@ -1615,7 +1618,7 @@ impl Imap { context .set_config_internal(Config::ConfiguredMvboxFolder, Some(mvbox_folder)) .await?; - } else if create_mvbox && context.config_exists(Config::MvboxMove).await? { + } else if context.get_config_bool_opt(Config::MvboxMove).await? == Some(true) { warn!(context, "Will retry configuring MVBOX on reconnect."); return Ok(()); } @@ -1814,7 +1817,7 @@ async fn needs_move_to_mvbox( } } } - if !context.get_config_bool(Config::MvboxMove).await? { + if !context.should_move_to_mvbox().await? { return Ok(false); }