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.sql
parent
99697a8fd5
commit
229e879c26
|
@ -525,17 +525,25 @@ impl ImapType {
|
|||
.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 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.read_response(&mut response)?;
|
||||
debug!(&response);
|
||||
|
||||
let mut lines = response.lines();
|
||||
for l in lines.by_ref() {
|
||||
if l.starts_with("* SEARCH") {
|
||||
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(
|
||||
l["* SEARCH".len()..]
|
||||
.trim()
|
||||
|
|
|
@ -407,6 +407,7 @@ pub fn query_to_imap(q: &Query) -> String {
|
|||
pub fn imap_search(
|
||||
term: &str,
|
||||
(sort_field, sort_order): (SortField, SortOrder),
|
||||
folder_hash: FolderHash,
|
||||
backend: &Arc<RwLock<Box<dyn MailBackend>>>,
|
||||
) -> Result<StackVec<EnvelopeHash>> {
|
||||
let query = query().parse(term)?.1;
|
||||
|
@ -414,7 +415,7 @@ pub fn imap_search(
|
|||
|
||||
let b = (*backend_lck).as_any();
|
||||
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 {
|
||||
panic!("Could not downcast ImapType backend. BUG");
|
||||
}
|
||||
|
|
|
@ -812,7 +812,6 @@ impl Account {
|
|||
ret
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn search(
|
||||
&self,
|
||||
search_term: &str,
|
||||
|
@ -820,7 +819,7 @@ impl Account {
|
|||
folder_hash: FolderHash,
|
||||
) -> Result<StackVec<EnvelopeHash>> {
|
||||
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")]
|
||||
|
|
Loading…
Reference in New Issue