mirror of
https://github.com/chatmail/core.git
synced 2026-05-25 09:46:31 +03:00
imap: remove unnecessary Imap.connected variable
It is always the same as Imap.session.is_some().
This commit is contained in:
39
src/imap.rs
39
src/imap.rs
@@ -88,7 +88,6 @@ pub struct Imap {
|
|||||||
idle_interrupt: Receiver<InterruptInfo>,
|
idle_interrupt: Receiver<InterruptInfo>,
|
||||||
config: ImapConfig,
|
config: ImapConfig,
|
||||||
session: Option<Session>,
|
session: Option<Session>,
|
||||||
connected: bool,
|
|
||||||
interrupt: Option<stop_token::StopSource>,
|
interrupt: Option<stop_token::StopSource>,
|
||||||
should_reconnect: bool,
|
should_reconnect: bool,
|
||||||
login_failed_once: bool,
|
login_failed_once: bool,
|
||||||
@@ -200,7 +199,6 @@ impl Imap {
|
|||||||
idle_interrupt,
|
idle_interrupt,
|
||||||
config,
|
config,
|
||||||
session: None,
|
session: None,
|
||||||
connected: false,
|
|
||||||
interrupt: None,
|
interrupt: None,
|
||||||
should_reconnect: false,
|
should_reconnect: false,
|
||||||
login_failed_once: false,
|
login_failed_once: false,
|
||||||
@@ -254,7 +252,7 @@ impl Imap {
|
|||||||
if self.should_reconnect() {
|
if self.should_reconnect() {
|
||||||
self.disconnect(context).await;
|
self.disconnect(context).await;
|
||||||
self.should_reconnect = false;
|
self.should_reconnect = false;
|
||||||
} else if self.is_connected() {
|
} else if self.session.is_some() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +345,6 @@ impl Imap {
|
|||||||
match login_res {
|
match login_res {
|
||||||
Ok(session) => {
|
Ok(session) => {
|
||||||
// needs to be set here to ensure it is set on reconnects.
|
// needs to be set here to ensure it is set on reconnects.
|
||||||
self.connected = true;
|
|
||||||
self.session = Some(session);
|
self.session = Some(session);
|
||||||
self.login_failed_once = false;
|
self.login_failed_once = false;
|
||||||
context.emit_event(EventType::ImapConnected(format!(
|
context.emit_event(EventType::ImapConnected(format!(
|
||||||
@@ -442,16 +439,11 @@ impl Imap {
|
|||||||
warn!(context, "failed to logout: {:?}", err);
|
warn!(context, "failed to logout: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.connected = false;
|
|
||||||
self.capabilities_determined = false;
|
self.capabilities_determined = false;
|
||||||
self.config.selected_folder = None;
|
self.config.selected_folder = None;
|
||||||
self.config.selected_mailbox = None;
|
self.config.selected_mailbox = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_connected(&self) -> bool {
|
|
||||||
self.connected
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn should_reconnect(&self) -> bool {
|
pub fn should_reconnect(&self) -> bool {
|
||||||
self.should_reconnect
|
self.should_reconnect
|
||||||
}
|
}
|
||||||
@@ -882,19 +874,13 @@ impl Imap {
|
|||||||
return (None, 0);
|
return (None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.is_connected() {
|
let session = match self.session.as_mut() {
|
||||||
|
Some(session) => session,
|
||||||
|
None => {
|
||||||
warn!(context, "Not connected");
|
warn!(context, "Not connected");
|
||||||
return (None, server_uids.len());
|
return (None, server_uids.len());
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if self.session.is_none() {
|
|
||||||
// we could not get a valid imap session, this should be retried
|
|
||||||
self.trigger_reconnect(context).await;
|
|
||||||
warn!(context, "Could not get IMAP session");
|
|
||||||
return (None, server_uids.len());
|
|
||||||
}
|
|
||||||
|
|
||||||
let session = self.session.as_mut().unwrap();
|
|
||||||
|
|
||||||
let sets = build_sequence_sets(server_uids.clone());
|
let sets = build_sequence_sets(server_uids.clone());
|
||||||
let mut read_errors = 0;
|
let mut read_errors = 0;
|
||||||
@@ -1123,7 +1109,7 @@ impl Imap {
|
|||||||
if uid == 0 {
|
if uid == 0 {
|
||||||
return Some(ImapActionResult::RetryLater);
|
return Some(ImapActionResult::RetryLater);
|
||||||
}
|
}
|
||||||
if !self.is_connected() {
|
if self.session.is_none() {
|
||||||
// currently jobs are only performed on the INBOX thread
|
// currently jobs are only performed on the INBOX thread
|
||||||
// TODO: make INBOX/SENT/MVBOX perform the jobs on their
|
// TODO: make INBOX/SENT/MVBOX perform the jobs on their
|
||||||
// respective folders to avoid select_folder network traffic
|
// respective folders to avoid select_folder network traffic
|
||||||
@@ -1283,11 +1269,11 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn configure_folders(&mut self, context: &Context, create_mvbox: bool) -> Result<()> {
|
pub async fn configure_folders(&mut self, context: &Context, create_mvbox: bool) -> Result<()> {
|
||||||
if !self.is_connected() {
|
let session = match self.session {
|
||||||
bail!("IMAP No Connection established");
|
Some(ref mut session) => session,
|
||||||
}
|
None => bail!("no IMAP connection established"),
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(ref mut session) = &mut self.session {
|
|
||||||
let mut folders = match session.list(Some(""), Some("*")).await {
|
let mut folders = match session.list(Some(""), Some("*")).await {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -1349,8 +1335,7 @@ impl Imap {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
"Cannot create MVBOX-folder, trying to create INBOX subfolder. ({})",
|
"Cannot create MVBOX-folder, trying to create INBOX subfolder. ({})", err
|
||||||
err
|
|
||||||
);
|
);
|
||||||
|
|
||||||
match session.create(&fallback_folder).await {
|
match session.create(&fallback_folder).await {
|
||||||
@@ -1391,7 +1376,7 @@ impl Imap {
|
|||||||
.sql
|
.sql
|
||||||
.set_raw_config_int("folders_configured", DC_FOLDERS_CONFIGURED_VERSION)
|
.set_raw_config_int("folders_configured", DC_FOLDERS_CONFIGURED_VERSION)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
|
||||||
info!(context, "FINISHED configuring IMAP-folders.");
|
info!(context, "FINISHED configuring IMAP-folders.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user