#!/afs/ece/usr/tcl/bin/wish -f
# The next line is executed by most shells, but not Tcl \
wish $0 $*

#
# Mail sending program, Can be used as -whatnowproc 
#

set cwd [pwd]
if {([string match /* [info script]])} {
	set bethmail_dir [file dirname [info script]]
} else {set bethmail_dir [file dirname $cwd/[info script]]}
cd $bethmail_dir

set folder "drafts"
set w .syme1.t
set f .syme1.t_fm
set mail_dir "$env(HOME)/Mail"

set list [exec ls $mail_dir/$folder]
set this [lindex $list end]
set argv "-a $mail_dir/$folder/$this"
set argc [llength $argv]
source elsbeth
set TH(Cycle,Active,.syme1.t) 0

wm title .syme1 "Mail: Send"
wm iconname .syme1 "MS"

$f.fnl invoke

button $f.send -text Send -command "exec touch $TH(File,$w) ; th_save_file $w ; exec send $TH(File,$w)"
pack $f.send -side left -expand yes -fill x
$f.quit configure -command exit

bind . <Destroy> {if {[file exists $TH(File,$w)]} {exec rm $TH(File,$w)}}

if {[set dash_index [$w search -forward -exact -- "---" 1.0 end]] != ""} {
  $w delete "$dash_index linestart" "$dash_index lineend"
}
th_Text_paint_region $w 1.0 end 0
