From 34c766dc2b347c60801856f8879c73da4604abf9 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 19 Nov 2019 23:00:28 +0100 Subject: [PATCH] merge JobThread::connect_to_imap with Imap::connect_configured for simplicity --- src/imap.rs | 11 +++++++++-- src/job_thread.rs | 23 ++++------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/imap.rs b/src/imap.rs index 27c61a801..9a295cd68 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -295,6 +295,14 @@ impl Imap { // the trailing underscore is correct if self.connect(context, ¶m) { + if context + .sql + .get_raw_config_int(context, "folders_configured") + .unwrap_or_default() + < 3 + { + self.configure_folders(context, 0x1); + } return Ok(()); } return Err(Error::ImapConnectionFailed( @@ -1069,8 +1077,7 @@ impl Imap { // TODO: make INBOX/SENT/MVBOX perform the jobs on their // respective folders to avoid select_folder network traffic // and the involved error states - let inbox_thread = context.inbox_thread.read().unwrap(); - if let Err(err) = inbox_thread.connect_to_imap(context) { + if let Err(err) = self.connect_configured(context) { warn!(context, "prepare_imap_op failed: {}", err); return Some(ImapActionResult::RetryLater); } diff --git a/src/job_thread.rs b/src/job_thread.rs index 8bc6ea887..2416faff5 100644 --- a/src/job_thread.rs +++ b/src/job_thread.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Condvar, Mutex}; use crate::context::Context; -use crate::error::{Error, Result}; +use crate::error::Error; use crate::imap::Imap; #[derive(Debug)] @@ -86,7 +86,7 @@ impl JobThread { if use_network { let prefix = format!("{}-fetch", self.name); - match self.connect_to_imap(context) { + match self.imap.connect_configured(context) { Ok(()) => { if let Some(watch_folder) = self.get_watch_folder(context) { let start = std::time::Instant::now(); @@ -102,7 +102,7 @@ impl JobThread { if let Err(err) = res { warn!(context, "fetch failed: {}, reconnect & retry", err); self.imap.trigger_reconnect(); - match self.connect_to_imap(context) { + match self.imap.connect_configured(context) { Ok(()) => { if let Err(err) = self.imap.fetch(context, &watch_folder) { error!(context, "fetch failed: {}", err); @@ -141,21 +141,6 @@ impl JobThread { } } - pub fn connect_to_imap(&self, context: &Context) -> Result<()> { - self.imap.connect_configured(context)?; - - if context - .sql - .get_raw_config_int(context, "folders_configured") - .unwrap_or_default() - < 3 - { - self.imap.configure_folders(context, 0x1); - } - - Ok(()) - } - pub fn idle(&self, context: &Context, use_network: bool) { { let &(ref lock, ref cvar) = &*self.state.clone(); @@ -193,7 +178,7 @@ impl JobThread { } let prefix = format!("{}-IDLE", self.name); - let do_fake_idle = match self.connect_to_imap(context) { + let do_fake_idle = match self.imap.connect_configured(context) { Ok(()) => { info!(context, "{} started...", prefix); let watch_folder = self.get_watch_folder(context);