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

David Bremner david at tethera.net
Mon Apr 9 18:45:39 PDT 2018


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



More information about the notmuch mailing list