#!/bin/bash me=${0##*/} usage() { exec 1>&2 cat <<-EOF usage: from within vi, use: !!$me {|} ... Invoke while positioned on the header/message separation line, which should look something like \"-------:\" (and which will be duplicated in the output). Inserts 'Attach:' headers for all of the given filenames or MH messages specifiers (but not both -- invoke twice instead). EOF exit 1 } case "$1" in -*|"") usage ;; esac read inputline if echo "$inputline" | grep -qv '^-\+-:$' then echo 'Error: run this only on the "------:" header separator line.' exit 1 fi curfold=$(folder -fast) # arrange to emit the separator line and restore current folder on exit trap 'echo "$inputline"; test "$chfold" && folder +$curfold >/dev/null' 0 # first get a +folder arg for a in "$@" do case $a in address@hidden) if [ "$chfold" ] then echo "$me: only one folder at a time!" exit 1 fi folder $a >/dev/null || exit 1 chfold=true mh=true ;; esac done # check each arg as a valid msg spec # i'd like to just run: # pick -noseq "$@" >/dev/null 2>&1 && mh=true # but this will fail for "cur" if cur isn't valid. for a in "$@" do case $a in cur|cur[:=-]*) pick -noseq $a >/dev/null || exit 1 mh=true ;; *) if pick -noseq $a >/dev/null 2>&1 then mh=true else not_mh="$a" break fi ;; esac done if [ "$mh" -a "$not_mh" ] then echo "** Don't mix pathnames and MH message specifiers: '$a' **" exit 1 fi if [ "$mh" ] # we've got message specifiers then mhpath "$@" | sed 's/^/Attach: /' exit 0 # can't use 'mhpath "$@"' because we want to check existence for p in $(mhpath "$@") do if [ -e $p ] then echo "Attach: $p" else echo "** No such message '$p' **" exit 1 fi done exit 0 else # we've got files for f in "$@" do if [ -f $f ] then echo "Attach: $f" else if [ -e $f ] then echo "** Not a regular file: '$f' **" else echo "** No such file: '$f' **" fi #exit 1 fi continue done fi exit 0