aboutsummaryrefslogtreecommitdiff
path: root/bin/mutt-open
diff options
context:
space:
mode:
authorRaul Benencia <rul@kalgan.cc>2020-05-24 13:44:14 -0700
committerRaul Benencia <rul@kalgan.cc>2020-05-24 13:47:59 -0700
commit546a3a211a0d59f14edbd97c1990476e84a46247 (patch)
treec5709cc4a8f7b0f39e1cb023f0f6b03bf749272e /bin/mutt-open
parent3589f3e66769e87831e9f31fb3493064dd3ce73e (diff)
Add bin/ repo from home-bin/ repo
Diffstat (limited to 'bin/mutt-open')
-rwxr-xr-xbin/mutt-open76
1 files changed, 76 insertions, 0 deletions
diff --git a/bin/mutt-open b/bin/mutt-open
new file mode 100755
index 0000000..0b21261
--- /dev/null
+++ b/bin/mutt-open
@@ -0,0 +1,76 @@
+#!/bin/bash
+#
+# Fire up mutt on a given mail, located in some Maildir
+# Mail can be specified either by path or by Messsage-ID; in the latter case
+# file lookup is performed using some mail indexing tool.
+#
+# Copyright: © 2009-2014 Stefano Zacchiroli <zack@upsilon.cc>
+# License: GNU General Public License (GPL), version 3 or above
+
+# requires: notmuch | maildir-utils >= 0.7
+
+MUTT="neomutt"
+MAIL_INDEXER="notmuch" # one of "notmuch", "mu"
+export NOTMUCH_CONFIG=$HOME/te/etc/notmuch-config
+
+MUTT_FLAGS="-R -F ~/te/etc/muttrc"
+HIDE_SIDEBAR_CMD="B" # set to empty string if sidebar is not used
+
+# Sample output of lookup command, which gets passed to mutt-open
+# /home/zack/Maildir/INBOX/cur/1256673179_0.8700.usha,U=37420,FMD5=7e33429f656f1e6e9d79b29c3f82c57e:2,S
+
+die_usage () {
+ echo "Usage: mutt-open FILE" 1>&2
+ echo " mutt-open MESSAGE-ID" 1>&2
+ echo 'E.g.: mutt-open `notmuch search --output=files id:MESSAGE-ID`' 1>&2
+ echo ' mutt-open `mu find -f l i:MESSAGE-ID`' 1>&2
+ echo ' mutt-open 20091030112543.GA4230@usha.takhisis.invalid' 1>&2
+ exit 3
+}
+
+# Lookup: Message-ID -> mail path. Store results in global $fname
+lookup_msgid () {
+ msgid_query="$1"
+ case "$MAIL_INDEXER" in
+ notmuch)
+ fname=$(notmuch search --output=files id:"$msgid_query" | head -n 1)
+ ;;
+ mu)
+ fname=$(mu find -f l i:"$msgid_query" | head -n 1)
+ ;;
+ esac
+}
+
+dump_info () {
+ echo "fname: $fname"
+ echo "msgid: $msgid"
+}
+
+if [ -z "$1" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
+ die_usage
+fi
+if (echo "$1" | grep -q /) && test -f "$1" ; then # arg is a file
+ fname="$1"
+ msgid=$(egrep -i '^message-id:' "$fname" | cut -f 2 -d':' | sed 's/[ <>]//g')
+elif ! (echo "$1" | grep -q /) ; then # arg is a Message-ID
+ msgid="$1"
+ lookup_msgid "$msgid" # side-effect: set $fname
+fi
+# dump_info ; exit 3
+if ! dirname "$fname" | egrep -q '/(cur|new|tmp)$' ; then
+ echo "Path not pointing inside a maildir: $fname" 1>&2
+ exit 2
+fi
+maildir=$(dirname $(dirname "$fname"))
+
+if ! [ -d "$maildir" ] ; then
+ echo "Not a (mail)dir: $maildir" 1>&1
+ exit 2
+fi
+
+# UGLY HACK: without sleep, push keys do not reach mutt, I _guess_ that there
+# might be some terminal-related issue here, since also waiting for an input
+# with "read" similarly "solves" the problem
+sleep 0.5
+mutt_keys="/=i$msgid\n\n$HIDE_SIDEBAR_CMD"
+exec $MUTT $MUTT_FLAGS -f "$maildir/" -e "push $mutt_keys"
nihil fit ex nihilo