Add OnlyFetchMvbox option

This commit is contained in:
Hocuri
2022-01-27 12:11:46 +01:00
parent 800c95ae63
commit 3e227f1566
6 changed files with 62 additions and 1 deletions

View File

@@ -1,5 +1,10 @@
# Changelog
## Unreleased
### API changes
- added `only_fetch_mvbox` config #3014
## 1.72.0
### Fixes

View File

@@ -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)=

View File

@@ -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::<i32>().ok())
.unwrap_or_default()
!= 0
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -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);

View File

@@ -671,6 +671,11 @@ impl Imap {
folder: &str,
fetch_existing_msgs: bool,
) -> Result<bool> {
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<bool> {
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 <https://tools.ietf.org/html/rfc2683#section-3.2.1.5>
/// command lines should not be much more than 1000 chars (servers should allow at least 8000 chars)

View File

@@ -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);