mhl and mhbuild ignore to long lines
[mmh] / uip / whatnow2.sh
index a4a2cc5..f9cf255 100755 (executable)
@@ -38,14 +38,14 @@ usage()
                exit 0
        fi
        printhelp 1>&2
-       exit $1
+       exit 1
 }
 
 get_editor()
 {
        if [ -f "$mhmetafile" ]
        then
-               lasteditor=`anno -list -component 'last-editor' $mhmetafile`
+               lasteditor=`anno -list -component 'mmh-last-editor' "$mhmetafile"`
                if [ -n "$lasteditor" ]
                then
                        editor=`echo $lasteditor | cut -d ' ' -f 1`
@@ -63,6 +63,14 @@ get_editor()
        mheditor=`mhparam 'Editor'`
 }
 
+save_config()
+{
+       component="$1"
+       newtext="$2"
+       anno -delete -number all -component "$component" "$mhmetafile"
+       anno -nodate -component "$component" -text "$newtext" "$mhmetafile"
+}
+
 get_showproc()
 {
        mhshowproc=`mhparam 'listproc'`
@@ -73,20 +81,9 @@ get_realpath()
 {
        reldir=`dirname "$1"`
        filename=`basename "$1"`
-       cd $reldir
+       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
+       cd "$OLDPWD"
 }
 
 create()
@@ -95,38 +92,25 @@ create()
        then
                usage 1
        fi
-       mhmetafile=$mhdraft.meta
-       touch $mhmetafile
-       if [ -z $mheditor ]
+       mhext=`mhparam Metafile-Extension`
+       mhmetafile="$mhdraft""$mhext"
+       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" ]
+       if [ "$mhuse" -eq 1 ]
        then
-               anno -nodate -component 'mhannotate' -text "$mhannotate" $mhmetafile
+               exec $mheditor $mhdraft
+               return
        fi
-       set_lasteditor "$mheditor"
-       exec $mheditor $mhdraft
+       save_config mmh-mhaltmsg "$mhaltmsg"
+       save_config mmh-mhdist "$mhdist"
+       save_config mmh-mhfolder "$mhfolder"
+       save_config mmh-mhmessages "$mhmessages"
+       save_config mmh-mhannotate "$mhannotate"
+       save_config mmh-last-editor "$mheditor"
+       exec $mheditor "$mhdraft"
 }
 
 edit()
@@ -138,8 +122,8 @@ edit()
                mheditor="$@"
        fi
 
-       set_lasteditor "$mheditor"
-       exec $mheditor $mhdraft
+       save_config mmh-last-editor "$mheditor"
+       exec $mheditor "$mhdraft"
 }
 
 list()
@@ -148,29 +132,39 @@ list()
        exec $mhshowproc -file $mhdraft
 }
 
-send()
+sendfunktion()
 {
-       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
+       export mhaltmsg=`anno -list -component 'mmh-mhaltmsg' "$mhmetafile"`
+       export mhdist=`anno -list -component 'mmh-mhdist' "$mhmetafile"`
+       export mhfolder=`anno -list -component 'mmh-mhfolder' "$mhmetafile"`
+       export mhmessages=`anno -list -component 'mmh-mhmessages' "$mhmetafile"`
+       export mhannotate=`anno -list -component 'mmh-mhannotate' "$mhmetafile"`
+       tmp=`mktemp`
+       cp "$mhdraft" "$tmp"
+       mhl -form mhl.whatnow2 "$tmp" > "$mhdraft"
+       mhle="$?"
+       if [ "$mhle" -ne 0 ]
+       then
+               mv "$tmp" "$mhdraft"
+               exit "$mhle"
+       fi
+       send "$@" "$mhdraft" || exit $?
+       rm -f "$mhmetafile"
+       rm -f "$tmp"
+       exit 0
 }
 
 delete()
 {
-       folder -push $draftfolder >/dev/null 2>&1
-       rmm $draftfolder c
+       folder -push "$draftfolder" >/dev/null 2>&1
+       rmm "$draftfolder" c
        folder -pop >/dev/null 2>&1
-       rm $mhmetafile
+       rm "$mhmetafile"
 }
 
 attach()
 {
-       get_attachmentheader
+       header=`mhparam 'Attachment-Header'`
        while [ -n "$1" ]
        do
                if [ ! -f "$1" ]
@@ -183,23 +177,23 @@ attach()
                        exit 1
                fi
                file=`get_realpath "$1"`
-               anno -nodate -append -component $header -text "$file" $mhdraft
+               anno -nodate -append -component "$header" -text "$file" "$mhdraft"
                shift
        done
 }
 
 alist()
 {
-       get_attachmentheader
-       anno -list -number -component $header $mhdraft
+       header=`mhparam 'Attachment-Header'`
+       anno -list -number -component "$header" "$mhdraft"
 }
 
 detach()
 {
-       get_attachmentheader
+       header=`mhparam 'Attachment-Header'`
        while [ -n "$1" ]
        do
-               anno -delete -component $header -number "$1" $mhdraft
+               anno -delete -component "$header" -number "$1" "$mhdraft"
                if [ $? -ne 0 ]
                then
                        echo "can't delet attachment $1" 1>&2
@@ -211,14 +205,14 @@ detach()
 
 display()
 {
-       mhaltmsg=`anno -list -component 'mhaltmsg' $mhmetafile`
+       mhaltmsg=`anno -list -component 'mmh-mhaltmsg' "$mhmetafile"`
        get_showproc
-       if [ -n "$mhaltmsg" ]
+       if [ -z "$mhaltmsg" ]
        then
                echo "no altmsg" 1>&2
                exit 1
        fi
-       exec $mhshowproc -file $mhaltmsg
+       exec $mhshowproc -file "$mhaltmsg"
 }
 
 if [ $# -eq 0 ]
@@ -227,32 +221,33 @@ then
        exit
 fi
 
-command=$1
+command="$1"
 shift
 
 draftfolder=`mhparam draftfolder`
 
-mhdraft=`mhpath $draftfolder c 2>/dev/null`
+mhdraft=`mhpath "$draftfolder" c 2>/dev/null`
 if [ -z "$mhdraft" ]
 then
-       case $command in
-       -h*)
+       case "$command" in
+       -h|-he|-hel|-help)
                usage $#
                ;;
-       -V*)
+       -V|-Ve|-Ver|-Vers|-Versi|-Versio|-Version)
                version $#
                ;;
        *)
-               echo "no current message in $draftsfolder" 1>&2
+               echo "no current message in $draftfolder" 1>&2
                usage 1
                ;;
        esac
 fi
-mhmetafile=$mhdraft.meta
-touch $mhmetafile
+mhext=`mhparam Metafile-Extension`
+mhmetafile="$mhdraft""$mhext"
+touch "$mhmetafile"
 
 
-case $command in
+case "$command" in
 e|ed|edi|edit)
        edit "$@"
        ;;
@@ -261,9 +256,9 @@ l|li|lis|list)
        list
        ;;
 s|se|sen|send)
-       send "$@"
+       sendfunktion "$@"
        ;;
-del|dele|delet)
+del|dele|delet|delete)
        [ $# -eq 0 ] || usage 1
        delete
        ;;
@@ -282,10 +277,10 @@ det|deta|detac|detach)
        detach "$@"
        ;;
 r|re|ref|refi|refil|refile)
-       refile -file $mhdraft "$@"
+       refile -file "$mhdraft" "$@"
        ;;
 w|wh|who|whom)
-       whom "$@" $mhdraft
+       whom "$@" "$mhdraft"
        ;;
 -h|-he|-hel|-help)
        usage $#
@@ -293,4 +288,7 @@ w|wh|who|whom)
 -V|-Ve|-Ver|-Vers|-Versi|-Versio|-Version)
        version $#
        ;;
+*)
+       usage 1
+       ;;
 esac