#!/bin/bash # Copyright 2006 John Duncan # Designed to enable PAN file attachment when invoked as the external editor. # As such, it may be distributed under the same license conditions, or # under the terms of the GNU General Public License v2.0 or higher (at your option). # http://pan.rebelbase.com/ or http://www.gnu.org/licenses/gpl.html. NAME="pan-attach-kd" VERSION="0.0.2006.10.07.0" BODYFILE=${1:--h} ################################################################################ # description and help HELP="\n $NAME, version $VERSION, Copyright 2006 John Duncan\n =======================================================\n Description:\n $NAME is designed to enable PAN file attachment when invoked as its\n external editor. $NAME has two requirements, KDE's kdialog, and\n uuenview from the uudeview package, the home page of which is\n http://www.fpx.de/fp/Software/UUDeview/\n =======================================================\n Parameters:\n Set PAN's external editor to $NAME %t. (%t is the name of the\n temporary edit file as pan passes it to the editor.) $NAME takes\n only that single parameter, either the file containing the body text\n as passed from PAN, or -h or --help for this text.\n =======================================================\n Encoding dialog:\n After starting, $NAME first asks for the encode type.\n Here, you may set uuencode, yenc, or text/identity, or select\n help, which displays this text, or pass-thru, see environment, below.\n (uuenview does mime as well, but pan would have to support it too.)\n NOTE: pan \> 0.90 won\'t take yenc at the time of this writing!\n =======================================================\n File dialog:\n =======================================================\n Environment:\n You can set the \$PAN_EDITOR variable if you don't want to give up your\n real external editor functionality. If $NAME finds that set and\n you choose pass-thru for your \"encoding\", $NAME will pass-thru\n to that editor, again as \$PAN_EDITOR %t.\n" # test for no parameter, or invoked with -h or --help [ "$BODYFILE" = "-h" -o "$BODYFILE" = "--help" ] && echo -e $HELP && exit # If kdialog isn't in the path, invoke help and exit, so we know it is after this. kdialog -v 1>&- 2>&- || { echo -e $HELP; exit; } ################################################################################ # First dialog, encoding e_dialog () { local PROMPT="Choose an encoding or pass-thru or help " local yenc="yenc (not on new pan)" ENCODE=$(kdialog --title $NAME --menu "$PROMPT" u uuencode y "$yenc" t text/identity p pass-thru h help) || exit } # We want to loop on this dialog as long as they select help... ENCODE=h while [ "$ENCODE" = "h" ]; do e_dialog if [ "$ENCODE" = "h" ] ; then kdialog --title $NAME --msgbox "$(echo -e "$HELP")" fi done unset -f e_dialog # OK, $ENCODE will now be one of u/uue, y/yenc, t/text, or p/pass-thru ################################################################################ # This section invokes help and exits if the first parameter # isn't an existing regular file with rw perms. param_fail () { local failbegin="Error! The only parameter must be a " local failend="file (or --help).\n Continue with help before exiting?" kdialog --title $NAME --warningcontinuecancel "$failbegin $failtype $failend" || exit kdialog --title $NAME --msgbox "$(echo -e "$HELP")" exit } failtype=none [ ! -w $BODYFILE ] && failtype=writable [ ! -r $BODYFILE ] && failtype=readable [ ! -f $BODYFILE ] && failtype=regular [ ! "$failtype" = "none" ] && param_fail unset failtype HELP unset -f param_fail ################################################################################ # This section deals with pass-thru. if [ "$ENCODE" = "p" ]; then if [ -x "${PAN_EDITOR}" ]; then exec ${PAN_EDITOR} ${BODYFILE} else HELP="No pass-thru editor set!\n If you want to pass through to an external editor of your choice,\n set and export the \$PAN_EDITOR variable appropriately, and\n $NAME can call it (as \$PAN_EDITOR %file)." kdialog --title $NAME --error "$HELP" exit fi fi # OK, all that's left is the real encoding choices, u/uue, y/yenc, and t/text. ################################################################################ # Second dialog, pick the file(s) f_dialog () { ATFILE=$(kdialog --title "Attach file - $NAME" --getopenfilename :$NAME) || exit } f_dialog #Is ${ATFILE} actually readable? If not, error out. while [ ! -r ${ATFILE} ]; do kdialog --error "The file you said to attach,\n ${ATFILE}\n wasn't readable!" f_dialog done ################################################################################ # OK, we know the attach file is readable, and we know what encoding to use, so... echo >> ${BODYFILE} echo >> ${BODYFILE} uuenview -${ENCODE} ${ATFILE} >> ${BODYFILE} ################################################################################ # debugging aids #konsole --noclose --nohist -e echo $ #exec kwrite $BODYFILE