Skip to content

Commit

Permalink
refactor: Make MvboxMove a dependent setting of IsChatmail
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iequidoo committed Aug 11, 2024
1 parent dc76ec6 commit ca5227f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<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.
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::IsChatmail).await?)
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
9 changes: 6 additions & 3 deletions src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
Expand Down Expand Up @@ -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(());
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ca5227f

Please sign in to comment.