3 # Fire up mutt on a given mail, located in some Maildir
4 # Mail can be specified either by path or by Messsage-ID; in the latter case
5 # file lookup is performed using some mail indexing tool.
7 # Copyright: © 2009-2011 Stefano Zacchiroli <zack@upsilon.cc>
8 # License: GNU General Public License (GPL), version 3 or above
10 # requires maildir-utils >= 0.7
14 HIDE_SIDEBAR_CMD="B" # set to empty string if sidebar is not used
16 # Sample output of 'mu find -f l i:MESSAGE-ID', which gets passed to mutt-open
17 # /home/zack/Maildir/INBOX/cur/1256673179_0.8700.usha,U=37420,FMD5=7e33429f656f1e6e9d79b29c3f82c57e:2,S
20 echo "Usage: mutt-open FILE" 1>&2
21 echo " mutt-open MESSAGE-ID" 1>&2
22 echo 'E.g.: mutt-open `mu find -f l i:MESSAGE-ID`' 1>&2
23 echo ' mutt-open 20091030112543.GA4230@usha.takhisis.invalid' 1>&2
27 # Lookup: Message-ID -> mail path. Store results in global $fname
29 #fname=$(mu find -f p m:"$1" | head -n 1)
30 fname=$(mu find -f l i:"$1" | head -n 1)
38 if [ -z "$1" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
41 if (echo "$1" | grep -q /) && test -f "$1" ; then # arg is a file
43 msgid=$(egrep -i '^message-id:' "$fname" | cut -f 2 -d':' | sed 's/[ <>]//g')
44 elif ! (echo "$1" | grep -q /) ; then # arg is a Message-ID
46 lookup_msgid "$msgid" # side-effect: set $fname
49 if ! dirname "$fname" | egrep -q '/(cur|new|tmp)$' ; then
50 echo "Path not pointing inside a maildir: $fname" 1>&2
53 maildir=$(dirname $(dirname "$fname"))
55 if ! [ -d "$maildir" ] ; then
56 echo "Not a (mail)dir: $maildir" 1>&1
60 # UGLY HACK: without sleep, push keys do not reach mutt, I _guess_ that there
61 # might be some terminal-related issue here, since also waiting for an input
62 # with "read" similarly "solves" the problem
64 mutt_keys="$HIDE_SIDEBAR_CMD/~i$msgid\n\n"
65 exec $MUTT $MUTT_FLAGS -f "$maildir/" -e "push $mutt_keys"