Add tagging support

v1
Manos Pitsidianakis 2020-07-31 16:50:14 +03:00
parent ee5745d1e1
commit f80348e194
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 59 additions and 17 deletions

View File

@ -239,6 +239,10 @@ impl MailBackend for DemoType {
)))
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
Some(self.tag_index.clone())
}
fn save(
&self,
_bytes: Vec<u8>,

View File

@ -618,8 +618,8 @@ async function init(input) {
imports.wbg.__wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
imports.wbg.__wbindgen_closure_wrapper3072 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 689, __wbg_adapter_26);
imports.wbg.__wbindgen_closure_wrapper3119 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 697, __wbg_adapter_26);
return addHeapObject(ret);
};

Binary file not shown.

View File

@ -385,6 +385,20 @@ pub trait MailListingTrait: ListingTrait {
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
}
}
let hash = tag_hash!(tag_str);
if let Some(pos) = envelope.labels().iter().position(|el| *el == hash) {
envelope.labels_mut().remove(pos);
context
.replies
.push_back(UIEvent::RefreshEvent(Box::new(RefreshEvent {
kind: melib::backends::RefreshEventKind::Update(
env_hash,
Box::new(envelope.clone()),
),
mailbox_hash,
account_hash,
})));
}
}
ListingAction::Tag(Add(ref tag_str)) => {
match op.set_tag(tag_str.to_string(), true) {
@ -404,6 +418,25 @@ pub trait MailListingTrait: ListingTrait {
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
}
}
let hash = tag_hash!(tag_str);
if envelope
.labels()
.iter()
.position(|el| *el == hash)
.is_none()
{
envelope.labels_mut().push(hash);
context
.replies
.push_back(UIEvent::RefreshEvent(Box::new(RefreshEvent {
kind: melib::backends::RefreshEventKind::Update(
env_hash,
Box::new(envelope.clone()),
),
mailbox_hash,
account_hash,
})));
}
}
_ => unreachable!(),
}

View File

@ -1312,6 +1312,7 @@ impl Account {
mailbox_hash: MailboxHash,
) -> ResultFuture<SmallVec<[EnvelopeHash; 512]>> {
use melib::parsec::Parser;
use melib::search::{Query, QueryTrait};
let query = melib::search::query().parse(search_term)?.1;
match self.settings.conf.search_backend {
#[cfg(feature = "sqlite3")]
@ -1324,28 +1325,32 @@ impl Account {
.search(query, Some(mailbox_hash))
} else {
let mut ret = SmallVec::new();
melib::log(format!("Starting search {:?}", search_term), melib::WARN);
let envelopes = self.collection.envelopes.read().unwrap();
for &env_hash in self.collection.get_mailbox(mailbox_hash).iter() {
melib::log(format!("Searching {:?}", env_hash), melib::WARN);
let envelope = &envelopes[&env_hash];
if envelope.subject().contains(&search_term) {
if envelope.is_match(&query) {
ret.push(env_hash);
continue;
}
if envelope.field_from_to_string().contains(&search_term) {
ret.push(env_hash);
continue;
}
let op = if let Ok(op) = self.operation(env_hash) {
op
} else {
continue;
};
let body = envelope.body(op)?;
let decoded = decode_rec(&body, None);
let body_text = String::from_utf8_lossy(&decoded);
if body_text.contains(&search_term) {
ret.push(env_hash);
match &query {
Query::Body(ref s) | Query::AllText(ref s) => {
let op = if let Ok(op) = self.operation(env_hash) {
op
} else {
continue;
};
let body = envelope.body(op)?;
let decoded = decode_rec(&body, None);
let body_text = String::from_utf8_lossy(&decoded);
if body_text.contains(s) {
ret.push(env_hash);
}
}
_ => {}
}
}
}
Ok(Box::pin(async { Ok(ret) }))