### Copyright (C) 1995-97 Jesper K. Pedersen
### 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 general {} {
  # General Setup

  Dir-Browser mailDir \
      -text "Directory to keep mail and logfiles in"\
      -default "~/Mail"

  Entry loginName \
      -text "email address"\
      -packEntry:expand 1 -packEntry:fill x
  
  Command getLogin \
      -invoke {
        set loginName [getUserName]
      }\
      -setvalue {$widget configure -text "Ask the system\nfor my name"}
  Frame userFrm \
      -entries loginName getLogin

  Header log \
      -text Log Files\
      -background grey

  Entry logfile \
      -text logfile\
      -textafter "(eventually with offset in Maildir)"\
      -default _logfile

  CheckBox extlog \
      -text "Turn on extended log diagnostics"\
      -default 0

  CheckBox logabstract\
      -text "Keep an abstract in the logfile"\
      -default 1

  Header pathh \
      -text "Search Path"\
      -background grey

  Dir-Browser pathComponent -text Directory
  ExtEntry path \
      -entries frame_pathComponent\
      -export 0
  Command readPath \
      -setvalue {$widget configure -text "Load path\nfrom system"} \
      -invoke {
        if {[info exists env(PATH)]} {
          foreach elm [split $env(PATH) ":"] {
            AddTuple path
            set pathComponent $elm
            set com_pathComponent $elm
          }
        }
      }
  Frame pathFrame -entries path readPath
  
  ######################################################################
  ###                       Help
  ######################################################################
  Desc \
      "On this page, you may configure the general setup for procmail."
  foreach elm {mailDir frame_mailDir com_mailDir} {
    Help $elm \
        "This is the directory to which all file commands are relative."\
        "This means that if you specify that a given message should"\
        "be saved to a file called test_file, that file will be placed"\
        "in this directory.  If you however specify full path, this"\
        "entry doesn't have any influence."
  }
  Help loginName \
      "This is your full email address.  It is used in situations, where"\
      "loop back is to be prevented (eg. you send a reply to a list,"\
      "saying that you are not home.  This letter will then be sent to"\
      "you (among many others) by the list, and you will reply again,"\
      "and again and.....)"

  Help getLogin \
      "This will try to see if 'whoami' and 'hostname -d' work on"\
      "your system.  If it does, this will be your email address."

  Help log\
      "Log files may be very useful if you suspect that something is"\
      "wrong with your procmail configuration.  A very useful program,"\
      "which comes with procmail is 'mailstat'. Type mailstat -h to get"\
      "some help.  Mailstat will give you a statistic of the log"\
      "file.  It is however required that the abstract login are"\
      "enabled."

  Help logfile\
      "This is the file in which log information should be placed. It"\
      "can be given either full (as in /home/blackie/logfile) or"\
      "relative to the mail directory specified above."

  Help extlog\
      "If you suspect that something is wrong with your procmail"\
      "configuration, you may turn on \"Verbose mode\".  In this mode"\
      "procmail will log anything it does!"

  Help logabstract\
      "If you select this check button, procmail will write an abstract"\
      "to the logfile, with information about where the mail ended up,"\
      "the user who sent you the mail and the subject of the mail."
  foreach elm {pathh pathComponent frame_pathComponent com_pathComponent
    path readPath pathFrame} {
      Help $elm \
          "If you specify any programs without a full path, the program"\
          "must be located in one of these directories.  External"\
          "programs are required, when you eg. specify a filter for a"\
          "letter"
    }
  ######################################################################
  ###                       Funktions
  ######################################################################
  PageEnd {
    if {$loginName == ""} {
      error "Empty login name!"
    }
    if {$mailDir == ""} {
      set mailDir ~/
    }
  }
  Save {
    if {$loginName == ""} {
      set w [makeTempWindow "Please give me your email address"]
      label $w.label -text "Please give me your email adress"
      entry $w.entry
      bind $w.entry <Return> "set loginName \[$w.entry get\];destroy $w"
      button $w.ok -command "set loginName \[$w.entry get\];destroy $w"\
          -text OK
      pack $w.label $w.entry $w.ok
      $w.entry insert 0 [getUserName]
      pushGrab local $w
      tkwait window $w
      popGrab
    }
    if {![file exists $mailDir]} {
      set answer [tk_dialog .error "Directory does not exixt" "The directory \"$mailDir\" does not exists. It is necessary for procmail that this directory exist, shall I create it?" error 0 Yes No]
      if {$answer == 0} {
        createDir $mailDir
      }
    }

    print "SHELL = $__system(mailhost,sh)"
    print "MAILDIR = [convertTilde $mailDir]"
    print "LOGFILE = [convertTilde $logfile]"
    print "VERBOSE = [pick $extlog yes no]"
    print "LOGABSTRACT = [pick $logabstract all no]"

    set p ""
    forevery path {
      append p :$pathComponent
    }
    if {$p != ""} {
      print "PATH = [string range $p 1 end]"
    }
    print ""
  }
}
