[PATCH] devel: add new tool to draw thread structure

Subject: [PATCH] devel: add new tool to draw thread structure

Date: Mon, 9 Apr 2018 22:45:39 -0300

To: David Bremner, Naveen N. Rao, notmuch@notmuchmail.org

Cc:

From: David Bremner


This is useful for understanding the case where different
message-files with the same message-id have distinct reference
headers.
---
 devel/draw-thread | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 devel/draw-thread

diff --git a/devel/draw-thread b/devel/draw-thread
new file mode 100755
index 00000000..628dcff4
--- /dev/null
+++ b/devel/draw-thread
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# This script can be used like
+# NOTMUCH_CONFIG=test/tmp.T580-thread-search/notmuch-config \
+#    devel/draw-thread thread:0000000000000002 | dot -Tpdf > thread2.pdf
+
+# In addition to notmuch, you will need the following tools installed
+# - graphviz
+# - formail (part of procmail)
+
+threadid=$1
+
+declare -a edges
+
+declare -a dest
+echo "digraph \"$threadid\" {"
+for messageid in $(notmuch search --output=messages $threadid); do
+    echo "subgraph \"cluster_$messageid\" {"
+    printf "\"%s\" [shape=folder];\n" ${messageid#id:}
+    for file in $(notmuch search --output=files $messageid); do
+        node=$(basename $file)
+        printf "\"%s\" [shape=note];\n" $node
+
+        mapfile -t dest < <(formail -x references < $file | tr '<>,' '"" ')
+        edge="\"$node\" -> { ${dest[*]} }"
+        edges+=($edge)
+    done
+    echo "}"
+done
+
+for edge in "${edges[*]}"; do
+    echo $edge
+done
+
+echo "}"
-- 
2.16.3

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: