Compare commits

...

2 Commits

Author SHA1 Message Date
iequidoo
a16a7d6682 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.
2025-04-10 00:25:57 -03:00
iequidoo
a5d0d4c126 fix: Retry configuring mvbox on IMAP reconnect if mvbox_move is enabled explicitly
If `mvbox_move` isn't enabled explictly, but only by default, better not to retry configuring it to
avoid excessive work, but if it's enabled explicitly by the user and actually can't be configured,
the user should disable it. But anyway not being able to configure the mvbox doesn't prevent Delta
Chat from working just leaving all mail in Inbox.
2025-04-09 16:21:22 -03:00
4 changed files with 29 additions and 8 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
/// ones are moved there anyway.
#[strum(props(default = "1"))]
MvboxMove,
/// Watch for new messages in the "Mvbox" (aka DeltaChat folder) only.
@@ -596,9 +595,17 @@ impl Context {
.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?)
}

View File

@@ -185,6 +185,15 @@ async fn test_delete_server_after_default() -> Result<()> {
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";
#[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 {
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?;
}

View File

@@ -482,7 +482,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?;
}
@@ -1776,14 +1779,17 @@ impl Imap {
context
.set_config_internal(Config::ConfiguredInboxFolder, Some("INBOX"))
.await?;
for (config, name) in folder_configs {
context.set_config_internal(config, Some(&name)).await?;
}
if let Some(mvbox_folder) = mvbox_folder {
info!(context, "Setting MVBOX FOLDER TO {}", &mvbox_folder);
context
.set_config_internal(Config::ConfiguredMvboxFolder, Some(mvbox_folder))
.await?;
}
for (config, name) in folder_configs {
context.set_config_internal(config, Some(&name)).await?;
} else if context.get_config_bool_opt(Config::MvboxMove).await? == Some(true) {
warn!(context, "Will retry configuring MVBOX on reconnect.");
return Ok(());
}
context
.sql
@@ -1994,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);
}