Skip to content

Commit

Permalink
wip: use custom struct ThreadedEnvelopes
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed May 18, 2024
1 parent 90e12dd commit 55ba892
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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?;
Expand Down
46 changes: 22 additions & 24 deletions src/email/envelope/command/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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()
Expand Down Expand Up @@ -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 = "
Expand All @@ -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 = "
Expand All @@ -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);

write_tree(&mut buf, &graph, 0, String::new(), 0).unwrap();
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();
let buf = String::from_utf8_lossy(&buf);

let expected = "
Expand Down

0 comments on commit 55ba892

Please sign in to comment.