mailfile revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
0N/A##########################################################################
3261N/A# mailfile
0N/A# Jeff Korn
0N/A#
0N/A# This script allows the user to email a file or directory to another
0N/A# user. It will gzip and uuencode files (if necessary) and tar
2362N/A# directories. If the COMPRESS enviroment variable is set, it will
0N/A# use the program COMPRESS instead of gzip.
2362N/A##########################################################################
0N/A
0N/Aif [[ $tk_version = "" ]]
0N/Athen
0N/A if whence tksh > /dev/null
0N/A then
0N/A tk_version=xxx exec tksh $0
0N/A else
0N/A print -u2 "This script requires Tksh"
0N/A fi
0N/A exit 1
0N/Afi
2362N/A
2362N/A########################### Open File Dialog Box #########################
2362N/A
0N/Afunction GetFile # msg default
0N/A{
0N/A typeset msg="${1-"Select a file:"}" olddir="$(pwd)" f="${2-"$(pwd)/"}"
0N/A typeset w=$(toplevel .fileselect -bd 4 -class Getfile)
0N/A
0N/A GetFileName="$f"
0N/A GetFileResources
0N/A GetFileWindow $w "$msg" > /dev/null
0N/A GetFileSetFiles $w.files
0N/A
0N/A wm title .fileselect "$msg"
0N/A bind $w.files.file.list "<1>" \
0N/A "GetFileSClick %W %y ; focus $w.sel.e"
0N/A bind $w.files.dir.list "<1>" \
0N/A "GetFileSClick %W %y ; focus $w.sel.e"
0N/A bind $w.files.dir.list "<Double-1>" \
0N/A "GetFileDClick $w.files %y ; focus $w.sel.e"
0N/A bind $w.sel.e "<Return>" "GetFileSetFiles $w.files"
0N/A
2981N/A tkwait variable GetFileDone
2981N/A destroy $w
2981N/A cd "$olddir"
2981N/A}
2981N/A
2981N/Afunction GetFileWindow # w msg
0N/A{
0N/A typeset w=$1 msg="$2"
0N/A
0N/A # Create everything
0N/A
0N/A message $w.msg -aspect 1000 -text "$msg"
0N/A
0N/A frame $w.sel
0N/A label $w.sel.l -padx 0
0N/A entry $w.sel.e -textvariable GetFileName
0N/A
0N/A frame $w.files
0N/A frame $w.files.dir
2981N/A frame $w.files.file
2981N/A MkXYScroll $w.files.dir
0N/A MkXYScroll $w.files.file
0N/A
0N/A frame $w.buttons
0N/A button $w.buttons.ok -command $'#!ksh\nGetFileDone=1'
0N/A button $w.buttons.cancel \
0N/A -command $'#!ksh\n'"GetFileName='' ; GetFileDone=1"
0N/A
0N/A # Take this out if you want a generic open file dialog box
28N/A frame $w.dest
28N/A label $w.dest.l -text "E-mail address:"
0N/A entry $w.dest.e -textvar Dest
0N/A
0N/A # Pack everything
0N/A
0N/A pack $w.sel.l -side left
0N/A pack $w.sel.e -side right -fill x -expand 1
2981N/A pack $w.msg -side top -fill x
0N/A pack $w.files.dir $w.files.file -side left -fill both
2981N/A pack $w.buttons.ok $w.buttons.cancel -side right
2981N/A pack $w.dest.l -side left
0N/A pack $w.dest.e -side left -expand 1 -fill x
2981N/A pack $w.msg $w.sel $w.files $w.dest $w.buttons -side top -fill both
0N/A}
0N/A
0N/Afunction GetFileResources
0N/A{
0N/A option add "*Getfile*ok.text" OK startup
0N/A option add "*Getfile*cancel.text" Cancel startup
0N/A option add "*Getfile*l.text" Selection: startup
0N/A}
0N/A
0N/Afunction MkXYScroll # widget
0N/A{
0N/A typeset w=$1
0N/A
0N/A listbox $w.list -yscrollcommand "$w.scroll set"
0N/A scrollbar $w.scroll -command "$w.list yview"
0N/A pack $w.list -side left -fill both -expand 1
0N/A pack $w.scroll -side left -fill y
0N/A}
0N/A
0N/Afunction GetFileSetFiles # widget
0N/A{
0N/A typeset dwidget=$1.dir.list fwidget=$1.file.list i w
0N/A
0N/A if [[ -d $GetFileName ]]
0N/A then cd $GetFileName > /dev/null 2>&1
0N/A else cd $(dirname $GetFileName) > /dev/null 2>&1
0N/A fi
0N/A
0N/A $dwidget delete 0 end
0N/A $fwidget delete 0 end
0N/A $dwidget insert end ..
0N/A for i in *
0N/A do
0N/A w=$dwidget
0N/A [[ -f $i ]] && w=$fwidget
0N/A $w insert end $i
0N/A done
0N/A}
0N/A
0N/Afunction GetFileSClick # widget point
0N/A{
0N/A GetFileName=$(pwd)/$($1 get $($1 nearest $2))
0N/A}
0N/A
0N/Afunction GetFileDClick # widget point
0N/A{
0N/A cd $($1.dir.list get $($1.dir.list nearest $2))
0N/A GetFileName=$(pwd)/
0N/A GetFileSetFiles $1
0N/A}
0N/A
0N/A##########################################################################
0N/A
0N/Awm withdraw .
0N/A
0N/AGetFile "Select file to send:"
0N/A
0N/A[[ $GetFileName == "" ]] && exit 0
0N/A[[ $Dest == "" ]] && exit 0
0N/Aname=$(basename $GetFileName)
0N/A
0N/Acase $COMPRESS in
0N/A compress) EXT=Z ;;
0N/A zip) EXT=zip ;;
0N/A pack) EXT=z ;;
0N/A *) COMPRESS=gzip
0N/A EXT=gz ;;
0N/Aesac
0N/A
0N/Acase $GetFileName in
28N/A "") break ;;
28N/A *.gz) uuencode $name < $GetFileName | mail $Dest ;;
28N/A *.tgz) uuencode $name < $GetFileName | mail $Dest ;;
0N/A *.uu) mail $Dest < $GetFileName ;;
0N/A *)
2241N/A if [[ -d $GetFileName ]]
2241N/A then
2241N/A tar -cvpf - $GetFileName | COMPRESS | uuencode \
2241N/A $name.tar.$EXT | mail $Dest
2241N/A else
0N/A $COMPRESS < $GetFileName | uuencode $name.$EXT | mail $Dest
2241N/A fi
0N/A ;;
2241N/Aesac
0N/A