#!/usr/local/bin/wish -f

wm withdraw .

set tkmail [lindex $argv 0]
set tw [lindex $argv 1]
set tfile [lindex $argv 2]
set tcmd [lrange $argv 3 end]

if {[catch "eval exec $tcmd" res]} {
    send $tkmail "mf_mailerror {$res}"
    exit
}
send $tkmail "$tw configure -state normal"
send $tkmail "$tw delete 1.0 end"
send $tkmail "$tw insert 1.0 \[exec cat $tfile\]"

set cmd {exec /bin/rm $tfile}
if {[catch "eval $cmd" res]} {
    send $tkmail "mf_mailerror {$res}"
    exit
}

exit

