diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-02-23 10:03:48 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-02-23 10:04:03 +0100 |
commit | 10613ad4f80f63fc354c9c06f08bca0fc6476eeb (patch) | |
tree | 2e1828a0dbee248e85d233aa738446c1fef52c2c | |
parent | ecd7db2b6ae350bb21f5d54ffe96a753310c2f19 (diff) |
Remove old implementation
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/domain/libimagmail/Cargo.toml | 1 | ||||
-rw-r--r-- | lib/domain/libimagmail/src/lib.rs | 1 | ||||
-rw-r--r-- | lib/domain/libimagmail/src/mailtree.rs | 201 |
3 files changed, 1 insertions, 202 deletions
diff --git a/lib/domain/libimagmail/Cargo.toml b/lib/domain/libimagmail/Cargo.toml index 11495de2..6bb37e51 100644 --- a/lib/domain/libimagmail/Cargo.toml +++ b/lib/domain/libimagmail/Cargo.toml @@ -28,7 +28,6 @@ failure = "0.1.5" resiter = "0.4.0" notmuch = "0.6" chrono = "0.4" -indextree = "4" itertools = "0.8" mda = { git = "https://github.com/matthiasbeyer/mda-rs", branch = "my-master" } # "0.1" diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs index 809c2981..12534a7d 100644 --- a/lib/domain/libimagmail/src/lib.rs +++ b/lib/domain/libimagmail/src/lib.rs @@ -46,7 +46,6 @@ extern crate resiter; extern crate chrono; extern crate notmuch as notmuch_rs; extern crate mda; -extern crate indextree; extern crate itertools; extern crate libimagerror; diff --git a/lib/domain/libimagmail/src/mailtree.rs b/lib/domain/libimagmail/src/mailtree.rs index 9b72ac6d..84d1784d 100644 --- a/lib/domain/libimagmail/src/mailtree.rs +++ b/lib/domain/libimagmail/src/mailtree.rs @@ -35,215 +35,16 @@ use crate::mail::LoadedMail; #[derive(Debug)] pub struct Mailtree { - arena: Arena<String>, - root: NodeId, } impl Mailtree { pub(crate) fn fill_from<'a>(store: &'a MailStoreWithConnection<'a>, root: LoadedMail) -> Result<Self> { - let mut arena = Arena::<String>::new(); - let root = fill_arena_with(&mut arena, store, root)?; - trace!("Arena = {:?}", root); - Ok(Mailtree { arena, root }) - } - - pub fn root(&self) -> Option<&String> { - self.arena.get(self.root).map(|node| node.get()) } pub fn traverse(&self) -> Traverse { - Traverse::with(self) - } -} - -fn fill_arena_with<'a>(arena: &mut Arena<String>, store: &'a MailStoreWithConnection<'a>, root: LoadedMail) -> Result<NodeId> { - trace!("Filling arena starting at: {}", root.get_id()); - - let root_id = root.get_id().clone(); - trace!("root_id = {:?}", root_id); - - let root_node = arena.new_node(root_id.clone()); - trace!("root_node = {:?}", root_node); - - let root_thread_id = root.get_thread_id().to_owned(); - trace!("root_thread_id = {:?}", root_thread_id); - drop(root); - - - let ids = store.connection().execute(|db| { - let q = format!("thread:{}", root_thread_id); - trace!("Executing query: {}", q); - let query = db.create_query(&q)?; - let r = query.search_threads()? - .map(|thread| { - trace!("Found thread: {}", thread.id()); - let messages = thread - .messages() - .map(|msg| { - let id = msg.id(); - trace!("Found Message: {}", id); - - let id = id.into_owned(); - let new_node_id = arena.new_node(id.clone()); - root_node.append(new_node_id, arena); - id - }) - .collect::<Vec<String>>(); - - trace!("Collected {} messages", messages.len()); - messages - }) - .flat_map(|v| v.into_iter()) - .unique() - .filter(|id| *id != root_id) - .map(Ok) - .collect::<Result<Vec<String>>>(); - - trace!("Query '{:?}' resulted in: {:?}", query, r); - r - })?; - - trace!("IDs = {:?}", ids); - - ids - .into_iter() - .map(|id: String| { - trace!("Trying to get: {:?}", id); - - { - let sid = StoreId::new(PathBuf::from(id.clone()))?; - if store.is_borrowed(sid.clone())? { - trace!("Entry is already borrowed, returning"); - return Ok(()) - } - - trace!("Seems not to be borrowed: {:?}", sid); - } - - let mail = store.get_mail_by_id(&id) - .context("Getting mail by id")? - .ok_or_else(|| format_err!("Cannot find mail for id {}", id))?; - trace!("Fetched from store: {}", mail.get_location()); - - - let reply = mail - .load(store.connection())? - .ok_or_else(|| format_err!("Tried to load unavailable mail: {}", mail.get_location()))?; - trace!("Loaded from store: {}", reply.get_id()); - drop(mail); - - trace!("Recursing with: {}", reply.get_id()); - fill_arena_with(arena, store, reply).map(|_| ()) - }) - .collect::<Result<Vec<_>>>() - .map(|_| root_node) -} - -/// A type for traversing the Mailtree -/// -/// Implements an iterator that yields the Message IDs combined with an "indentation", which marks -/// how deep the yielded node is in the tree. -#[derive(Debug)] -pub struct Traverse<'a> { - tree: &'a Mailtree, - next_node: Option<NodeId>, - next_indent: usize, -} - -impl<'a> Traverse<'a> { - fn with(tree: &'a Mailtree) -> Self { - Traverse { - tree, - next_node: Some(tree.root), - next_indent: 0, - } - } - - fn get_node(&self, nodeid: NodeId) -> Option<String> { - self.tree.arena.get(nodeid).map(|n| n.get()).map(ToOwned::to_owned) - } - - fn get_current_node(&self) -> Option<&Node<String>> { - self.next_node - .and_then(|nodeid| self.tree.arena.get(nodeid)) - } - - fn current_node_next_sibling(&self) -> Option<NodeId> { - self.get_current_node() - .and_then(|node| node.next_sibling()) - } - - fn current_node_first_child(&self) -> Option<NodeId> { - self.get_current_node() - .and_then(|node| node.first_child()) - } - - fn current_node_parent(&self) -> Option<NodeId> { - self.get_current_node() - .and_then(|node| node.parent()) - } -} - -impl<'a> Iterator for Traverse<'a> { - type Item = (usize, String); // (Indention, Message Id) - - fn next(&mut self) -> Option<Self::Item> { - if let Some(current_node) = self.next_node.and_then(|n| self.get_node(n)) { - let current_indent = self.next_indent; - trace!("Iterating: {:?}", self); - - if let Some(sibling) = self.current_node_next_sibling() { - trace!("Sibling found: {:?}", sibling); - // do not alter indent - self.next_node = Some(sibling); - return Some((current_indent, current_node)); - } else { - trace!("No sibling found"); - if let Some(child) = self.current_node_first_child() { - trace!("Child found: {:?}", child); - - // We have a child, make that the current node and return it - self.next_indent += 1; - self.next_node = Some(child); - return Some((current_indent, current_node)); - } else { - trace!("No child found"); - // We have no siblings and - // We have no children - // We might have to go back up one level - - if let Some(parent) = self.current_node_parent() { - trace!("Parent found: {:?}", parent); - // We have a parent - if let Some(parents_sibling) = self.tree.arena.get(parent).and_then(|n| n.next_sibling()) { - trace!("Parents sibling found: {:?}", parents_sibling); - // And the parent has a sibling - // - // Make that the next current node and go from there - self.next_indent -= 1; - self.next_node = Some(parents_sibling); - return Some((current_indent, current_node)); - } else { - trace!("No parents sibling found"); - // We are the last node: - // - We have no sibling - // - We have no child - // - Our parent has no sibling - self.next_node = None; - return Some((current_indent, current_node)) - } - } else { - trace!("No parent found"); - self.next_node = None; - return Some((current_indent, current_node)) - } - } - } - } else { - return None; - } + unimplemented!() } } |