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.
This commit is contained in:
iequidoo
2024-08-06 13:29:22 -03:00
parent a5d0d4c126
commit a16a7d6682
4 changed files with 24 additions and 6 deletions

View File

@@ -164,7 +164,6 @@ pub enum Config {
/// True if chat messages should be moved to a separate folder. Auto-sent messages like sync /// True if chat messages should be moved to a separate folder. Auto-sent messages like sync
/// ones are moved there anyway. /// ones are moved there anyway.
#[strum(props(default = "1"))]
MvboxMove, MvboxMove,
/// Watch for new messages in the "Mvbox" (aka DeltaChat folder) only. /// Watch for new messages in the "Mvbox" (aka DeltaChat folder) only.
@@ -596,9 +595,17 @@ impl Context {
.unwrap_or_default()) .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<bool> {
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. /// Returns true if movebox ("DeltaChat" folder) should be watched.
pub(crate) async fn should_watch_mvbox(&self) -> Result<bool> { pub(crate) async fn should_watch_mvbox(&self) -> Result<bool> {
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::OnlyFetchMvbox).await?
|| !self.get_config_bool(Config::IsChatmail).await?) || !self.get_config_bool(Config::IsChatmail).await?)
} }

View File

@@ -185,6 +185,15 @@ async fn test_delete_server_after_default() -> Result<()> {
Ok(()) 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(())
}
const SAVED_MESSAGES_DEDUPLICATED_FILE: &str = "969142cb84015bc135767bc2370934a.png"; const SAVED_MESSAGES_DEDUPLICATED_FILE: &str = "969142cb84015bc135767bc2370934a.png";
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]

View File

@@ -529,7 +529,6 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Configure
}; };
if is_chatmail { if is_chatmail {
ctx.set_config(Config::SentboxWatch, None).await?; 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::OnlyFetchMvbox, None).await?;
ctx.set_config(Config::ShowEmails, None).await?; ctx.set_config(Config::ShowEmails, None).await?;
} }

View File

@@ -482,7 +482,10 @@ impl Imap {
false => session.is_chatmail(), false => session.is_chatmail(),
true => context.get_config_bool(Config::IsChatmail).await?, 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) self.configure_folders(context, &mut session, create_mvbox)
.await?; .await?;
} }
@@ -1784,7 +1787,7 @@ impl Imap {
context context
.set_config_internal(Config::ConfiguredMvboxFolder, Some(mvbox_folder)) .set_config_internal(Config::ConfiguredMvboxFolder, Some(mvbox_folder))
.await?; .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."); warn!(context, "Will retry configuring MVBOX on reconnect.");
return Ok(()); return Ok(());
} }
@@ -1997,7 +2000,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); return Ok(false);
} }