# $Header: /home/cvsroot/tcldb/ucodb/Tlib/mailText,v 1.3 1998/12/07 20:18:33 de Exp $
# tcl procs saved on Sun Sep 03 16:19:01 PDT 1995

proc mailText {box username} {

        set win .[lindex [split $box .] 1]
        set wlist [winfo children $win]
        $win configure -cursor watch
        foreach child $wlist {
                $child configure -cursor watch
        }

	set self 0

	if {$username == ""} {
		set username [id user]
		set self 1
	}

	set unique [getclock]

	set of "/tmp/fmail.$unique"	

	set ofp [open $of w]

	if {$self} {
		puts $ofp "Because you left the recipient blank, you mailed this report to yourself.\n\n"
	}

#	if you can't get a size, then it must be a text box not a list box
	set err [catch {set len [$box size]} res]

	if {!$err} {
	loop i 0 $len {
		puts $ofp "[stringFix2 [$box get $i] out]"
	}
	} else {
		set text "[$box get 1.0 end]"
		puts $ofp "$text"
	}

	close $ofp

	system "/usr/ucb/Mail -s Sybase_Report $username < $of"

	system "/bin/rm -f $of"

        $win configure -cursor {}
        foreach child $wlist {
                $child configure -cursor {}
        }
}

