MU=${MU:-mu}
NMZMAIL=${NMZMAIL:-nmzmail}
SCREEN=${SCREEN:-screen}
+FORMAIL=${FORMAIL:-formail}
+REFORMAIL=${REFORMAIL:-reformail}
function die () {
echo -e >&2 "$0: $1"
die "$MUTT is not in PATH, set MUTT variable"
fi
+case $MUTTJUMP_MODE in
+ limit|search)
+ ;;
+ *)
+ die "variable MUTTJUMP_MODE must be set to \"limit\" or \"search\""
+ ;;
+esac
+
# search for Message-ID in STDIN
-msgid=$(sed -n 's/^Message-ID: \(.*\)/\1/Ip' | head -n1)
+if type -p $FORMAIL >/dev/null ; then
+ msgid=$($FORMAIL -c -z -x Message-ID | head -n1)
+elif type -p $REFORMAIL >/dev/null ; then
+ msgid=$($REFORMAIL -c -x Message-ID: | head -n1)
+else
+ msgid=$(sed -n 's/^Message-ID: \(.*\)/\1/Ip' | head -n1)
+fi
if [ -z "$msgid" ] ; then
die "could not find Message-ID header in standard input"
fi
die "directory \"$orig_maildir\" doesn't exist or is no Maildir"
fi
-jump_cmd="<change-folder>$orig_maildir<enter><$MUTTJUMP_MODE>~i $msgid<enter>"
+jump_cmd="<change-folder>$orig_maildir<enter><$MUTTJUMP_MODE>~i '$msgid'<enter>"
if [ "$MUTTJUMP_USE_SCREEN" = no ] ; then
screen_opts="-S $MUTTJUMP_SCREEN_SESSION"
fi
- $SCREEN $screen_opts -X eval "select $screen_window_name" "stuff ':push \"$jump_cmd\"
-'"
+ $SCREEN $screen_opts -X eval "select $screen_window_name" "stuff \":push \\\"$jump_cmd\\\"
+\""
if [ $? != 0 ] ; then
die "You have to manually start a screen session with:
$SCREEN $screen_opts -t $screen_window_name $MUTT -f \"$orig_maildir\""