add my whatnow replacement whatnow2
authorPhilipp Takacs <philipp@bureaucracy.de>
Sat, 27 Feb 2016 18:58:42 +0000 (19:58 +0100)
committerPhilipp Takacs <philipp@bureaucracy.de>
Sat, 30 Jul 2016 20:23:12 +0000 (22:23 +0200)
whatnow2 is tool which acts like whatnow, but
don't trap the user in it.

man/Makefile.in
man/whatnow2.man1 [new file with mode: 0644]
uip/Makefile.in
uip/whatnow2.sh [new file with mode: 0755]

index ffa1203..9a27e82 100644 (file)
@@ -54,7 +54,7 @@ MAN1SRC = ali. anno. burst. comp. dist. flist. flists. folder. folders. \
        mhmail. mhparam. mhpath. mhstore. new. fnext. \
        fprev. unseen. next. packf. pick. prev. prompter. rcvdist. rcvpack. \
        rcvstore. refile. repl. rmf. rmm. scan. send. sendfiles. \
-       show. slocal. sortm. whatnow. whom.
+       show. slocal. sortm. whatnow. whom. whatnow2.
 
 MAN5SRC = mh-alias. mh-format. mh-mail. mh-profile.
 
diff --git a/man/whatnow2.man1 b/man/whatnow2.man1
new file mode 100644 (file)
index 0000000..a9e1a84
--- /dev/null
@@ -0,0 +1,134 @@
+.\"
+.\" %nmhwarning%
+.\"
+.TH WHATNOW %manext1% "%nmhdate%" MH.6.8 [%nmhversion%]
+.SH NAME
+whatnow \- front-end for handling drafts
+.SH SYNOPSIS
+.HP 5
+.na
+.B whatnow
+.RI [ command
+.RB | \-Version ]
+.RB | \-help ]
+.ad
+.SH DESCRIPTION
+.B Whatnow
+is the default program that queries the user about
+the disposition of a composed draft.  It is normally automatically
+invoked by one of the
+.B mmh
+commands
+.BR comp ,
+.BR dist ,
+.BR forw ,
+or
+.B repl
+after the initial edit.
+.PP
+When started, the editor is started on the draft. Then,
+.B whatnow
+can called with one of the commands.
+.PP
+.RS 5
+.TP \w'refilezzzzfolderz'u
+.B edit
+re\-edit using the same editor that was used on the
+preceding round unless a profile entry
+`<lasteditor>\-next: <editor>' names an alternate editor
+.TP \w'refilezzzzfolderz'u
+.B edit <editor>
+invoke <editor> for further editing
+.TP \w'refilezzzzfolderz'u
+.B list
+list the draft on the terminal
+.TP \w'refilezzzzfolderz'u
+.B display
+list the message being distributed/replied\-to on the terminal
+.TP \w'refilezzzzfolderz'u
+.B whom
+list the recipients of the message
+.TP \w'refilezzzzfolderz'u
+.B send
+send the message
+.TP \w'refilezzzzfolderz'u
+.B refile +folder
+refile the draft into the given folder
+.TP \w'refilezzzzfolderz'u
+.B delete
+delete the draft and exit
+.TP \w'refilezzzzfolderz'u
+.B attach files
+add the named files to the draft as MIME attachments
+.TP \w'refilezzzzfolderz'u
+.B alist
+list the MIME attachments
+.TP \w'refilezzzzfolderz'u
+.B detach numbers
+remove MIME attachments by number
+.RE
+.PP
+When entering your response, you need only type enough characters
+to uniquely identify the response.
+.PP
+For the
+.B edit
+response, any valid switch to the editor is valid.
+.PP
+For the
+.B send
+response, any valid switch to
+.BR send (1)
+is valid.
+.PP
+For the
+.B refile
+response, any valid switch to
+.B refile
+is valid.
+.PP
+See
+.BR mh\-profile (5)
+for further information about how editors
+are used by
+.BR mmh .
+It also discusses how environment variables can be
+used to direct
+.BR whatnow 's
+actions in complex ways.
+.PP
+If the initial edit fails, no new draft is created, but any
+existing re-used draft is preserved.
+Failures of later edits are ignored and another prompt is printed.
+.PP
+Consult the
+.BR mh-draft (7)
+man page for more
+information.
+
+.SH FILES
+.fc ^ ~
+.nf
+.ta \w'%etcdir%/ExtraBigFileName  'u
+^$HOME/.mmh/profile~^The user profile
+^+drafts~^The draft folder
+.fi
+
+.SH "PROFILE COMPONENTS"
+.fc ^ ~
+.nf
+.ta 2.4i
+.ta \w'ExtraBigProfileName  'u
+^Path:~^To determine the user's mail storage
+^Draft\-Folder:~^To set the default draft\-folder
+^Editor:~^To override the default editor
+^<lasteditor>\-next:~^To name an editor to be used after exit
+^~^from <lasteditor>
+^listproc:~^Program to list the contents of a message
+.fi
+
+.SH "SEE ALSO"
+send(1)
+
+.SH CONTEXT
+None
index 6b7a570..d7cad06 100644 (file)
@@ -58,7 +58,7 @@ CMDS = ali anno burst comp dist flist folder forw mmh mark \
 LCMDS = flists folders next prev fnext fprev unseen
 
 # misc support binaries
-MISC = ap dp fmtdump mhtest mmhwrap
+MISC = ap dp fmtdump mhtest mmhwrap whatnow2
 
 # commands with 'S'pecial installation needs
 SCMDS = inc
@@ -74,7 +74,7 @@ SRCS = ali.c aliasbr.c anno.c ap.c burst.c comp.c \
        prompter.c rcvdist.c rcvpack.c rcvstore.c \
        refile.c repl.c rmf.c rmm.c scan.c scansbr.c send.c \
        sendfiles.sh slocal.c sortm.c spost.c termsbr.c \
-       whatnow.c whatnowproc.c whom.c
+       whatnow.c whatnowproc.c whom.c whatnow2.sh
 
 # ========== DEFAULT TARGET ==========
 
@@ -223,6 +223,9 @@ spost: spost.o aliasbr.o $(LOCALLIBS)
 whatnow: whatnow.o $(LOCALLIBS)
        $(LINK) whatnow.o $(LINKLIBS)
 
+whatnow2: whatnow2.sh
+       cp $(srcdir)/whatnow2.sh whatnow2
+
 whom: whom.o $(LOCALLIBS)
        $(LINK) whom.o $(LINKLIBS)
 
diff --git a/uip/whatnow2.sh b/uip/whatnow2.sh
new file mode 100755 (executable)
index 0000000..a4be1a9
--- /dev/null
@@ -0,0 +1,312 @@
+#!/bin/sh
+
+printhelp()
+{
+       echo "Usage: $0 command"
+       echo "  commands are:"
+       echo "  edit [editor]"
+       echo "  list"
+       echo "  send [sendargs]"
+       echo "  delete"
+       echo "  display"
+       echo "  attach files"
+       echo "  alist"
+       echo "  detach anum"
+       echo "  refile +folder"
+       echo "  -help"
+       echo "  -Version"
+}
+
+version()
+{
+       if [ $# -eq 0 ]
+       then
+               echo "$0 has no own version number, thus this instead:"
+               folder -Version
+               exit 0
+       fi
+       echo "$0 has no own version number, thus this instead:" 1>&2
+       folder -Version 1>&2
+       exit 1
+}
+
+usage()
+{
+       if [ $1 -eq 0 ]
+       then
+               printhelp
+               exit 0
+       fi
+       printhelp 1>&2
+       exit $1
+}
+
+get_editor()
+{
+       if [ -f "$mhmetafile" ]
+       then
+               lasteditor=`anno -list -component 'last-editor' $mhmetafile`
+               if [ -n "$lasteditor" ]
+               then
+                       editor=`echo $lasteditor | cut -d ' ' -f 1`
+                       mheditor=`mhparam "$editor-next"`
+                       [ -n "$mheditor" ] && return
+                       mheditor=$lasteditor
+                       return
+               fi
+       fi
+       if [ -n "$MMHEDITOR" ]
+       then
+               mheditor=$MMHEDITOR
+               return
+       fi
+       mheditor=`mhparam 'Editor'`
+       if [ -n "$mheditor" ]
+       then
+               return
+       fi
+       if [ -n "$VISUAL" ]
+       then
+               mheditor=$VISUAL
+               return
+       fi
+       if [ -n "$EDITOR" ]
+       then
+               mheditor=$EDITOR
+               return
+       fi
+       mheditor=vi
+}
+
+get_showproc()
+{
+       mhshowproc=`mhparam 'listproc'`
+       return
+}
+
+get_realpath()
+{
+       reldir=`dirname "$1"`
+       filename=`basename "$1"`
+       cd $reldir
+       echo "$PWD/$filename"
+       cd -
+}
+
+get_attachmentheader()
+{
+       header=`mhparam 'Attachment-Header'`
+}
+
+set_lasteditor()
+{
+       anno -delete -number all -component 'last-editor' $mhmetafile
+       anno -nodate -component 'last-editor' -text "$1" $mhmetafile
+}
+
+create()
+{
+       if [ -z "$mhdraft" ]
+       then
+               usage 1
+       fi
+       mhmetafile=$mhdraft.meta
+       touch $mhmetafile
+       if [ -z $mheditor ]
+       then
+               get_editor
+       fi
+       if [ -n "$mhaltmsg" ]
+       then
+               anno -nodate -component 'mhaltmsg' -text "$mhaltmsg" $mhmetafile
+       fi
+       if [ -n "$mhdist" ]
+       then
+               anno -nodate -component 'mhdist' -text "$mhdist" $mhmetafile
+       fi
+       if [ -n "$mhdist" ]
+       then
+               anno -nodate -component 'mhuse' -text "$mhuse" $mhmetafile
+       fi
+       if [ -n "$mhfolder" ]
+       then
+               anno -nodate -component 'mhfolder' -text "$mhfolder" $mhmetafile
+       fi
+       if [ -n "$mhmessages" ]
+       then
+               anno -nodate -component 'mhmessages' -text "$mhmessages" $mhmetafile
+       fi
+       if [ -n "$mhannotate" ]
+       then
+               anno -nodate -component 'mhannotate' -text "$mhannotate" $mhmetafile
+       fi
+       set_lasteditor "$mheditor"
+       exec $mheditor $mhdraft
+}
+
+edit()
+{
+       if [ $# -eq 0 ]
+       then
+               get_editor
+       else
+               mheditor="$@"
+       fi
+
+       set_lasteditor "$mheditor"
+       exec $mheditor $mhdraft
+}
+
+list()
+{
+       get_showproc
+       exec $mhshowproc -file $mhdraft
+}
+
+send()
+{
+       export mhaltmsg=`anno -list -component 'mhaltmsg' $mhmetafile`
+       export mhdist=`anno -list -component 'mhdist' $mhmetafile`
+       export mhuse=`anno -list -component 'mhuse' $mhmetafile`
+       export mhfolder=`anno -list -component 'mhfolder' $mhmetafile`
+       export mhmessages=`anno -list -component 'mhmessages' $mhmetafile`
+       export mhannotate=`anno -list -component 'mhannotate' $mhmetafile`
+       rm -f $mhmetafile
+       exec send "$@" $mhdraft
+}
+
+delete()
+{
+       rmm +draft c
+       rm $mhmetafile
+}
+
+attach()
+{
+       get_attachmentheader
+       while [ -n "$1" ]
+       do
+               if [ ! -f "$1" ]
+               then
+                       echo "file not found: $1" 1>&2
+                       shift
+                       echo -n "folloing files are not attached: " 1>&2
+                       echo -n "$1" 1>&2
+                       echo "$@" 1>&2
+                       exit 1
+               fi
+               file=`get_realpath "$1"`
+               anno -nodate -append -component $header -text "$file" $mhdraft
+               shift
+       done
+}
+
+alist()
+{
+       get_attachmentheader
+       anno -list -number -component $header $mhdraft
+}
+
+detach()
+{
+       get_attachmentheader
+       while [ -n "$1" ]
+       do
+               anno -delete -component $header -number "$1" $mhdraft
+               if [ $? -ne 0 ]
+               then
+                       echo "can't delet attachment $1" 1>&2
+                       exit 1
+               fi
+               shift
+       done
+}
+
+display()
+{
+       mhaltmsg=`anno -list -component 'mhaltmsg' $mhmetafile`
+       get_showproc
+       if [ -n "$mhaltmsg" ]
+       then
+               echo "no altmsg" 1>&2
+               exit 1
+       fi
+       exec $mhshowproc -file $mhaltmsg
+}
+
+if [ $# -eq 0 ]
+then
+       create
+       exit
+fi
+
+command=$1
+shift
+
+draftfolder=`mhparam Draft-Folder`
+if [ -z "$dratffolder" ]
+then
+    draftfolder="+drafts"
+fi
+mhdraft=`mhpath $draftfolder c 2>/dev/null`
+if [ -z "$mhdraft" ]
+then
+       case $command in
+       -h*)
+               usage $#
+               ;;
+       -V*)
+               version $#
+               ;;
+       *)
+               echo "no current message in $draftsfolder" 1>&2
+               usage 1
+               ;;
+       esac
+fi
+mhmetafile=$mhdraft.meta
+touch $mhmetafile
+
+
+case $command in
+e*)
+       edit "$@"
+       ;;
+l*)
+       [ $# -eq 0 ] || usage 1
+       list
+       ;;
+s*)
+       send "$@"
+       ;;
+del*)
+       [ $# -eq 0 ] || usage 1
+       delete
+       ;;
+di*)
+       [ $# -eq 0 ] || usage 1
+       display
+       ;;
+at*)
+       attach "$@"
+       ;;
+al*)
+       [ $# -eq 0 ] || usage 1
+       alist
+       ;;
+det*)
+       detach "$@"
+       ;;
+r*)
+       refile -nolink -file $mhdraft "$@"
+       ;;
+w*)
+       whom "$@" $mhdraft
+       ;;
+-h*)
+       usage $#
+       ;;
+-V*)
+       version $#
+       ;;
+esac