wip: use custom struct ThreadedEnvelopes

This commit is contained in:
Clément DOUIN 2024-05-18 09:45:03 +02:00
parent 90e12ddc51
commit 55ba892436
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
2 changed files with 23 additions and 25 deletions

View file

@ -26,7 +26,7 @@ use email::{
list::{ListEnvelopes, ListEnvelopesOptions},
thread::ThreadEnvelopes,
watch::WatchEnvelopes,
Id, SingleId,
Id, SingleId, ThreadedEnvelopes,
},
flag::{add::AddFlags, remove::RemoveFlags, set::SetFlags, Flag, Flags},
folder::{
@ -710,7 +710,7 @@ impl Backend {
&self,
folder: &str,
opts: ListEnvelopesOptions,
) -> Result<DiGraphMap<u32, u32>> {
) -> Result<ThreadedEnvelopes> {
let backend_kind = self.toml_account_config.thread_envelopes_kind();
let id_mapper = self.build_id_mapper(folder, backend_kind)?;
let envelopes = self.backend.thread_envelopes(folder, opts).await?;

View file

@ -204,12 +204,10 @@ impl ThreadEnvelopesCommand {
query: None,
};
let graph = backend.thread_envelopes(folder, opts).await?;
println!("graph: {graph:#?}");
let envelopes = backend.thread_envelopes(folder, opts).await?;
let mut stdout = std::io::stdout();
write_tree(&mut stdout, &graph, 0, String::new(), 0)?;
write_tree(&mut stdout, envelopes.graph(), "root", String::new(), 0)?;
stdout.flush()?;
// printer.print_table(envelopes, self.table_max_width)?;
@ -220,10 +218,10 @@ impl ThreadEnvelopesCommand {
pub fn write_tree(
w: &mut impl std::io::Write,
graph: &DiGraphMap<u32, u32>,
parent: u32,
graph: &DiGraphMap<&str, u8>,
parent: &str,
pad: String,
weight: u32,
weight: u8,
) -> std::io::Result<()> {
let edges = graph
.all_edges()
@ -264,11 +262,11 @@ mod test {
fn tree_1() {
let mut buf = Vec::new();
let mut graph = DiGraphMap::new();
graph.add_edge(0, 1, 0);
graph.add_edge(0, 2, 0);
graph.add_edge(0, 3, 0);
graph.add_edge("0", "1", 0);
graph.add_edge("0", "2", 0);
graph.add_edge("0", "3", 0);
write_tree(&mut buf, &graph, 0, String::new(), 0).unwrap();
write_tree(&mut buf, &graph, "0", String::new(), 0).unwrap();
let buf = String::from_utf8_lossy(&buf);
let expected = "
@ -284,11 +282,11 @@ mod test {
fn tree_2() {
let mut buf = Vec::new();
let mut graph = DiGraphMap::new();
graph.add_edge(0, 1, 0);
graph.add_edge(1, 2, 1);
graph.add_edge(1, 3, 1);
graph.add_edge("0", "1", 0);
graph.add_edge("1", "2", 1);
graph.add_edge("1", "3", 1);
write_tree(&mut buf, &graph, 0, String::new(), 0).unwrap();
write_tree(&mut buf, &graph, "0", String::new(), 0).unwrap();
let buf = String::from_utf8_lossy(&buf);
let expected = "
@ -304,15 +302,15 @@ mod test {
fn tree_3() {
let mut buf = Vec::new();
let mut graph = DiGraphMap::new();
graph.add_edge(0, 1, 0);
graph.add_edge(1, 2, 1);
graph.add_edge(2, 22, 2);
graph.add_edge(1, 3, 1);
graph.add_edge(0, 4, 0);
graph.add_edge(4, 5, 1);
graph.add_edge(5, 6, 2);
graph.add_edge("0", "1", 0);
graph.add_edge("1", "2", 1);
graph.add_edge("2", "22", 2);
graph.add_edge("1", "3", 1);
graph.add_edge("0", "4", 0);
graph.add_edge("4", "5", 1);
graph.add_edge("5", "6", 2);
write_tree(&mut buf, &graph, 0, String::new(), 0).unwrap();
write_tree(&mut buf, &graph, "0", String::new(), 0).unwrap();
let buf = String::from_utf8_lossy(&buf);
let expected = "