melib/imap: move current_mailbox to ImapStream
ImapStream holds the connection state (current command id), so it makes sense to move current_mailbox state there. That way, when a connection drops for whatever reason the old current_mailbox is dropped and not carried over to new connections.memfd
parent
2db983ae1f
commit
7bbfd188ef
|
@ -752,9 +752,10 @@ impl MailBackend for ImapType {
|
|||
let mut response = String::with_capacity(8 * 1024);
|
||||
{
|
||||
let mut conn_lck = connection.lock().await;
|
||||
let current_mailbox = conn_lck.stream.as_ref()?.current_mailbox;
|
||||
if !no_select
|
||||
&& (conn_lck.current_mailbox == MailboxSelection::Examine(mailbox_hash)
|
||||
|| conn_lck.current_mailbox == MailboxSelection::Select(mailbox_hash))
|
||||
&& (current_mailbox == MailboxSelection::Examine(mailbox_hash)
|
||||
|| current_mailbox == MailboxSelection::Select(mailbox_hash))
|
||||
{
|
||||
/* make sure mailbox is not selected before it gets deleted, otherwise
|
||||
* connection gets dropped by server */
|
||||
|
|
|
@ -46,9 +46,10 @@ pub enum ImapProtocol {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct ImapStream {
|
||||
cmd_id: usize,
|
||||
stream: AsyncWrapper<Connection>,
|
||||
protocol: ImapProtocol,
|
||||
pub cmd_id: usize,
|
||||
pub stream: AsyncWrapper<Connection>,
|
||||
pub protocol: ImapProtocol,
|
||||
pub current_mailbox: MailboxSelection,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
|
@ -73,7 +74,6 @@ pub struct ImapConnection {
|
|||
pub stream: Result<ImapStream>,
|
||||
pub server_conf: ImapServerConf,
|
||||
pub uid_store: Arc<UIDStore>,
|
||||
pub current_mailbox: MailboxSelection,
|
||||
}
|
||||
|
||||
impl Drop for ImapStream {
|
||||
|
@ -220,6 +220,7 @@ impl ImapStream {
|
|||
cmd_id,
|
||||
stream,
|
||||
protocol: server_conf.protocol,
|
||||
current_mailbox: MailboxSelection::None,
|
||||
};
|
||||
if let ImapProtocol::ManageSieve = server_conf.protocol {
|
||||
use data_encoding::BASE64;
|
||||
|
@ -476,7 +477,6 @@ impl ImapConnection {
|
|||
stream: Err(MeliError::new("Offline".to_string())),
|
||||
server_conf: server_conf.clone(),
|
||||
uid_store,
|
||||
current_mailbox: MailboxSelection::None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -615,7 +615,8 @@ impl ImapConnection {
|
|||
ret: &mut String,
|
||||
force: bool,
|
||||
) -> Result<()> {
|
||||
if !force && self.current_mailbox == MailboxSelection::Select(mailbox_hash) {
|
||||
if !force && self.stream.as_ref()?.current_mailbox == MailboxSelection::Select(mailbox_hash)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
self.send_command(
|
||||
|
@ -629,7 +630,7 @@ impl ImapConnection {
|
|||
self.read_response(ret, RequiredResponses::SELECT_REQUIRED)
|
||||
.await?;
|
||||
debug!("select response {}", ret);
|
||||
self.current_mailbox = MailboxSelection::Select(mailbox_hash);
|
||||
self.stream.as_mut()?.current_mailbox = MailboxSelection::Select(mailbox_hash);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -639,7 +640,9 @@ impl ImapConnection {
|
|||
ret: &mut String,
|
||||
force: bool,
|
||||
) -> Result<()> {
|
||||
if !force && self.current_mailbox == MailboxSelection::Examine(mailbox_hash) {
|
||||
if !force
|
||||
&& self.stream.as_ref()?.current_mailbox == MailboxSelection::Examine(mailbox_hash)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
self.send_command(
|
||||
|
@ -653,12 +656,12 @@ impl ImapConnection {
|
|||
self.read_response(ret, RequiredResponses::EXAMINE_REQUIRED)
|
||||
.await?;
|
||||
debug!("examine response {}", ret);
|
||||
self.current_mailbox = MailboxSelection::Examine(mailbox_hash);
|
||||
self.stream.as_mut()?.current_mailbox = MailboxSelection::Examine(mailbox_hash);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn unselect(&mut self) -> Result<()> {
|
||||
match self.current_mailbox.take() {
|
||||
match self.stream.as_mut()?.current_mailbox.take() {
|
||||
MailboxSelection::Examine(mailbox_hash) |
|
||||
MailboxSelection::Select(mailbox_hash) =>{
|
||||
let mut response = String::with_capacity(8 * 1024);
|
||||
|
|
|
@ -51,8 +51,7 @@ impl ImapConnection {
|
|||
} else { Ok(()) }?;)+
|
||||
};
|
||||
}
|
||||
//FIXME
|
||||
let mailbox_hash = match self.current_mailbox {
|
||||
let mailbox_hash = match self.stream.as_ref()?.current_mailbox {
|
||||
MailboxSelection::Select(h) | MailboxSelection::Examine(h) => h,
|
||||
MailboxSelection::None => return Ok(false),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue