#!/usr/local/bin/wish
global env gv

set gv(version)		"VisualMail (Version 3.2.4 18feb97)"
set gv(program)		vmail3
set gv(iconname)	[string toupper $gv(program)]
set gv(top)		.$gv(program)
set gv(author)		"John van Gulik"

proc errmess { pw {msg ""} } {
	global env gv
	pack [label .errmess -text $msg] -side top -expand true -fill both
	pack [button .ok -text "OK" -command "destroy .ok"] -side top
	tkwait window .ok
}

##############################################################################
#####	Set the required environment variables
##############################################################################

if {[info exists env(HOME)] && $env(HOME)=="/"} {set env(HOME) "/root"}

if {$tcl_platform(platform)=="windows"} {
	if {![info exists env(TKAPPS)]} {
		set env(TKAPPS) /tkapps
	}
	if {![file isdirectory $env(TKAPPS)]} {
		errmess . "Directory $env(TKAPPS) not found"
		exit 1
	}
} elseif {$tcl_platform(platform)=="unix"} {
	if {![info exists env(TKAPPS)]} {
		if {[file isdirectory $env(HOME)/TKAPPS]} {
			set env(TKAPPS) $env(HOME)/TKAPPS
		} elseif {[file isdirectory /opt/TKAPPS]} {
			set env(TKAPPS) /opt/TKAPPS
		} elseif {[file isdirectory /apps/TKAPPS]} {
			set env(TKAPPS) /apps/TKAPPS
		} else {
			set env(TKAPPS) /usr/local/TKAPPS
		}
	}
	if {![file isdirectory $env(TKAPPS)]} {
		errmess . "Directory $env(TKAPPS) not found"
		exit 1
	}
} else {
	errmess . "This application is not supported under $tcl_platform(platform)"
	exit 1
}

set auto_path [linsert $auto_path 0 $env(TKAPPS)/lib]

#wm withdraw .

standard_startup $gv(program) $gv(version)

##############################################################################
#####	Set required variables and options
##############################################################################

set gv(classfile)	$env(TKAPPS)/etc/class
set gv(caveatfile)	$env(TKAPPS)/etc/caveat

#
if {[file exists $env(HOME)/Mail] \
	&& [file isdirectory $env(HOME)/Mail]} {
	set gv(fdir)	$env(HOME)/Mail
} else {
	set gv(fdir)	$env(HOME)
}
set gv(inbox)		"+Inbox"

set gv(sitesfile)	/usr/local/etc/sites.database
if {[file exists $gv(sitesfile)] && [file readable $gv(sitesfile)]} {
	set gv(sites) {}
	set fp [open $gv(sitesfile) r]
	while {[gets $fp line]>=0} {lappend gv(sites) [lindex [split $line ":"] 0]}
	if {[catch {close $fp} res]} {
		set gv(sites) {}
	}
} else {
	set gv(sites) {}
}

#
#	Location of some required files
#
set gv(sounddir)	"$env(TKAPPS)/sound"

set gv(bm_empty)	"$env(TKAPPS)/bitmaps/empty.xbm"
set gv(bm_empty_mask)	"$env(TKAPPS)/bitmaps/empty.msk"
set gv(bm_full)		"$env(TKAPPS)/bitmaps/full.xbm"
set gv(bm_full_mask)	"$env(TKAPPS)/bitmaps/full.msk"
set gv(bm_newmail)	"$env(TKAPPS)/bitmaps/newmail.xbm"
set gv(bm_newmail_mask)	"$env(TKAPPS)/bitmaps/newmail.msk"
set gv(bm_compose)	"$env(TKAPPS)/bitmaps/compose.xbm"
set gv(bm_compose_mask)	"$env(TKAPPS)/bitmaps/compose.msk"
set gv(bm_option)	"$env(TKAPPS)/bitmaps/option.xbm"
set gv(bm_option_mask)	"$env(TKAPPS)/bitmaps/option.msk"

set gv(bm_up)		"$env(TKAPPS)/bitmaps/up.xbm"
set gv(bm_down)		"$env(TKAPPS)/bitmaps/down.xbm"
set gv(bm_left)		"$env(TKAPPS)/bitmaps/left.xbm"
set gv(bm_right)	"$env(TKAPPS)/bitmaps/right.xbm"
set gv(bm_close)	"$env(TKAPPS)/bitmaps/close.xbm"
set gv(bm_expand)	"$env(TKAPPS)/bitmaps/expand.xbm"
set gv(bm_shrink)	"$env(TKAPPS)/bitmaps/shrink.xbm"
set gv(bm_expandh)	"$env(TKAPPS)/bitmaps/expandh.xbm"
set gv(bm_shrinkh)	"$env(TKAPPS)/bitmaps/shrinkh.xbm"

#
#	Initialize the startup options
#
set gv(option:names) {}
proc addopt {name menu type default help} {
	global env gv
	lappend gv(option:names) $name
	set gv(option:menu:$name) $menu
	set gv(option:type:$name) $type
	set gv(option:defs:$name) [lrange $default 0 end]
	set gv(option:help:$name) $help
	set gv(option:value:$name) [lindex $default 0]
}
addopt	autoopen	other	other		[list true false] \
	[lang "Pop open window when new messages" "Ouvrir une fentre lors de nouveaux messages"]
addopt	incmess		other	other		[list all body none] \
	[lang "Include message on replies" "Inclure le message lors de rplique"]
addopt	classopt	other	other		[list false true] \
	[lang "Turn on classification support" "FRENCH"]
addopt	strip		other	other		[list false true] \
	[lang "Strip unknown remote domains on replies" "Enlever les domaines loigns et inconnus sur les rpliques"]
addopt	nolog		other	other		[list false true] \
	[lang "Do not log sent messages" "Ne pas sauvegarder les messages envoy"]
addopt	receipt		other	other		[list false true] \
	[lang "Ask for a delivery receipt" "Demander un reu de rception"]
addopt	read		other	other		[list false true] \
	[lang "Ask for a read receipt" "Demander un reu de lecture"]
addopt	crypt		other	other		[list none pgp entrust] \
	[lang "Default Encryption type" "Type de cryptophonie par dfaut"]
addopt	autosign	other	other		[list true false] \
	[lang "Insert signature file" "Ajouter le fichier signature"]
addopt	showfold	other	other		[list true false] \
	[lang "Show Folder commands" "FRENCH"]
addopt	shownews	other	other		[list true false] \
	[lang "Show Newsgroup commands" "FRENCH"]
addopt	headers		other	other		[list true false] \
	[lang "Show full message header information" "Montrer les informations du titre de message au complet"]
addopt	headskip	other	other		[list true false] \
	[lang "Skip past headers in message view" "viter les titres lors du visionnement de message"]
addopt	headtag		other	other		[list false true] \
	[lang "Tag header fields in message view" "Marquer les titres lors du visionnement de message"]
addopt	beepmail	other	other		[list true false] \
	[lang "Sound audible beep on new mail" "mettre un bip sonore lors de nouveaux messages"]
addopt	beeperr		other	other		[list true false] \
	[lang "Sound audible beep on errors" "mettre un bip sonore lors d'erreurs"]
addopt	quitprompt	other	other		[list true false] \
	[lang "Confirm exit of VMail" "Voulez-vous vraiment quitter Vmail"]
addopt	showbcc		other	other		[list false true] \
	[lang "Show Bcc field in compose windows" "Montrer le champ Bcc dans la fentre de composition"]
addopt	showreplyto	other	other		[list false true] \
	[lang "Show Reply-To field in compose windows" "Montrer le champ Reply-To dans la fentre de composition"]
addopt	showfcc		other	other		[list false true] \
	[lang "Show Fcc field in compose windows" "Montrer le champ Fcc dans la fentre de composition"]
addopt	reverse		other	other		[list true false] \
	[lang "Show messages in reverse" "Montrer les messages  l'inverse"]
addopt	sortflag	other	other		[list date sender size subject] \
	[lang "Message sorting type" "Type de tri des messages"]
addopt	attachtype	other	other		[list mime sun generic] \
	[lang "Default attachment format" "Format des attachements par dfaut"]
addopt	attachcode	other	other		[list base64 x-uuencode] \
	[lang "Default attachment encoding method" "FRENCH"]

addopt	lastseen	other	other		"" \
	[lang "Current version" "FRENCH"]

addopt	nntpserver	news	menu		"$env(NNTPSERVER)" \
	[lang "News Server (NNTP)" "FRENCH"]
addopt	nntpport	news	menu		"$env(NNTPPORT)" \
	[lang "News Port" "FRENCH"]
addopt	newsmax		news	scale		[list 300 10 1000] \
	[lang "Maximum news headers to list" "FRENCH"]

addopt	fullname	mail	menu		[list $env(FULLNAME)] \
	[lang "My full name" "FRENCH"]
addopt	mailaddress	mail	menu		"$env(USER)" \
	[lang "Mail Address (for replies)" "FRENCH"]
addopt	mailserver	mail	menu		"$env(MAILSERVER)" \
	[lang "Mail Server (for outgoing email)" "FRENCH"]
addopt	mailport	mail	menu		"$env(MAILPORT)" \
	[lang "Mail Port" "FRENCH"]
addopt	mailboxes	mail	menu		[list [mail system $env(USER)] $env(USER)@$env(MAILSERVER)] \
	[lang "Incoming mailboxes" "FRENCH"]
addopt	record		mail	menu		[list +Sent +Outbox] \
	[lang "Default folder for sent messages" "FRENCH"]
addopt	autodate	mail	menu		[list +Date +Auto] \
	[lang "Top level folder for messages filed by date" "FRENCH"]
addopt	autosend	mail	menu		[list +Sender +Auto] \
	[lang "Top level folder for messages filed by sender" "FRENCH"]
addopt	trash		mail	menu		[list {} +Deleted +Trash] \
	[lang "Folder to save deleted messages in" "FRENCH"]
addopt	filter_newmail	mail	string		"" \
	[lang "Default filter to run for new mail" "FRENCH"]
addopt	sendwrap	mail	scale		[list 0 0 120] \
	[lang "Width to wrap on send (0=none)" "Largeur de retour lors d'envoie (0=aucun)"]
addopt	quote		mail	string		"> " \
	[lang "Insert message quote string" "Insrer le texte de message"]

addopt	filedir		file	string		"$env(HOME)" \
	[lang "Default directory to save attachments" "Rpertoire de sauvegarde par dfaut"]
addopt	formdir		file	string		"$env(TKAPPS)/forms" \
	[lang "Default directory for forms" "FRENCH"]


addopt	mailchk		timers	scale		[list 120 10 600] \
	[lang "Check for new mail (seconds)" "Vrification de nouveaux messages (secondes)"]
addopt	infotime	timers	scale		[list 5 1 60] \
	[lang "Show info messages (seconds)" "Montrer les messages d'information (secondes)"]
addopt	popuptime	timers	scale		[list 3 0 20] \
	[lang "Show popup info messages (seconds)" "Montrer les messages popup d'information (secondes)"]

addopt	sound_newmail	sound	menu		[list "" "$env(TKAPPS)/sound/newmail.au"] \
	[lang "Sound file to play on new mail" "FRENCH"]
addopt	sound_start	sound	menu		[list "" "$env(TKAPPS)/sound/start.au"] \
	[lang "Sound file to play on startup" "FRENCH"]
addopt	sound_restart	sound	menu		[list "" "$env(TKAPPS)/sound/restart.au"] \
	[lang "Sound file to play on restart" "FRENCH"]
addopt	sound_exit	sound	menu		[list "" "$env(TKAPPS)/sound/exit.au"] \
	[lang "Sound file to play on exit" "FRENCH"]

addopt	printque	print	menu		[print_queues] \
	[lang "Printer queue" "FRENCH"]
addopt	printype	print	menu		[list postscript other] \
	[lang "Printer type" "FRENCH"]

addopt	foldside	config	menu		[list left right] \
	[lang "Folder/News listing side" "FRENCH"]
addopt	scrollpos	config	menu		[list left right] \
	[lang "Scrollbar position" "Position de barre de rotation"]
addopt	maxfold		config	scale		[list 30 5 50] \
	[lang "Maximum number of menu entries" "Limite d'entre de menu"]
addopt	compwidth	config	scale		[list 72 60 120] \
	[lang "Width of compose window" "Largeur de la fentre de composition"]
addopt	messwidth	config	scale		[list 72 60 120] \
	[lang "Width of message view window" "Largeur de la fentre de message"]
addopt	foldwidth	config	scale		[list 20 10 50] \
	[lang "Width of folder listing area" "Largeur de la zone de fichier"]
addopt	foldheight	config	scale		[list 20 2 50] \
	[lang "Height of folder listing area" "Hauteur de la zone de fichier"]
addopt	headheight	config	scale		[list 8 2 50] \
	[lang "Height of header listing area" "Hauteur de la zone des titres"]
addopt	addressheight	config	scale		[list 2 2 10] \
	[lang "Height of address area" "Hauteur de la zone d'adresse"]

#
#	Change defaults for the non-internet sites
#
if {$env(SITE)!="internet"} {
	set gv(option:defs:classopt)	[list true false]
	set gv(option:defs:crypt)	[list none icarus entrust]
	set gv(option:defs:attachcode)	[list x-uuencode base64]
	set gv(option:defs:mailboxes)	[list [mail system $env(USER)]]
}

#
#	Shortcuts to widgets
#
set gv(statusw)	$gv(top).status
set gv(headw)	$gv(top).head.list
set gv(messw)	$gv(top).mess.txt

#
#	Private program variables
#

# Default classification
set gv(badclass) UNKNOWN

# Attachment format
set gv(aformat) "%-2d %-10s %-35s %s\n"

#	name of current folder file
set gv(curfold) ""

#	number of messages in folder
set gv(messnum) 0

#	current message number
set gv(curmess) 0

#	current message text index
set gv(curmpos) 0.0

#	flag to indicate which icon to show for the main window
set gv(mailflag) ""

#	number of filters
set gv(filter.num) 0
set gv(filter.filename) ""

#	number of attachments in the main window
set gv($gv(top).attach.num) 0

set gv(news.newsgroup) ""
set gv(news.curtype) all
set gv(news.curmax) $gv(option:value:newsmax)



##############################################################################
#####	SUBROUTINES
##############################################################################

proc default_action {{type ""}} {
	global env gv

	if {$type=="first" || $type=="last" || $type=="next" || $type=="prev"} {
		v_selmess show $type
	} elseif {$type=="top"} {
		$gv(top).mess.txt see 1.0
	} elseif {$type=="bottom"} {
		$gv(top).mess.txt see end
	} elseif {$type=="pgdn"} {
		$gv(top).mess.txt yview scroll 1 page
	} elseif {$type=="pgup"} {
		$gv(top).mess.txt yview scroll -1 page
	} elseif {$type=="skip" && $gv(curfold)==""} {
		set index [lindex [$gv(top).man.news.list curselection] 0]
		if {$index==""} {return}
		incr index
		if {$index>[$gv(top).man.news.list index end]} {
			v_newsbox list
			return
		}
		set newsgroup [lindex [split [$gv(top).man.news.list get $index]] 0]
		$gv(top).man.news.list selection clear 0 end
		$gv(top).man.news.list selection anchor $index
		$gv(top).man.news.list selection set $index
		$gv(top).man.news.list activate $index
		$gv(top).man.news.list see $index
		if {$newsgroup!=""} {
			v_newsbox open $newsgroup
		}
	} else {
		set last [lindex [$gv(top).mess.txt yview] 1]
		if {$last<1} {
			$gv(top).mess.txt yview scroll 1 page
			return
		}
		if {$gv(curmpos)<[expr $gv(messnum) - 1]} {
			v_selmess show next
			return
		}
		if {$gv(curfold)==""} {
			set index [lindex [$gv(top).man.news.list curselection] 0]
			if {$index==""} {return}
			incr index
			if {$index>=[$gv(top).man.news.list size]} {
				v_newsbox list
				set index 0
			}
			set newsgroup [lindex [split [$gv(top).man.news.list get $index]] 0]
			$gv(top).man.news.list selection clear 0 end
			$gv(top).man.news.list selection anchor $index
			$gv(top).man.news.list selection set $index
			$gv(top).man.news.list activate $index
			$gv(top).man.news.list see $index
			if {$newsgroup!=""} {
				v_newsbox open $newsgroup
			}
		}
	}
	return
}

proc v_packmailbox { } {
	global env gv

	foreach child [winfo children $gv(top).b1.newmail] {destroy $child}

	set i 0
	set gv(pop:mailbox) ""
	foreach mailbox $gv(option:value:mailboxes) {
		set file [lindex [split $mailbox ":"] 0]
		set filter [lindex [split $mailbox ":"] 1]
		set gv(lastsize.$i) 0
		set gv(pass.$i) ""
		set temp [split $file "@"]
		if {[llength $temp]==3} {
			set gv(pass.$i) [lindex $temp 2]
			set file "[lindex $temp 0]@[lindex $temp 1]"
		}
		set name [file tail $file]
		if {$name==$env(USER)} { set name [lang "New Mail" "Nouveau"] }
		set gv(newmail.$i) $gv(top).b1.newmail.$i
		pack [button $gv(newmail.$i) -text "$name" \
			-command "v_incorporate $i" ] \
			-side left -expand true -fill x
		bind $gv(newmail.$i) <3> {
			set gv(pop:mailbox) [getstring $gv(top) "Mailbox:" $gv(pop:mailbox)]
			if {$gv(pop:mailbox)!=""} {v_incorporate -1 $gv(pop:mailbox)}
			break
		}
		set gv(newmail.$i.bg) [$gv(newmail.$i) cget -background]
		set gv(newmail.$i.fg) [$gv(newmail.$i) cget -foreground]
		set gv(newmail.$i.hbg) red
		set gv(newmail.$i.hfg) white
		bind_help $gv(newmail.$i)	$gv(top).help \
			[lang "Pull in new messages from $file" "Recevoir les messages nouveaux avec $file"]
		incr i
	}
	return
}

##############################################################################
#####	MAIN PROGRAM
##############################################################################

# start off in the user's home directory
cd

# load the .vmailrc file options
v_option_load

# save the options in case there are new ones
v_option_save

# initialize the mail routines
mail load $gv(option:value:mailserver) $gv(option:value:mailport)

# initialize the crypt routines
crypt_init
# temporary fix for an incompatibility with older vmail versions
if {$gv(option:value:crypt)=="false"} {set gv(option:value:crypt) "none"}


if {$gv(option:value:sound_start)!=""} {catch {viewfile $gv(option:value:sound_start)} res}

toplevel	$gv(top)
wm iconname	$gv(top) $env(USER)
wm iconbitmap	$gv(top) @$env(TKAPPS)/bitmaps/$gv(program).xbm
wm iconmask	$gv(top) @$env(TKAPPS)/bitmaps/$gv(program).msk
wm title	$gv(top) $gv(version)
wm minsize	$gv(top) 100 100
wm protocol	$gv(top) WM_DELETE_WINDOW v_exit

v_getopts $argv

pack [label $gv(top).help ] \
	-side bottom -fill x
bind_help $gv(top).help $gv(top).help \
	[lang "Help text" "Texte d'aide"]

set gv(fcolor) [option get .vmail3 foreground {}]
set gv(bcolor) [option get .vmail3 background {}]
if {$gv(fcolor)==""} {set gv(fcolor) [$gv(top).help cget -foreground]}
if {$gv(bcolor)==""} {set gv(bcolor) [$gv(top).help cget -background]}

set gv(hfcolor)	[option get .vmail3 alarmForeground {}]
set gv(hbcolor) [option get .vmail3 alarmBackground {}]
if {$gv(hfcolor)==""} {set gv(hfcolor) white}
if {$gv(hbcolor)==""} {set gv(hbcolor) red}


pack [frame $gv(top).b1 ] \
	-side top -fill x
pack [menubutton $gv(top).b1.file -menu $gv(top).b1.file.m \
	-text [lang "File..." "Fichier..."] ] \
	-side left -fill y
pack [menubutton $gv(top).b1.options -menu $gv(top).b1.options.m \
	-text [lang "Options..." "FRENCH"] ] \
	-side left -fill y
pack [button $gv(top).b1.news -text [lang "New News" "FRENCH"] \
	-command {
		set gv(news.ngtype) new
		set gv(news.type) new
		if {$gv(option:value:shownews)=="false"} {
			set gv(option:value:shownews) true
			pack $gv(top).man.news -side bottom -expand true -fill both
			pack $gv(top).man.newsbar -side bottom -fill x
		}
		v_newsbox list
	} ] \
	-side left
pack [frame $gv(top).b1.newmail] \
	-side left -expand true -fill x

v_packmailbox

pack [button $gv(top).b1.icon -text [lang "Save & Iconify" "Sauvegarder et Minimiser"] \
	-command "wm iconify $gv(top) ; v_openfolder \$gv(inbox) ; v_checkmail" ] \
	-side left
pack [button $gv(top).b1.exit -text [lang "Exit" "Abandonner"] \
	-command "v_exit"] \
	-side left

bind_help $gv(top).b1.file $gv(top).help \
	[lang "Standard file menu" "Menu standard du fichier"]
bind_help $gv(top).b1.options	$gv(top).help \
	[lang "Menu of options" "Menu des options"]
bind_help $gv(top).b1.news	$gv(top).help \
	[lang "List subscribed newsgroups with new messages" "FRENCH"]
bind_help $gv(top).b1.icon	$gv(top).help \
	[lang "Save changes and iconify window" "Sauvegarder et Minimiser"]
bind_help $gv(top).b1.exit	$gv(top).help \
	[lang "Close and exit VMail" "Fermer et Abandonner"]

menu $gv(top).b1.file.m
$gv(top).b1.file.m add command -command {v_restart english} \
	-label [lang "Restart VMail (English)" "Redmarrer VMail (Anglais)"]
$gv(top).b1.file.m add command -command {v_restart french} \
	-label [lang "Restart VMail (French)" "Redmarrer VMail (Franais)"]
$gv(top).b1.file.m add separator
$gv(top).b1.file.m add command \
	-command {v_compose -type "Gripe" -to "$gv(gripeman)" -subject "VMail Gripe" } \
	-label [lang "Send a VMail Gripe to the author" "Rouspetage (en anglais SVP)"]
$gv(top).b1.file.m add command -command "background vvac" \
	-label [lang "Turn Vacation ON/OFF" "Vacance"]
if {$env(SITE)!="internet"} {
	$gv(top).b1.file.m add command -command {background vdir} \
		-label [lang "Update (NUAD/LIST) databases" "Services des rpertoires (NUAD/LIST)"]
}
if {$env(SITE)!="internet"} {
	$gv(top).b1.file.m add command -command {background vquery} \
		-label [lang "Directory Query" "Demande au rpertoire gnral"]
}

$gv(top).b1.file.m add separator
$gv(top).b1.file.m add command -command "eval \[getstring $gv(top) \"Enter your tcl command\" {}\]" \
	-label [lang "Execute TCL command" "FRENCH"]
$gv(top).b1.file.m add separator
$gv(top).b1.file.m add command -command "help $env(TKAPPS)/help/$gv(program)" \
	-label [lang "Help" "Aide"]
$gv(top).b1.file.m add command -command "background tkcustom $gv(program)" \
	-label [lang "Fonts/Colors" "Fontes/Couleurs"]
$gv(top).b1.file.m add command \
	-command "wm iconify $gv(top) ; v_openfolder \$gv(inbox) ; v_checkmail" \
	-label [lang "Save & Iconify" "Sauvegarder et Minimiser"]
$gv(top).b1.file.m add command -command "v_exit" \
	-label [lang "Exit" "Abandonner"]



menu $gv(top).b1.options.m
$gv(top).b1.options.m add cascade -menu $gv(top).b1.options.m.v \
	-label [lang "Message View Options..." "Options visuels"]
$gv(top).b1.options.m add cascade -menu $gv(top).b1.options.m.o \
	-label [lang "Other Options..." "Autres options"]
$gv(top).b1.options.m add command -command {v_option} \
	-label [lang "Change Other Options" "Modifier les prfrences de l'utilisateur"]
$gv(top).b1.options.m add command -command {v_option_save} \
	-label [lang "Save Startup Options" "Sauvegarder les options de dmarrage"]
$gv(top).b1.options.m add separator
$gv(top).b1.options.m add cascade -menu $gv(top).b1.options.m.e \
	-label [lang "Edit Secondary Files..." "Modifier les fichiers secondaires"]

menu $gv(top).b1.options.m.e
$gv(top).b1.options.m.e add command \
	-command "f_touch $env(HOME)/.signature ; viewfile $env(HOME)/.signature text/plain vedit" \
	-label [lang "Signature" "Signature"] \
	-accel "~/.signature"
$gv(top).b1.options.m.e add command \
	-command "f_touch $env(HOME)/.names ; viewfile $env(HOME)/.names text/plain vedit" \
	-label [lang "Names menu" "Menu de noms"] \
	-accel "~/.names"
$gv(top).b1.options.m.e add command \
	-command "f_touch $env(HOME)/.subjects ; viewfile $env(HOME)/.subjects text/plain vedit" \
	-label [lang "Subjects menu" "Menu de sujets"] \
	-accel "~/.subjects"
$gv(top).b1.options.m.e add command \
	-command "f_touch $env(HOME)/.vmailrc ; viewfile $env(HOME)/.vmailrc text/plain vedit" \
	-label [lang "VMail startup options" "Options de dmarrage pour VMail"] \
	-accel "~/.vmailrc"
$gv(top).b1.options.m.e add command \
	-command "f_touch $env(HOME)/.mime.types ; viewfile $env(HOME)/.mime.types text/plain vedit" \
	-label [lang "File extension mapping" "Plan des rpertoires d'extensions"] \
	-accel "~/.mime.types"
$gv(top).b1.options.m.e add command \
	-command "f_touch $env(HOME)/.mailcap ; viewfile $env(HOME)/.mailcap text/plain vedit" \
	-label [lang "Attachment viewer definitions" "Dfinitions des voyeurs d'attachments"] \
	-accel "~/.mailcap"

menu $gv(top).b1.options.m.v
$gv(top).b1.options.m.v add checkbutton -label $gv(option:help:headers) \
	-variable gv(option:value:headers) -onvalue "true" -offvalue "false" \
	-command "v_dispmess \$gv(curmess) $gv(top) ; v_option_save"
$gv(top).b1.options.m.v add checkbutton -label $gv(option:help:headskip) \
	-variable gv(option:value:headskip) -onvalue "true" -offvalue "false" \
	-command "v_dispmess \$gv(curmess) $gv(top) ; v_option_save"
$gv(top).b1.options.m.v add checkbutton -label $gv(option:help:headtag) \
	-variable gv(option:value:headtag) -onvalue "true" -offvalue "false" \
	-command "v_dispmess \$gv(curmess) $gv(top) ; v_option_save"
$gv(top).b1.options.m.v add separator
$gv(top).b1.options.m.v add checkbutton -label $gv(option:help:reverse) \
	-variable gv(option:value:reverse) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.v add separator
$gv(top).b1.options.m.v add radiobutton -label [lang "Sort by date/time" "Triage par date et heure"] \
	-variable gv(option:value:sortflag) -value {date} \
	-command "v_folder sort \$gv(curfold) ; v_option_save"
$gv(top).b1.options.m.v add radiobutton -label [lang "Sort by sender" "Triage par originateur"] \
	-variable gv(option:value:sortflag) -value {sender} \
	-command "v_folder sort \$gv(curfold) ; v_option_save"
$gv(top).b1.options.m.v add radiobutton -label [lang "Sort by size" "Triage par grosseur"] \
	-variable gv(option:value:sortflag) -value {size} \
	-command "v_folder sort \$gv(curfold) ; v_option_save"
$gv(top).b1.options.m.v add radiobutton -label [lang "Sort by subject" "Triage par sujet"] \
	-variable gv(option:value:sortflag) -value {subject} \
	-command "v_folder sort \$gv(curfold) ; v_option_save"

menu $gv(top).b1.options.m.o
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:autoopen) \
	-variable gv(option:value:autoopen) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:beepmail) \
	-variable gv(option:value:beepmail) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:beeperr) \
	-variable gv(option:value:beeperr) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:quitprompt) \
	-variable gv(option:value:quitprompt) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add separator
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:strip) \
	-variable gv(option:value:strip) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:nolog) \
	-variable gv(option:value:nolog) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:receipt) \
	-variable gv(option:value:receipt) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:read) \
	-variable gv(option:value:read) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:autosign) \
	-variable gv(option:value:autosign) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:showbcc) \
	-variable gv(option:value:showbcc) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:showfcc) \
	-variable gv(option:value:showfcc) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:classopt) \
	-variable gv(option:value:classopt) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add checkbutton -label $gv(option:help:showreplyto) \
	-variable gv(option:value:showreplyto) -onvalue "true" -offvalue "false" \
	-command {v_option_save}
$gv(top).b1.options.m.o add separator
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:incmess) -value "none" \
	-label [lang "Do not include message for Reply/Replyall" "Ne pas inclure le message pour Rpondre/Rpondre  tous"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:incmess) -value "body" \
	-label [lang "Only include message body in Reply/Replyall" "Inclure seulement le corps du message pour Rpondre/Rpondre  tous"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:incmess) -value "all" \
	-label [lang "Include message with all attachments" "Inclure le message avec tout les attachements"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add separator
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:attachtype) -value "mime" \
	-label [lang "Default send using MIME attachment format" "Format d'attachement - MIME"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:attachtype) -value "sun" \
	-label [lang "Default send using SUN attachment format" "Format d'attachement - SUN"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:attachtype) -value "generic" \
	-label [lang "Default send using generic attachment format" "Format d'attachement - gnrique"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add separator
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:attachcode) -value "base64" \
	-label [lang "Default send using MIME encoding (base64)" "FRENCH"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:attachcode) -value "x-uuencode" \
	-label [lang "Default send using UUENCODE encoding (x-uuencode)" "FRENCH"] \
	-command {v_option_save}
$gv(top).b1.options.m.o add separator
$gv(top).b1.options.m.o add radiobutton \
	-variable gv(option:value:crypt) -value "none" \
	-label [lang "Default send using no encryption" "Pas de cryptophonie"] \
	-command {v_option_save}
if {$gv(crypt.prog.icarus)!=""} {
	$gv(top).b1.options.m.o add radiobutton \
		-variable gv(option:value:crypt) -value "icarus" \
		-label [lang "Default send using ICARUS encryption" "Cryptophonie ICARUS"] \
		-command {v_option_save}
}
if {$gv(crypt.prog.entrust)!=""} {
	$gv(top).b1.options.m.o add radiobutton \
		-variable gv(option:value:crypt) -value "entrust" \
		-label [lang "Default send using ENTRUST encryption" "Cryptophonie ENTRUST"] \
		-command {v_option_save}
}

pack [label $gv(top).status -textvariable gv(stat.action) ] \
	-side top -fill x
bind_help $gv(top).status $gv(top).help \
	[lang "General status line" "Ligne d'tat gnrale"]

pack [frame $gv(top).man -width 1] \
	-side $gv(option:value:foldside) -fill y

frame $gv(top).man.foldbar
pack [button $gv(top).man.foldbar.expandh -bitmap "@$gv(bm_expandh)" \
	-command {set gv(option:value:foldwidth) [expr $gv(option:value:foldwidth)+1] ; \
		$gv(top).man.fold.list configure -width $gv(option:value:foldwidth)} ] \
	-side left -fill y
pack [button $gv(top).man.foldbar.shrinkh -bitmap "@$gv(bm_shrinkh)" \
	-command {set gv(option:value:foldwidth) [expr $gv(option:value:foldwidth)-1] ; \
		if {$gv(option:value:foldwidth)<20} {set gv(option:value:foldwidth) 20} ; \
		$gv(top).man.fold.list configure -width $gv(option:value:foldwidth)} ] \
	-side left -fill y
pack [menubutton $gv(top).man.foldbar.menu -menu $gv(top).man.foldbar.menu.m \
	-text [lang "Folder commands..." "FRENCH"] ] \
	-side left -expand true -fill both
pack [button $gv(top).man.foldbar.close -bitmap "@$gv(bm_close)" \
	-command {
		set gv(option:value:showfold) "false"
		pack forget $gv(top).man.fold
		pack forget $gv(top).man.foldbar
		if {$gv(option:value:shownews)=="false"} {
			pack forget $gv(top).man
			$gv(top).man configure -width 1
			pack $gv(top).man -after $gv(top).status \
				-side $gv(option:value:foldside) -fill y
		}
	} ] \
	-side left

bind_help $gv(top).man.foldbar.menu $gv(top).help \
	[lang "Menu of folder commands" "FRENCH"]
bind_help $gv(top).man.foldbar.expandh $gv(top).help \
	[lang "Expand folder area width" "FRENCH"]
bind_help $gv(top).man.foldbar.shrinkh $gv(top).help \
	[lang "Shrink folder area width" "FRENCH"]
bind_help $gv(top).man.foldbar.close $gv(top).help \
	[lang "Close folder area" "FRENCH"]

menu $gv(top).man.foldbar.menu.m
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Update folder list and menus" "FRENCH"] \
	-command "v_folder rebuild"
$gv(top).man.foldbar.menu.m add separator
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Open selected folder" "FRENCH"] \
	-command "v_folder open \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Print message listing of selected folder(s)" "FRENCH"] \
	-command "v_folder print \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Create new folder" "FRENCH"] \
	-command "v_folder create \[getstring $gv(top) {[lang "Create new folder:" "FRENCH"]} {}\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Rename selected folder(s)" "FRENCH"] \
	-command "v_folder rename \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Empty selected folder(s)" "FRENCH"] \
	-command "v_folder empty \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Delete selected folder(s)" "FRENCH"] \
	-command "v_folder delete \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Export selected folder(s)" "FRENCH"] \
	-command "v_folder export \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Export all folders" "FRENCH"] \
	-command "v_folder export"
$gv(top).man.foldbar.menu.m add separator
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Mark all messages in selected folder(s) as UNREAD" "FRENCH"] \
	-command "v_folder unread \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Mark all messages in selected folder(s) as READ" "FRENCH"] \
	-command "v_folder read \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Rescan all messages in selected folder(s)" "FRENCH"] \
	-command "v_folder rescan \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add separator
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Split selected folder(s) by date (year/month)" "FRENCH"] \
	-command "v_folder date \[v_foldbox_folders $gv(top).man.fold.list\]"
$gv(top).man.foldbar.menu.m add separator
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Import an entire directory of Mail folders" "Importation d'un rpertoire complet de poste"] \
	-command "v_folder import \[getstring $gv(top) \
		{[lang "Directory to import :" "Rpertoires  importer"]} \$gv(fdir)\]"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Import a single Mail folder" "Importation d'un seul rpertoire simple"] \
	-command "prompt -master $gv(top) -stayup true -title \"Import Mail Folder\" -directory \$gv(fdir) -command \"v_folder import \$gv(fdir)\""
$gv(top).man.foldbar.menu.m add separator
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Filter folders" "Filtrer des rpertoires"] \
	-command "v_filter"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Search folders for messages" "Chercher des rpertoires"] \
	-command "v_search"
$gv(top).man.foldbar.menu.m add command \
	-label [lang "Select messages by a header string" "Choisir le message par une portion du titre"] \
	-command "v_selectmess \[getstring $gv(top) \
		{[lang "Header string for message selection:" "Portion du titre:"]} {}\]"


frame $gv(top).man.fold
pack [scrollbar $gv(top).man.fold.yscroll \
	-command "$gv(top).man.fold.list yview" ] \
	-side $gv(option:value:scrollpos) -fill y
pack [listbox $gv(top).man.fold.list -relief sunken \
	-width $gv(option:value:foldwidth) \
	-yscroll "$gv(top).man.fold.yscroll set" \
	-selectmode extended ] \
	-expand true -fill both
bind $gv(top).man.fold.list <Double-1> {v_foldbox_double $gv(top).man.fold.list}
bind_help $gv(top).man.fold $gv(top).help \
	[lang "List of folders" "Liste de rpertoires"]

if {$gv(option:value:showfold)=="true"} {
	pack $gv(top).man.foldbar -side top -fill x
	pack $gv(top).man.fold -side top -expand true -fill both
}

frame $gv(top).man.newsbar
pack [button $gv(top).man.newsbar.expandh -bitmap "@$gv(bm_expandh)" \
	-command {set gv(option:value:foldwidth) [expr $gv(option:value:foldwidth)+1] ; \
		$gv(top).man.news.list configure -width $gv(option:value:foldwidth)} ] \
	-side left -fill y
pack [button $gv(top).man.newsbar.shrinkh -bitmap "@$gv(bm_shrinkh)" \
	-command {set gv(option:value:foldwidth) [expr $gv(option:value:foldwidth)-1] ; \
		if {$gv(option:value:foldwidth)<20} {set gv(option:value:foldwidth) 20} ; \
		$gv(top).man.news.list configure -width $gv(option:value:foldwidth)} ] \
	-side left -fill y
pack [menubutton $gv(top).man.newsbar.menu -menu $gv(top).man.newsbar.menu.m \
	-text [lang "News commands..." "FRENCH"] ] \
	-side left -expand true -fill both
pack [button $gv(top).man.newsbar.close -bitmap "@$gv(bm_close)" \
	-command {
		set gv(option:value:shownews) "false"
		pack forget $gv(top).man.news
		pack forget $gv(top).man.newsbar
		if {$gv(option:value:showfold)=="false"} {
			pack forget $gv(top).man
			$gv(top).man configure -width 1
			pack $gv(top).man -after $gv(top).status \
				-side $gv(option:value:foldside) -fill y
		}
	} ] \
	-side left

bind_help $gv(top).man.newsbar.menu $gv(top).help \
	[lang "Menu of NEWS commands" "FRENCH"]
bind_help $gv(top).man.newsbar.expandh $gv(top).help \
	[lang "Expand NEWS area width" "FRENCH"]
bind_help $gv(top).man.newsbar.shrinkh $gv(top).help \
	[lang "Shrink NEWS area width" "FRENCH"]
bind_help $gv(top).man.newsbar.close $gv(top).help \
	[lang "Close NEWS area" "FRENCH"]

menu $gv(top).man.newsbar.menu.m
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Mark selected messages as read" "FRENCH"] \
	-command {v_newsbox catchup selected}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Show more news messages" "FRENCH"] \
	-command {v_opennews $gv(news.newsgroup) $gv(news.curtype) $gv(option:value:newsmax)}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Show MAX news messages" "FRENCH"] \
	-command {v_opennews $gv(news.newsgroup) $gv(news.curtype) 10000}
$gv(top).man.newsbar.menu.m add separator
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Download list of all newsgroups from server" "FRENCH"] \
	-command {v_newsbox grouplist}
$gv(top).man.newsbar.menu.m add separator
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Print message headers of selected newsgroup(s)" "FRENCH"] \
	-command {v_newsbox print}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Open selected news group" "FRENCH"] \
	-command {v_newsbox open}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Subscribe to selected newsgroup(s)" "FRENCH"] \
	-command {v_newsbox subscribe ; v_newsbox menu}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Unsubscribe from selected newsgroup(s)" "FRENCH"] \
	-command {v_newsbox unsubscribe ; v_newsbox menu}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Mark selected newsgroup(s) as UNREAD" "FRENCH"] \
	-command {v_newsbox unread}
$gv(top).man.newsbar.menu.m add command \
	-label [lang "Mark selected newsgroup(s) as READ" "FRENCH"] \
	-command {v_newsbox catchup}
$gv(top).man.newsbar.menu.m add separator
$gv(top).man.newsbar.menu.m add radiobutton \
	-variable gv(news.ngtype) -value "new" \
	-command {v_newsbox list} -label "Show only subscribed groups with new messages"
$gv(top).man.newsbar.menu.m add radiobutton \
	-variable gv(news.ngtype) -value "active" \
	-command {v_newsbox list} -label "Show all active subscribed groups"
$gv(top).man.newsbar.menu.m add radiobutton \
	-variable gv(news.ngtype) -value "subscribed" \
	-command {v_newsbox list} -label "Show all subscribed groups"
$gv(top).man.newsbar.menu.m add radiobutton \
	-variable gv(news.ngtype) -value "all" \
	-command {v_newsbox list} -label "Show all groups"
$gv(top).man.newsbar.menu.m add separator
$gv(top).man.newsbar.menu.m add radiobutton \
	-variable gv(news.type) -value "new" \
	-label "Show new messages only"
$gv(top).man.newsbar.menu.m add radiobutton \
	-variable gv(news.type) -value "all" \
	-label "Show all messages"

frame $gv(top).man.news
pack [scrollbar $gv(top).man.news.yscroll \
	-command "$gv(top).man.news.list yview" ] \
	-side $gv(option:value:scrollpos) -fill y
pack [listbox $gv(top).man.news.list -relief sunken \
	-width $gv(option:value:foldwidth) \
	-yscroll "$gv(top).man.news.yscroll set" \
	-selectmode extended ] \
	-expand true -fill both
bind $gv(top).man.news.list <Double-1> \
	{v_newsbox open [lindex [split [%W get [%W nearest %y]]] 0]}
bind_help $gv(top).man.news $gv(top).help \
	[lang "List of news groups" "FRENCH"]

if {$gv(option:value:shownews)=="true"} {
	pack $gv(top).man.news -side bottom -expand true -fill both
	pack $gv(top).man.newsbar -side bottom -fill x
}

pack [frame $gv(top).hstat] \
	-side top -fill x
pack [menubutton $gv(top).hstat.open -text [lang "Folder..." "FRENCH"] \
	-menu $gv(top).hstat.open.m ] \
	-side left -fill y
pack [menubutton $gv(top).hstat.news -text [lang "Newsgroup..." "FRENCH"] \
	-menu $gv(top).hstat.news.m ] \
	-side left -fill y
pack [button $gv(top).hstat.next -text [lang "Next" "Suivant"] \
	-command "v_selmess show next" ] \
	-side left
pack [button $gv(top).hstat.prev -text [lang "Prev" "Antrieur"] \
	-command "v_selmess show prev" ] \
	-side left
pack [label $gv(top).hstat.lab -textvariable gv(stat.message) ] \
	-side left -expand true -fill both
pack [button $gv(top).hstat.shrink -bitmap "@$gv(bm_shrink)" \
	-command {set gv(option:value:headheight) [expr $gv(option:value:headheight)-1] ; \
		if {$gv(option:value:headheight)<3} {set gv(option:value:headheight) 3} ; \
		$gv(headw) configure -height $gv(option:value:headheight)} ] \
	-side right -fill y
pack [button $gv(top).hstat.expand -bitmap "@$gv(bm_expand)" \
	-command {set gv(option:value:headheight) [expr $gv(option:value:headheight)+1] ; \
		$gv(headw) configure -height $gv(option:value:headheight)} ] \
	-side right -fill y

bind_help $gv(top).hstat.open	$gv(top).help \
	[lang "Open a mail folder" "Ouvrir rpertoire de messages"]
bind_help $gv(top).hstat.news	$gv(top).help \
	[lang "Open a newsgroup" "FRENCH"]
bind_help $gv(top).hstat.next	$gv(top).help \
	[lang "Display the next message" "Montrer le message suivant"]
bind_help $gv(top).hstat.prev	$gv(top).help \
	[lang "Display the previous message" "Montrer le message antrieur"]
bind_help $gv(top).hstat.lab		$gv(top).help \
	[lang "Current folder/message status line" "Ligne d'tat du rpertoire courant"]
bind_help $gv(top).hstat.shrink		$gv(top).help \
	[lang "Shrink header window" "Rtrcir la fentre de titre"]
bind_help $gv(top).hstat.expand		$gv(top).help \
	[lang "Expand header window" "Agrandir la fentre de titre"]

pack [frame $gv(top).head] \
	-side top -fill both
pack [scrollbar $gv(top).head.yscroll \
	-command "$gv(top).head.list yview" ] \
	-side $gv(option:value:scrollpos) -fill y
pack [listbox $gv(top).head.list -width $gv(option:value:messwidth) -height $gv(option:value:headheight) \
	-yscroll "$gv(top).head.yscroll set" \
	-selectmode extended -relief sunken ] \
	-expand true -fill both
bind_help $gv(top).head $gv(top).help \
	[lang "List of messages in current folder" "Titres des messages dans le rpertoire courant"]

action_add "Focus"			"focus %W"

action_add "First message"		"default_action first; break"
action_add "Last message"		"default_action last; break"
action_add "Next message"		"default_action next; break"
action_add "Previous message"		"default_action prev; break"
action_add "First page"			"default_action top; break"
action_add "Last page"			"default_action bottom; break"
action_add "Next page"			"default_action pgdn; break"
action_add "Previous page"		"default_action pgup; break"
action_add "Skip to new newsgroup"	"default_action skip; break"
action_add "Next page/message/newsgroup"	"default_action; break"

action_add "Open folder"		"tk_popup $gv(top).hstat.open.m %X %Y"
action_add "Open newsgroup"		"tk_popup $gv(top).hstat.news.m %X %Y"
action_add "Move to folder"		"tk_popup $gv(top).mbut.1.move.m %X %Y"
action_add "Copy to folder"		"tk_popup $gv(top).mbut.1.copy.m %X %Y"
action_add "Delete messages"		"v_mess delete"
action_add "Undelete messages"		"v_flagmess"
action_add "Print messages"		"v_mess print"
action_add "Forward messages"		"$gv(top).mbut.2.forward invoke"
action_add "Reply to sender"		"$gv(top).mbut.2.reply invoke"
action_add "Reply to all"		"$gv(top).mbut.2.replyall invoke"
action_add "Compose new message"	"$gv(top).mbut.2.compose invoke"
action_add "Popup compose menu"		"tk_popup $gv(top).mbut.2.other.m.c %X %Y"

action_bind $gv(top).head.list <Shift-Key-Up>	"First message"
action_bind $gv(top).head.list <Shift-Key-Down>	"Last message"
action_bind $gv(top).head.list <Key-Down>	"Next message"
action_bind $gv(top).head.list <Key-Up>		"Previous message"
action_bind $gv(top).head.list <Key-Home>	"First page"
action_bind $gv(top).head.list <Key-End>	"Last page"
action_bind $gv(top).head.list <Key-Next>	"Next page"
action_bind $gv(top).head.list <Key-Prior>	"Previous page"
action_bind $gv(top).head.list <Key-KP_Enter>	"Skip to new newsgroup"
action_bind $gv(top).head.list <Key-space>	"Next page/message/newsgroup"

action_bind $gv(top).head.list <Alt-Key-O>	"Open folder"
action_bind $gv(top).head.list <Alt-Key-N>	"Open newsgroup"
action_bind $gv(top).head.list <Alt-Key-M>	"Move to folder"
action_bind $gv(top).head.list <Alt-Key-C>	"Copy to folder"
action_bind $gv(top).head.list <Alt-Key-d>	"Delete messages"
action_bind $gv(top).head.list <Alt-Key-u>	"Undelete messages"
action_bind $gv(top).head.list <Alt-Key-p>	"Print messages"
action_bind $gv(top).head.list <Alt-Key-f>	"Forward messages"
action_bind $gv(top).head.list <Alt-Key-R>	"Reply to all"
action_bind $gv(top).head.list <Alt-Key-r>	"Reply to sender"
action_bind $gv(top).head.list <Alt-Key-m>	"Popup compose menu"
action_bind $gv(top).head.list <Alt-Key-c>	"Compose new message"

bind $gv(top).head.list <1> {focus %W ; v_selmess show [%W nearest %y]}
bind $gv(top).head.list <Control-1> {%W activate $gv(curmpos)}
bind $gv(top).head.list <Shift-1> {%W activate $gv(curmpos)}
bind $gv(top).head.list <ButtonRelease-1> {
	tkCancelRepeat
	%W activate $gv(curmpos)
	break
}

pack [frame $gv(top).mbut] \
	-side top -fill x

pack [frame $gv(top).mbut.1] \
	-side left -expand true -fill x
pack [menubutton $gv(top).mbut.1.move -text [lang "Move..." "Dmnager..."] \
	-menu $gv(top).mbut.1.move.m ] \
	-side left -expand true -fill both
pack [menubutton $gv(top).mbut.1.copy -text [lang "Copy..." "Copier..."] \
	-menu $gv(top).mbut.1.copy.m ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.1.del -text [lang "Delete" "Effacer"] \
	-command "v_mess delete" ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.1.undelete -text [lang "Undelete" "Recouvrir"] \
	-command "v_flagmess" ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.1.print -text [lang "Print" "Imprimer"] \
	-command {v_mess print} ] \
	-side left -expand true -fill both

bind_help $gv(top).mbut.1.move		$gv(top).help \
	[lang "Move the selected message(s) to a folder" "Dmnager le(s) message(s) choisi(ent)  un rpertoire"]
bind_help $gv(top).mbut.1.copy		$gv(top).help \
	[lang "Copy the selected message(s) to a folder" "Copier le(s) message(s) choisi(ent)  un rpertoire"]
bind_help $gv(top).mbut.1.del		$gv(top).help \
	[lang "Delete the selected message(s)" "Effacer le(s) message(s) choisi(ent)"]
bind_help $gv(top).mbut.1.undelete	$gv(top).help \
	[lang "Undelete the selected message(s)" "Recouvrir le(s) message(s) choisi(ent)"]
bind_help $gv(top).mbut.1.print		$gv(top).help \
	[lang "Print the selected message(s)" "Imprimer le(s) message(s) choisi(ent)"]

pack [frame $gv(top).mbut.2] \
	-side left -expand true -fill x
pack [menubutton $gv(top).mbut.2.other -text [lang "Other..." "Regarder..."] \
	-menu $gv(top).mbut.2.other.m ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.2.post -text [lang "Post" "FRENCH"] \
	-command {v_compose -type "Post" -newsgroups $gv(news.newsgroup)} ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.2.followup -text [lang "Followup" "FRENCH"] \
	-command {foreach mess [v_getselmess] {v_compose -type "Followup" -incmess "$gv(option:value:incmess)" -inctype quote -messlist $mess}} ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.2.forward -text [lang "Forward" "Relancer"] \
	-command {foreach mess [v_getselmess] {v_compose -type "Forward" -incmess all -messlist $mess}} ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.2.replyall -text [lang "Reply all" "Rpondre  tous"] \
	-command {foreach mess [v_getselmess] {v_compose -type "Replyall" -incmess "$gv(option:value:incmess)" -messlist $mess}} ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.2.reply -text [lang "Reply" "Rpondre"] \
	-command {foreach mess [v_getselmess] {v_compose -type "Reply" -incmess "$gv(option:value:incmess)" -messlist $mess}} ] \
	-side left -expand true -fill both
pack [button $gv(top).mbut.2.compose -text [lang "Compose" "Composer"] \
	-command {v_compose -type "Compose"} ] \
	-side left -expand true -fill both

bind_help $gv(top).mbut.2.other		$gv(top).help \
	[lang "Menu of other message functions" "FRENCH"]
bind_help $gv(top).mbut.2.post		$gv(top).help \
	[lang "Post new NEWS message" "FRENCH"]
bind_help $gv(top).mbut.2.followup		$gv(top).help \
	[lang "Followup message(s) in NEWS" "FRENCH"]
bind_help $gv(top).mbut.2.forward		$gv(top).help \
	[lang "Forward the current message(s)" "Relancer le(s) message(s) choisi(ent)"]
bind_help $gv(top).mbut.2.replyall	$gv(top).help \
	[lang "Reply to all addressees of the current message(s)" "Rpondre  tout les rcipients du(des) message(s) courant(s)"]
bind_help $gv(top).mbut.2.reply		$gv(top).help \
	[lang "Reply to the sender of the current message(s)" "Rpondre  l'originateur du(des) message(s) courant(s)"]
bind_help $gv(top).mbut.2.compose		$gv(top).help \
	[lang "Compose a new message" "Composer un message nouveau"]

menu $gv(top).mbut.2.other.m
$gv(top).mbut.2.other.m add command \
	-label [lang "Rescan message(s) for attachments" "FRENCH"] \
	-command "v_mess rescan ; v_dispmess \$gv(curmess) $gv(top)"
$gv(top).mbut.2.other.m add separator
$gv(top).mbut.2.other.m add command \
	-label [lang "View body of message(s) using VEdit" "FRENCH"] \
	-command "v_mess view vedit"
$gv(top).mbut.2.other.m add command \
	-label [lang "View body of message(s) using WordPerfect (xwp)" "FRENCH"] \
	-command "v_mess view xwp"
$gv(top).mbut.2.other.m add command \
	-label [lang "View body of message(s) using other program" "FRENCH"] \
	-command "v_mess view \[getstring $gv(top) {[lang "Program :" "Programme :"]} {}\]"
$gv(top).mbut.2.other.m add command \
	-label [lang "Pipe body of message(s) through a program" "FRENCH"] \
	-command "v_mess pipe \[getstring $gv(top) {[lang "Program :" "Programme :"]} {}\]"
$gv(top).mbut.2.other.m add separator
$gv(top).mbut.2.other.m add command \
	-label [lang "Edit message(s) (NOT RECOMMENDED)" "FRENCH"] \
	-command "v_mess edit vedit"
$gv(top).mbut.2.other.m add separator
$gv(top).mbut.2.other.m add cascade \
	-label [lang "Other compose options..." "FRENCH"] \
	-menu $gv(top).mbut.2.other.m.c
$gv(top).mbut.2.other.m add command \
	-label [lang "Bulk forward selected messages" "Relancer un groupe de message individuellement"] \
	-command "v_forward_bulk"

menu $gv(top).mbut.2.other.m.c
$gv(top).mbut.2.other.m.c add command -label [lang "Compose new message" "FRENCH" ] \
	-command {v_compose -type "Compose"}
$gv(top).mbut.2.other.m.c add separator
$gv(top).mbut.2.other.m.c add command -label [lang "Forward (include message body only)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Forward" -incmess "body" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Forward (include attachments)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Forward" -incmess "all" -messlist $mess}}
$gv(top).mbut.2.other.m.c add separator
$gv(top).mbut.2.other.m.c add command -label [lang "Reply (do not include message)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Reply" -incmess "none" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply (include message body only)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Reply" -incmess "body" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply (include attachments)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Reply" -incmess "all" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply (quote message body)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Reply" -incmess "body" -messlist $mess -inctype quote}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply (quote message body, include attachments)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Reply" -incmess "all" -messlist $mess -inctype quote}}
$gv(top).mbut.2.other.m.c add separator
$gv(top).mbut.2.other.m.c add command -label [lang "Reply all (do not include message)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Replyall" -incmess "none" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply all (include message body only)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Replyall" -incmess "body" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply all (include attachments)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Replyall" -incmess "all" -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply all (quote message body)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Replyall" -incmess "body" -messlist $mess -inctype quote}}
$gv(top).mbut.2.other.m.c add command -label [lang "Reply all (quote message body, include attachments)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Replyall" -incmess "all" -messlist $mess -inctype quote}}
$gv(top).mbut.2.other.m.c add separator
$gv(top).mbut.2.other.m.c add command -label [lang "Post new message to NEWS" "FRENCH" ] \
	-command {v_compose -type "Post"}
$gv(top).mbut.2.other.m.c add separator
$gv(top).mbut.2.other.m.c add command -label [lang "Followup message(s) in NEWS (do not include message)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Followup" -incmess "none" -inctype quote -messlist $mess}}
$gv(top).mbut.2.other.m.c add command -label [lang "Followup message(s) in NEWS (quote message body)" "FRENCH" ] \
	-command {foreach mess [v_getselmess] {v_compose -type "Followup" -incmess "body" -inctype quote -messlist $mess}}

#bind $gv(top).mbut.2.other.m.c	 <3> "$gv(top).mbut.2.other.m.c unpost ; break"
#bind_help $gv(top).mbut.2.other.m.c	$gv(top).help \
#		[lang "<1>=select <2>=move menu <3>=close menu" "FRENCH"]

bind $gv(top).mbut.2.post	<3> "tk_popup $gv(top).mbut.2.other.m.c %X %Y ; break"
bind $gv(top).mbut.2.followup	<3> "tk_popup $gv(top).mbut.2.other.m.c %X %Y ; break"
bind $gv(top).mbut.2.forward	<3> "tk_popup $gv(top).mbut.2.other.m.c %X %Y ; break"
bind $gv(top).mbut.2.replyall	<3> "tk_popup $gv(top).mbut.2.other.m.c %X %Y ; break"
bind $gv(top).mbut.2.reply	<3> "tk_popup $gv(top).mbut.2.other.m.c %X %Y ; break"
bind $gv(top).mbut.2.compose	<3> "tk_popup $gv(top).mbut.2.other.m.c %X %Y ; break"

pack [label $gv(top).subject -textvariable gv(stat.subject) \
	-foreground $gv(hfcolor) -background $gv(hbcolor)] \
	-side top -fill x
bind_help $gv(top).subject $gv(top).help \
	[lang "Subject of the message" "FRENCH"]


pack [frame $gv(top).mess] \
	-side top -expand true -fill both
pack [frame $gv(top).mess.attach] \
	-side right -fill y
pack [button $gv(top).mess.attach.view -text "View all" -width 8 \
	-command "v_attach_viewall $gv(top)" ] \
	-side top -fill x
pack [button $gv(top).mess.attach.save -text "Save all" -width 8 \
	-command "v_attach_saveall $gv(top)" ] \
	-side top -fill x

pack [scrollbar $gv(top).mess.yscroll -command "$gv(top).mess.txt yview" ] \
	-side $gv(option:value:scrollpos) -fill y
pack [text $gv(top).mess.txt -yscroll "$gv(top).mess.yscroll set" \
	-width $gv(option:value:messwidth) -wrap word -relief sunken ] \
	-expand true -fill both

bind_help $gv(top).mess.attach $gv(top).help \
	[lang "Attachment area" "FRENCH"]
bind_help $gv(top).mess $gv(top).help \
	[lang "Main body of the current message" "Corps principal du message courant"]
$gv(top).mess.txt tag configure search -background $gv(hbcolor) -foreground $gv(hfcolor)


#
#	Start up the actions required to get going
#
after 500 {
	mstatus 0 "...loading folder listing"
	v_folder load

	mstatus 0 "...initializing news"
	news init $gv(option:value:nntpserver) $gv(option:value:nntpport) $gv(option:value:newsmax)
	set gv(news.newsgroup) ""
	set gv(news.ngtype) "new"
	set gv(news.type) "new"

	mstatus 0 "...building news menu"
	v_newsbox menu

	# set the initial folder
	mstatus 0 "...opening +Inbox"
	set gv(curfold) ""
	v_openfolder $gv(inbox)

	# start up the mailbox checking
	v_schedule

}

#
#	Ready to go
#

wm withdraw .
if {[winfo exists .startup]} {destroy .startup}
if {[info exists gv(startup.id)]} {image delete $gv(startup.id)}

update idletasks

if {[file exists $env(HOME)/.forward]} {
	set fp [open $env(HOME)/.forward r]
	set res [read -nonewline $fp]
	catch {close $fp} junk
	if {[regexp "vacation" $res] \
		&& [yesno $gv(top) "Vacation looks like it is turned on.  Turn it off?"]} {
		catch {f_rename $env(HOME)/.forward $env(HOME)/.forward.save} res
	}
}
