summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-06 18:11:20 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-06 18:26:28 +0100
commitf033d0af40ee86bfa4684db701e55619a204a346 (patch)
tree4a2d98579a5fc9a4ae932982e5f33faf6e193351
parent80a13ec7073d097dc7d251591e9b47156ad981e7 (diff)
Make sure messages are dropped before re-fetching them from notmuch
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/mailtree.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/domain/libimagmail/src/mailtree.rs b/lib/domain/libimagmail/src/mailtree.rs
index 1ac63350..e1c052af 100644
--- a/lib/domain/libimagmail/src/mailtree.rs
+++ b/lib/domain/libimagmail/src/mailtree.rs
@@ -21,6 +21,7 @@ use failure::Fallible as Result;
use indextree::Arena;
use indextree::NodeId;
use indextree::Node;
+use itertools::Itertools;
use crate::store::MailStoreWithConnection;
use crate::mail::Mail;
@@ -55,9 +56,11 @@ fn fill_arena_with<'a>(arena: &mut Arena<String>, store: &'a MailStoreWithConnec
trace!("Filling arena starting at: {}", root.get_id());
let root_id = root.get_id().clone();
let root_node = arena.new_node(root_id);
+ let root_thread_id = root.get_thread_id().to_owned();
+ drop(root);
store.connection().execute(|db| {
- let q = format!("thread:{}", root.get_thread_id());
+ let q = format!("thread:{}", root_thread_id);
trace!("Executing query: {}", q);
let query = db.create_query(&q)?;
let r = query.search_threads()?
@@ -68,28 +71,36 @@ fn fill_arena_with<'a>(arena: &mut Arena<String>, store: &'a MailStoreWithConnec
let id = msg.id();
trace!("Found Message: {}", id);
- let mail = store.get_mail_by_id(&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());
-
- let new_node_id = arena.new_node(id.into_owned());
+ let id = id.into_owned();
+ let new_node_id = arena.new_node(id.clone());
root_node.append(new_node_id, arena);
-
- trace!("Recursing with: {}", reply.get_id());
- fill_arena_with(arena, store, reply).map(|_| ())
+ id
})
- .collect::<Result<Vec<_>>>()
+ .collect::<Vec<String>>()
})
- .collect::<Result<Vec<_>>>()
- .map(|_| root_node);
-
+ .flat_map(|v| v.into_iter())
+ .unique()
+ .map(Ok)
+ .collect::<Result<Vec<String>>>();
r
+ })?
+ .into_iter()
+ .map(|id: String| {
+ let mail = store.get_mail_by_id(&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());
+
+ 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