diff --git a/CHANGELOG.md b/CHANGELOG.md index 76848b662..73c8fb908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +### API changes +- added `only_fetch_mvbox` config #3014 + ## 1.72.0 ### Fixes diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index d8c6aa057..ee5d223db 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -343,6 +343,11 @@ char* dc_get_blobdir (const dc_context_t* context); * and watch the `DeltaChat` folder for updates (default), * 0=do not move chat-messages * changes require restarting IO by calling dc_stop_io() and then dc_start_io(). + * - `only_fetch_mvbox` = 1=ignore all folders except for the `DeltaChat` folder. + * Setting this will automatically set `mvbox_move` to 1 and `sentbox_watch` to 0. + * Setting `mvbox_move` to 0 or `sentbox_watch` to 1 will automatically disable this option. + * When this option is set, the UI should disable the `mvbox_move` and `sentbox_watch` options. + * 0=watch all folders normally (default) * - `show_emails` = DC_SHOW_EMAILS_OFF (0)= * show direct replies to chats only (default), * DC_SHOW_EMAILS_ACCEPTED_CONTACTS (1)= diff --git a/src/config.rs b/src/config.rs index af83cba2c..04a4a5587 100644 --- a/src/config.rs +++ b/src/config.rs @@ -74,6 +74,9 @@ pub enum Config { #[strum(props(default = "0"))] SentboxMove, // If `MvboxMove` is true, this config is ignored. Currently only used in tests. + #[strum(props(default = "0"))] + OnlyFetchMvbox, + #[strum(props(default = "0"))] // also change ShowEmails.default() on changes ShowEmails, @@ -295,6 +298,33 @@ impl Context { let value = value.map(improve_single_line_input); self.sql.set_raw_config(key, value.as_deref()).await?; } + Config::SentboxWatch => { + self.sql.set_raw_config(key, value).await?; + if config_to_bool(value) { + self.sql + .set_raw_config(Config::OnlyFetchMvbox, Some("0")) + .await?; + } + } + Config::MvboxMove => { + self.sql.set_raw_config(key, value).await?; + if !config_to_bool(value) { + self.sql + .set_raw_config(Config::OnlyFetchMvbox, Some("0")) + .await?; + } + } + Config::OnlyFetchMvbox => { + self.sql.set_raw_config(key, value).await?; + if config_to_bool(value) { + self.sql + .set_raw_config(Config::SentboxWatch, Some("0")) + .await?; + self.sql + .set_raw_config(Config::MvboxMove, Some("1")) + .await?; + } + } _ => { self.sql.set_raw_config(key, value).await?; } @@ -335,6 +365,13 @@ fn get_config_keys_string() -> String { format!(" {} ", keys) } +fn config_to_bool(value: Option<&str>) -> bool { + value + .and_then(|s| s.parse::().ok()) + .unwrap_or_default() + != 0 +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/context.rs b/src/context.rs index 3ed0278fd..93262e564 100644 --- a/src/context.rs +++ b/src/context.rs @@ -358,6 +358,7 @@ impl Context { let sentbox_watch = self.get_config_int(Config::SentboxWatch).await?; let mvbox_move = self.get_config_int(Config::MvboxMove).await?; let sentbox_move = self.get_config_int(Config::SentboxMove).await?; + let only_fetch_mvbox = self.get_config_int(Config::OnlyFetchMvbox).await?; let folders_configured = self .sql .get_raw_config_int("folders_configured") @@ -422,6 +423,7 @@ impl Context { res.insert("sentbox_watch", sentbox_watch.to_string()); res.insert("mvbox_move", mvbox_move.to_string()); res.insert("sentbox_move", sentbox_move.to_string()); + res.insert("only_fetch_mvbox", only_fetch_mvbox.to_string()); res.insert("folders_configured", folders_configured.to_string()); res.insert("configured_sentbox_folder", configured_sentbox_folder); res.insert("configured_mvbox_folder", configured_mvbox_folder); diff --git a/src/imap.rs b/src/imap.rs index 6115e58b0..fd66b43f2 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -671,6 +671,11 @@ impl Imap { folder: &str, fetch_existing_msgs: bool, ) -> Result { + if should_ignore_folder(context, folder).await? { + info!(context, "Not fetching from {}", folder); + return Ok(false); + } + let new_emails = self.select_with_uidvalidity(context, folder).await?; if !new_emails && !fetch_existing_msgs { @@ -2076,6 +2081,14 @@ pub async fn get_config_last_seen_uid(context: &Context, folder: &str) -> Result } } +async fn should_ignore_folder(context: &Context, folder: &str) -> Result { + Ok(context.get_config_bool(Config::OnlyFetchMvbox).await? + && context.is_mvbox(folder).await? + // Even if OnlyFetchMvbox is set, we have a look at the spam folder + // in case an answer to a known message was put into spam: + && context.is_spam_folder(folder).await?) +} + /// Builds a list of sequence/uid sets. The returned sets have each no more than around 1000 /// characters because according to /// command lines should not be much more than 1000 chars (servers should allow at least 8000 chars) diff --git a/src/imap/idle.rs b/src/imap/idle.rs index ffff87070..f325c3648 100644 --- a/src/imap/idle.rs +++ b/src/imap/idle.rs @@ -157,7 +157,6 @@ impl Imap { // in anything. If so, we behave as if IDLE had data but // will have already fetched the messages so perform_*_fetch // will not find any new. - match self.fetch_new_messages(context, &watch_folder, false).await { Ok(res) => { info!(context, "fetch_new_messages returned {:?}", res);