diff --git a/src/context.rs b/src/context.rs index 5a3d09e86..8e573c423 100644 --- a/src/context.rs +++ b/src/context.rs @@ -44,7 +44,6 @@ pub struct Context { /// Blob directory path blobdir: PathBuf, pub sql: Sql, - pub perform_inbox_jobs_needed: Arc>, pub probe_imap_network: Arc>, pub inbox_thread: Arc>, pub sentbox_thread: Arc>, @@ -147,7 +146,6 @@ impl Context { Imap::new(), ))), probe_imap_network: Arc::new(RwLock::new(false)), - perform_inbox_jobs_needed: Arc::new(RwLock::new(false)), generating_key_mutex: Mutex::new(()), translated_stockstrings: RwLock::new(HashMap::new()), }; diff --git a/src/job.rs b/src/job.rs index 7df6c1283..ab3aa0c46 100644 --- a/src/job.rs +++ b/src/job.rs @@ -35,7 +35,7 @@ const JOB_RETRIES: u32 = 17; /// Thread IDs #[derive(Debug, Display, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)] #[repr(i32)] -enum Thread { +pub enum Thread { Unknown = 0, Imap = 100, Smtp = 5000, @@ -436,13 +436,6 @@ pub fn perform_sentbox_fetch(context: &Context) { } pub fn perform_inbox_idle(context: &Context) { - if *context.perform_inbox_jobs_needed.clone().read().unwrap() { - info!( - context, - "INBOX-IDLE will not be started because of waiting jobs." - ); - return; - } let use_network = context.get_config_bool(Config::InboxWatch); context @@ -552,7 +545,7 @@ pub fn perform_smtp_idle(context: &Context) { info!(context, "SMTP-idle ended.",); } -fn get_next_wakeup_time(context: &Context, thread: Thread) -> Duration { +pub(crate) fn get_next_wakeup_time(context: &Context, thread: Thread) -> Duration { let t: i64 = context .sql .query_get_value( @@ -704,7 +697,6 @@ pub fn perform_inbox_jobs(context: &Context) { let probe_imap_network = *context.probe_imap_network.clone().read().unwrap(); *context.probe_imap_network.write().unwrap() = false; - *context.perform_inbox_jobs_needed.write().unwrap() = false; job_perform(context, Thread::Imap, probe_imap_network); info!(context, "dc_perform_inbox_jobs ended.",); @@ -951,10 +943,6 @@ pub fn add_job_no_interrupt( (timestamp + delay_seconds as i64) ] ).ok(); - - if thread == Thread::Imap { - *context.perform_inbox_jobs_needed.write().unwrap() = true; - } } pub fn add_job_with_interrupt( diff --git a/src/job_thread.rs b/src/job_thread.rs index 0af525f0f..3253232c7 100644 --- a/src/job_thread.rs +++ b/src/job_thread.rs @@ -3,6 +3,8 @@ use std::sync::{Arc, Condvar, Mutex}; use crate::context::Context; use crate::error::{Error, Result}; use crate::imap::Imap; +use crate::job::{get_next_wakeup_time, Thread}; +use std::time::Duration; #[derive(Debug)] pub struct JobThread { @@ -57,10 +59,6 @@ impl JobThread { } pub fn interrupt_idle(&self, context: &Context) { - { - self.state.0.lock().unwrap().jobs_needed = true; - } - info!(context, "Interrupting {}-IDLE...", self.name); self.imap.interrupt_idle(context); @@ -140,14 +138,15 @@ impl JobThread { let &(ref lock, ref cvar) = &*self.state.clone(); let mut state = lock.lock().unwrap(); - if state.jobs_needed { - info!( - context, - "{}-IDLE will not be started as it was interrupted while not ideling.", - self.name, - ); - state.jobs_needed = false; - return; + if self.folder_config_name == "INBOX" { + let duration = get_next_wakeup_time(context, Thread::Imap); + if duration <= Duration::from_millis(1) { + info!( + context, + "INBOX-IDLE will not be started because of waiting jobs." + ); + return; + } } if state.suspended {