mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
merge JobThread::connect_to_imap with Imap::connect_configured for simplicity
This commit is contained in:
11
src/imap.rs
11
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user