mirror of
https://git.meli.delivery/meli/meli
synced 2024-11-15 06:12:47 +00:00
ui/imap: select user given folder before search
IMAP search() didn't select a folder before searching, thus searching the mailbox the previous user of self.connection had selected.
This commit is contained in:
parent
99697a8fd5
commit
229e879c26
@ -525,17 +525,25 @@ impl ImapType {
|
|||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search(&self, query: String) -> Result<crate::structs::StackVec<EnvelopeHash>> {
|
pub fn search(
|
||||||
|
&self,
|
||||||
|
query: String,
|
||||||
|
folder_hash: FolderHash,
|
||||||
|
) -> Result<crate::structs::StackVec<EnvelopeHash>> {
|
||||||
|
let folders_lck = self.folders.lock()?;
|
||||||
let mut response = String::with_capacity(8 * 1024);
|
let mut response = String::with_capacity(8 * 1024);
|
||||||
let mut conn = self.connection.lock()?;
|
let mut conn = self.connection.lock()?;
|
||||||
|
conn.send_command(format!("EXAMINE {}", folders_lck[&folder_hash].path()).as_bytes())?;
|
||||||
|
conn.read_response(&mut response)?;
|
||||||
conn.send_command(format!("UID SEARCH CHARSET UTF-8 {}", query).as_bytes())?;
|
conn.send_command(format!("UID SEARCH CHARSET UTF-8 {}", query).as_bytes())?;
|
||||||
conn.read_response(&mut response)?;
|
conn.read_response(&mut response)?;
|
||||||
|
debug!(&response);
|
||||||
|
|
||||||
let mut lines = response.lines();
|
let mut lines = response.lines();
|
||||||
for l in lines.by_ref() {
|
for l in lines.by_ref() {
|
||||||
if l.starts_with("* SEARCH") {
|
if l.starts_with("* SEARCH") {
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
let uid_index = self.uid_index.lock().unwrap();
|
let uid_index = self.uid_index.lock()?;
|
||||||
return Ok(crate::structs::StackVec::from_iter(
|
return Ok(crate::structs::StackVec::from_iter(
|
||||||
l["* SEARCH".len()..]
|
l["* SEARCH".len()..]
|
||||||
.trim()
|
.trim()
|
||||||
|
@ -407,6 +407,7 @@ pub fn query_to_imap(q: &Query) -> String {
|
|||||||
pub fn imap_search(
|
pub fn imap_search(
|
||||||
term: &str,
|
term: &str,
|
||||||
(sort_field, sort_order): (SortField, SortOrder),
|
(sort_field, sort_order): (SortField, SortOrder),
|
||||||
|
folder_hash: FolderHash,
|
||||||
backend: &Arc<RwLock<Box<dyn MailBackend>>>,
|
backend: &Arc<RwLock<Box<dyn MailBackend>>>,
|
||||||
) -> Result<StackVec<EnvelopeHash>> {
|
) -> Result<StackVec<EnvelopeHash>> {
|
||||||
let query = query().parse(term)?.1;
|
let query = query().parse(term)?.1;
|
||||||
@ -414,7 +415,7 @@ pub fn imap_search(
|
|||||||
|
|
||||||
let b = (*backend_lck).as_any();
|
let b = (*backend_lck).as_any();
|
||||||
if let Some(imap_backend) = b.downcast_ref::<melib::backends::ImapType>() {
|
if let Some(imap_backend) = b.downcast_ref::<melib::backends::ImapType>() {
|
||||||
imap_backend.search(query_to_imap(&query))
|
imap_backend.search(query_to_imap(&query), folder_hash)
|
||||||
} else {
|
} else {
|
||||||
panic!("Could not downcast ImapType backend. BUG");
|
panic!("Could not downcast ImapType backend. BUG");
|
||||||
}
|
}
|
||||||
|
@ -812,7 +812,6 @@ impl Account {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
pub fn search(
|
pub fn search(
|
||||||
&self,
|
&self,
|
||||||
search_term: &str,
|
search_term: &str,
|
||||||
@ -820,7 +819,7 @@ impl Account {
|
|||||||
folder_hash: FolderHash,
|
folder_hash: FolderHash,
|
||||||
) -> Result<StackVec<EnvelopeHash>> {
|
) -> Result<StackVec<EnvelopeHash>> {
|
||||||
if self.settings.account().format() == "imap" {
|
if self.settings.account().format() == "imap" {
|
||||||
return crate::cache::imap_search(search_term, sort, &self.backend);
|
return crate::cache::imap_search(search_term, sort, folder_hash, &self.backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sqlite3")]
|
#[cfg(feature = "sqlite3")]
|
||||||
|
Loading…
Reference in New Issue
Block a user