From 7f81aa6012164f64876c9ad370105792b6042953 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Mon, 18 Jul 2016 19:42:25 +0200 Subject: [PATCH] thread: prune empty messages from top with only one child --- thread.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/thread.c b/thread.c index 829fe02..b645233 100644 --- a/thread.c +++ b/thread.c @@ -242,6 +242,22 @@ find_roots() top->next = 0; } +void +prune_tree(struct container *c, int depth) +{ + do { + if (c->child) + prune_tree(c->child, depth+1); + if (!c->file && c->child && !c->child->next) { + // turn into child if we don't exist and only have a child + c->mid = c->child->mid; + c->file = c->child->file; + c->msg = c->child->msg; + c->child = c->child->child; + } + } while ((c = c->next)); +} + void print_tree(struct container *c, int depth) { @@ -267,7 +283,7 @@ main(int argc, char *argv[]) int i = blaze822_loop(argc-1, argv+1, thread); find_roots(); - + prune_tree(top, -1); print_tree(top, -1); fprintf(stderr, "%d mails threaded\n", i);