Skip to content

Commit

Permalink
feat: add developer option to disable IDLE
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Oct 9, 2023
1 parent f279730 commit 94bbaa0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ pub enum Config {
#[strum(props(default = "60"))]
ScanAllFoldersDebounceSecs,

/// Whether to avoid using IMAP IDLE even if the server supports it.
///
/// This is a developer option for testing "fake idle".
#[strum(props(default = "0"))]
DisableIdle,

/// Defines the max. size (in bytes) of messages downloaded automatically.
/// 0 = no limit.
#[strum(props(default = "0"))]
Expand Down Expand Up @@ -479,7 +485,8 @@ impl Context {
| Config::Bot
| Config::NotifyAboutWrongPw
| Config::SendSyncMsgs
| Config::SignUnencrypted => {
| Config::SignUnencrypted
| Config::DisableIdle => {
ensure!(
matches!(value, None | Some("0") | Some("1")),
"Boolean value must be either 0 or 1"
Expand Down
2 changes: 2 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ impl Context {
let mdns_enabled = self.get_config_int(Config::MdnsEnabled).await?;
let bcc_self = self.get_config_int(Config::BccSelf).await?;
let send_sync_msgs = self.get_config_int(Config::SendSyncMsgs).await?;
let disable_idle = self.get_config_bool(Config::DisableIdle).await?;

let prv_key_cnt = self.sql.count("SELECT COUNT(*) FROM keypairs;", ()).await?;

Expand Down Expand Up @@ -691,6 +692,7 @@ impl Context {
);
res.insert("bcc_self", bcc_self.to_string());
res.insert("send_sync_msgs", send_sync_msgs.to_string());
res.insert("disable_idle", disable_idle.to_string());
res.insert("private_key_count", prv_key_cnt.to_string());
res.insert("public_key_count", pub_key_cnt.to_string());
res.insert("fingerprint", fingerprint_str);
Expand Down
6 changes: 5 additions & 1 deletion src/imap/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ impl Session {
) -> Result<(Self, InterruptInfo)> {
use futures::future::FutureExt;

if ctx.get_config_bool(Config::DisableIdle).await? {
bail!("IMAP IDLE is disabled");
}

if !self.can_idle() {
bail!("IMAP server does not have IDLE capability");
}
Expand Down Expand Up @@ -163,7 +167,7 @@ impl Imap {
continue;
}
if let Some(session) = &self.session {
if session.can_idle() {
if session.can_idle() && !ctx.get_config_bool(Config::DisableIdle).await? {
// we only fake-idled because network was gone during IDLE, probably
break InterruptInfo::new(false);
}
Expand Down
13 changes: 13 additions & 0 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,19 @@ async fn fetch_idle(
.await;
}

if ctx
.get_config_bool(Config::DisableIdle)
.await
.context("Failed to get disable_idle config")
.log_err(ctx)
.unwrap_or_default()
{
info!(ctx, "IMAP IDLE is disabled, going to fake idle.");
return connection
.fake_idle(ctx, Some(watch_folder), folder_meaning)
.await;
}

info!(ctx, "IMAP session supports IDLE, using it.");
match session
.idle(
Expand Down

0 comments on commit 94bbaa0

Please sign in to comment.