### Copyright (C) 1996 Per Zacho
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

proc mail {} {
    # User<->Bash interface / Mail check

    Desc "This configuration page will help you to setup options relating to"\
    "mailcheck. Though, users often may prefer the \"biff\" program, or when using X-windows,"\
    "\"xbiff\" which in contrast to Bash is able to inform you of new mail at any time. Bash"\
    "only print \"new mail\" before printing the command prompt."

    ShortDesc "Mail check"

    ### Mail check ###

    Header head1 -text "Mail check"\
	    -background gray\
	    -help "Options concerning when and where to check for mail."

    Int mailchk -text "Check for mail every"\
	    -textafter "seconds"\
	    -default 60\
	    -width 3\
	    -help "You can specify how often Bash is to check for mail."

    CheckBox mailwarn -text "Notify if mailfile has been read since last check"\
	    -help "If mail file has been accessed since the last time it was checked,"\
	    "the message \"The mail in (mailfile) has been read\" is printed."

    Line line1

    File-Dir-Browser path -text "Mail file"\
	-exist 1

    foreach elm {frame_path path com_path} {
	Help $elm "Name of file, which Bash is to check for mail"
    }

    Entry comment -text "  Message"\
	    -help "When mail arrives in the file specified, this message, if defined, will be"\
	    "printed before command prompt. \"\$_\" will expand to the name of mailfile holding"\
	    "the new mail."

    ExtEntry mailpath -text "File(s) to check for incoming mail"\
	    -entries {frame_path comment}\
	    -help "You can specify several files to check for mail. The first entry will be"\
	    "stored in the old mail variable \"MAIL\""

    PageEnd {
	if {$mailchk < 0} {
	    error "Time between mailcheck has to be a positive number of seconds"
	}
	set temp 0
	forevery mailpath {
	    incr temp
	    if {$path == "" && $comment != ""} {
		error "No mailfile specified for comment in line $temp"
	    }
	}
    }

    Save {
	### Mail check ###
	if {$mailchk != 60 || $generateDefault} {
	    if {$mailchk == 0} {
		print "unset MAILCHECK"
	    } {
		print "export MAILCHECK=$mailchk"
	    }
	}

	if {$mailwarn || $generateDefault} {
	    print "[pick $mailwarn "export MAIL_WARNING=on" "unset MAIL_WARNING"]"
	}

	set temp ""

	forevery mailpath {
	    if {$path != ""} {
		if {$comment != ""} {
		    append temp "$path?$comment:"
		} {
		    append temp "$path:"
		}
	    }
	}

	set temp [string trim $temp ":"]
	if {$temp != ""} {
	    print "export MAILPATH='$temp'"
}
    }
}

