;**
;** Install_AEMail - AEMail installation script for Installer
;**
;** Copyright (c) 1996-1998 John F. Zacharias
;**                    All rights reserved.
;**
;** This script has been tested with Installer 43.3 which is included with
;** this archive:
;**
;**     Installer and Installer project icon
;**     (c) Copyright 1995-96 Escom AG.  All Rights Reserved.
;**     Reproduced and distributed under license from Escom AG.
;**
;**     INSTALLER SOFTWARE IS PROVIDED "AS-IS" AND SUBJECT TO CHANGE;
;**     NO WARRANTIES ARE MADE.  ALL USE IS AT YOUR OWN RISK.  NO LIABILITY
;**     OR RESPONSIBILITY IS ASSUMED.
;**
;** Use following Icon tooltypes / Command line options:
;**
;** APPNAME=AEMail
;** MINUSER=NOVICE
;**
;**
;** Installer script modified on 03/07/98 for AEMail Version 1.50

(set
 ;;
 ;; The source directory name
 ;;
 source-dir (if (= 1 (exists @icon))
		    (pathonly (expandpath @icon))
		    (expandpath @icon)))

(set version_3_0 39)

(set aem-vernum (getversion (tackon source-dir "AEMail")))
(set
    aem-vernew (/ aem-vernum 65536)
    aem-revnew (- aem-vernum (* aem-vernew 65536)))

(set exec-version (/ (getversion) 65536))
(set avail-mem (+ (database "total-mem")))
(set system-cpu (database "cpu"))

(set full-aem-name "AEMail Beta Version 1.50")

(set
    aem-name "AEMail"
    aem-assign (cat aem-name ":")
    aem-Termite 0
    )

(if (= 1 (exists "ENV:TermiteTCP.prefs" (noreq)))
         (set aem-Termite 1)
         (set aem-Termite 0))

(if (= 2 (exists "AMITCP:bin" (noreq)))
    (set aem-have-AMITCP 1)
    (set aem-have-AMITCP 0))

(if (= 2 (exists "Miami:" (noreq)))
    (set aem-have-MIAMI 1)
    (set aem-have-MIAMI 0))

(if (= 1 (exists "ENV:AEMail_Dir" (noreq)))
    ((set
        @default-dest (getenv ("AEMail_Dir"))
        len (strlen @default-dest))
     (if (= "\n" (substr @default-dest (- len 1) 1))
         (set @default-dest (substr @default-dest 0 (- len 1)))))
    (set @default-dest
        (if (= 1 aem-have-AMITCP)
            (expandpath "AMITCP:bin")
            (@default-dest))))

(if (= "AEMail" (fileonly @default-dest))
    (set @default-dest (pathonly @default-dest)))


(if (= 2 @user-level)

    (set
    ;;
    ;; Sets up where to place AEMail program
    ;;
    @default-dest
        (askdir
            (prompt "Enter the drawer in which you want AEMail installed\n"
                    "A drawer called AEMail will be created "
                    "if it does not already exist (except if AmiTCP:bin is "
                    "specified)")
            (help   "If you are using AmiTCP, AEMail should be installed in "
                    "'AmiTCP:bin'\n\n"
                    "However, you may install it anywhere you like\n\n"
                    "If it is not 'AmiTCP:bin' a drawer called 'AEMail' "
                    "will be created.\n")
            (default @default-dest)
            (newpath))))

(if (= 1 aem-have-AMITCP)
    (if (<> @default-dest (expandpath "AMITCP:bin"))
        (set aem-have-AMITCP 0)))

; (if (= "AEMail" (fileonly @default-dest))
;     (set @default-dest (pathonly @default-dest)))

(if (= 0 aem-have-AMITCP)
    (set @default-dest (tackon @default-dest "AEMail")))

(if (= 0 (exists @default-dest (noreq)))
    ((makedir @default-dest (infos))
     (onerror ((delete @default-dest
                (prompt "Deleting AEMail directory")
                (help "Deleting AEMail directory")
                (optional "force")
                (safe)
                (all)
                (infos))
              (delete "RAM:AEMfiles"
                (prompt "Deleting RAM: AEMail files")
                (optional "force")
                (safe)
                (all)
                (infos))))))

(if (= 1 (exists @default-dest (noreq)))
    (set @default-dest (pathonly @default-dest)))

(set aem-default-dest @default-dest)

(set
 ;;
 ;; The default Mail directory
 ;;
    aem-change-name 0

    atcp-dir (if (= 1 aem-have-AMITCP)
        (expandpath "AMITCP:")
        (@default-dest))

    aem-dft-maildir (if (= 2 (exists aem-assign (noreq)))
        (pathonly(getassign aem-name))
        (atcp-dir))

    aem-mail-name (if (= 2 (exists aem-assign (noreq)))
        (fileonly(getassign aem-name))
        (""))
  )


(if (<> "" aem-mail-name)
    (if (<> "AEMail_Mail" aem-mail-name)
        ((set
            aem-change-name
                (askbool
                    (prompt "Your AEMAIL: assignment is for:\n\n"
                            (getassign aem-name) "\n\n"
                            "This directory is not named \"AEMail_Mail\"\n\n"
                            "Do you want to change the directory's name to "
                            "\"AEMail_Mail\" and use it as your AEMAIL: directory?")
                    (help   "This install script automatically uses an AEMAIL: "
                            "assignment name of \"AEMail_Mail\".  If you reply NO "
                            "to this request your existing AEMAIL: directory "
                            "will NOT be used as your mail directory\n")
                    (default 1))))))

(if (= 1 aem-change-name)

    ((rename (tackon aem-dft-maildir aem-mail-name)
            (tackon aem-dft-maildir "AEMail_Mail")
            (prompt "Relabeling AEMAIL: directory")
            (help   "Relabeling AEMAIL: directory"))
    (rename (tackon aem-dft-maildir ("%s.info" aem-mail-name))
            (tackon aem-dft-maildir "AEMail_Mail.info")
            (prompt "Relabeling AEMAIL: directory .info")
            (help   "Relabeling AEMAIL: directory .info")))
)

(set
    aem-mail-dir (aem-dft-maildir))

(if (= 2 @user-level)

    (set
        aem-mail-dir
            (askdir
                (prompt "Enter the drawer in which you want your mail placed.  "
                    "A drawer called 'AEMail_Mail' will be created in this "
                    "drawer (if it does not already exist) and AEMAIL: will be "
                    "assigned to 'AEMail_Mail'")
                (help   "All of your mail and configuration files will be stored "
                    "in the 'AEMail_Mail' sub-directory of this drawer.  An assign "
                    "statement will be assigned to the 'AEMail_Mail' sub-directory to 'AEMAIL:' "
                    "and will be placed in your 'S:User-Startup' script.\n\n"
                    "The directory your specify here will be created if it does "
                    "not exist\b")
                (default aem-dft-maildir)
                (newpath))))


(if (= "AEMail_Mail" (fileonly aem-mail-dir))
    (set aem-mail-dir (pathonly aem-mail-dir)))

(set aem-mail-dir (tackon aem-mail-dir "AEMail_Mail"))

; Use ENV:PAGER program, Multiview, or copy "More" to RAM: for use

(set
 pager-cmd (if (exists "ENV:PAGER" (noreq)) (getenv "PAGER"))
 pager-cmd
    (if pager-cmd pager-cmd
        (if (= 1 (exists "SYS:Utilities/Multiview" (noreq)))
            ("SYS:Utilities/Multiview")
            ((copyfiles
	            (prompt "Copying " (tackon source-dir "c/More") " to RAM: for use")
	            (source (tackon source-dir "c/More"))
	            (dest   "RAM:")
	            (safe)
	            (optional "nofail"))
	            "RAM:More"))))

(makedir "RAM:AEMfiles")
(makedir "RAM:AEMfiles/ARexx")

(copyfiles
    (prompt "Copying AEMail.readme to RAM:")
	(source (tackon source-dir "AEMail.readme"))
	(dest   "RAM:AEMfiles")
    (infos))

(copyfiles
    (prompt "Copying LHA to RAM:")
	(source (tackon source-dir "c/LHex"))
	(dest   "RAM:"))

(set
    doc-files (tackon source-dir "files.lha"))

(set
    doc-files ("\"%s\"" doc-files))

(message "\n\nSelect PROCEED to decompress the AEMail files to RAM\n\n"
    "Be patient, this will take a while\n\n"
    "If you are installing from diskette, the decompression "
    "will take approx 3 minutes\n\n"
    "From your hard drive, the decompression will take approx 20 seconds")

(set aem-lha
    (run "RAM:lhex -fwRAM:AEMfiles x " doc-files " >NIL:" (safe)))
(set aem-lha
    (run "RAM:lhex -fw=RAM:AEMfiles/ARexx x RAM:AEMfiles/arexx.lha >NIL:" (safe)))

(delete 
    "RAM:lhex"
    (prompt "Deleting RAM:lha file")
    (optional "force")
    (safe))

(if (< exec-version version_3_0)
    (tooltype
        (dest "RAM:AEMfiles/AEMail.guide")
        (setdefaulttool "AmigaGuide"))
    (tooltype
        (dest "RAM:AEMfiles/AEMail.guide")
        (setdefaulttool "MultiView")))

(set
    aem-configure 0
    aem-interlace 0
    aem-needconfig 0
    aem-options 3
    aem-config ""
    aem-username ""
    aem-password ""
    aem-from ""
    aem-replyto ""
    aem-organization ""
    aem-realname ""
    aem-domain ""
    aem-popserver ""
    aem-smtpserver ""
    aem-editor ""
    aem-startnet ""
    aem-stopnet ""
    aem-need-AREXX 0
    aem-needstrtarexx 0
    aem-needstoparexx 0)

(if (= 1 aem-have-MIAMI)
    (set
        aem-need-AREXX 1
        aem-needstrtarexx 1
        aem-startnet (tackon aem-default-dest "startnet.miami")
        aem-needstoparexx 1
        aem-stopnet  (tackon aem-default-dest "stopnet.miami"))
    (if (= 1 aem-have-AMITCP)
        (set
            aem-need-AREXX 1
            aem-startnet (tackon aem-default-dest "startnet")
            aem-stopnet (tackon aem-default-dest "stopnet"))))

(if (= 1 aem-Termite)
    ((set
        aem-from (getenv "ttcp-email-address")
        aem-tccp-len (strlen aem-from)
        aem-tccp-cnt 0)

     (while (<> aem-tccp-cnt aem-tccp-len)
            (if (= "@" (substr aem-from aem-tccp-cnt 1))
                (set
                    aem-username
                        (substr aem-from 0 aem-tccp-cnt)
                    aem-tccp-cnt (+ 1 aem-tccp-cnt)
                    aem-domain
                        (substr aem-from aem-tccp-cnt))
                (set
                    aem-tccp-cnt (+ 1 aem-tccp-cnt))))))


(if (< 0 @user-level)
(if (<> 1 (exists "s:aemail.cnfg" (noreq)))
(set
    aem-configure
        (askbool
            (prompt "\nYou can configure AEMail now or you can wait until "
                    "AEMail is first loaded.  Do you want to configure now?\n")
            (help   "AEMail is configured either by Tool Types in it's icon "
                    "or by a configuration screen which is automatically "
                    "called up when you first execute AEMail if the Tool "
                    "Type parameters were not given.  By replying "
                    "'Yes, Configure Now' you will be setting the Tool Type "
                    "parameters\n")
            (choices "No, Configure Later" "Yes, Configure Now"))
    )
(set
    aem-configure
        (askbool
            (prompt "\nYou have an existing configuration file.\n\n"
                    "Do you want to use it or do you want to re-configure "
                    "AEMail now?\n")
            (help   "By replying 'Yes, Re-configure Now' "
                    "you will be renaming the current configuration file "
                    "to 's:aemail.cnfg.old' "
                    "and resetting the configuration by tool type "
                    "parameters\n")
            (choices "Use existing Config File" "Yes, Re-Configure Now")))
)
)

(if (= 0 aem-configure)
    ((rename "s:aemail.cnfg" "s:aemail.cnfg.old"
            (prompt "Renaming old s:aemail.cnfg file"))
    (set aem-interlace
        (askbool
            (prompt "\n\nDo you want to open AEMail on an interlaced screen?")
            (help   "Replying 'YES' will place the Tool Type 'INTERLACE=YES' "
                    "in your AEMail icon.  This will open AEMail on an "
                    "interlaced screen when it is executed.\n")))

    (Set continue 0)

    (message "\n\nWe need to know something about your Internet provider and what "
        "the POP and SMTP Servers on your provider's machine are called.  "
        "Also, when you signed up for your InterNet service you chose or "
        "were given a login name and password for your POP server. "
        "You will be prompted for these names now.  If you have any "
        "questions as to what parameters to use, select 'help' "
        "or consult information provided by your Internet provider.")

    (while
        (= continue 0)

        (set

        aem-domain
            (askstring
                (prompt "\nEnter the domain name for your InterNet Provider " 
                        "required for getting mail\n\n")
                (help   "The domain name is usually the part of your e-mail address "
                        "that follows the '@' sign.  If something else is required "
                        "by your Internet Provider, provide it here.\n\n"
                        "As an example, my email "
                        "address is\n\njzachar@calweb.com\n\nThe domain name "
                        "for my Internet provider is therefor 'calweb.com'.")
                (default aem-domain))

        aem-popserver
            (if (= "" aem-domain)
                ("")
                (if (= "" aem-popserver)
                    (cat "pop." aem-domain)
                    (aem-popserver)))

        aem-smtpserver
            (if (= "" aem-domain)
                ("")
                (if (= "" aem-smtpserver)
                    (cat "smtp." aem-domain)
                    (aem-smtpserver)))

        aem-popserver
            (askstring
                (prompt "\nEnter the name of your POP Server\n\n")
                (help   "POP stands for 'Post Office Protocol' and your "
                        "POP Server is the name assigned to the host "
                        "computer that holds your Internet mail.  Normally "
                        "this would be 'pop.' or 'mail.'  prepended to your "
                        "Domain name.\n\n"
                        "Consult your Internet provider if the POP Server "
                        "is called something other than '"aem-popserver
                        "' enter that name in this string requester ")
                (default aem-popserver))

        aem-smtpserver
            (askstring
                (prompt "\nEnter the name of your SMTP Server\n")
                (help   "SMTP stands for 'Simple Mail Transfer Protocol' and "
                        "your SMTP server is the name assigned to the host "
                        "computer that sends your Internet mail.  Normally "
                        "this would be 'smtp.' or 'mail.' prepended to your " 
                        "Domain name.\n\n"
                        "Consult your Internet provider if the SMTP Server "
                        "is called something other than '"aem-smtpserver
                        "' enter that name in this string requester ")
                (default aem-smtpserver))

        aem-username
            (askstring
                (prompt "\nEnter the login name you have been assigned by your "
                "InterNet Provider for logging into your POP Server\n\n"
                "NOTE: Your provider may have allowed you to chose this login "
                "name.\n")
                (help "You must give your login name.  The login name consists "
                "of lowercase letters a-z and numbers.  Its recommended maximum "
                "length is 8 characters.\n\n"
                "Examples of acceptable login names are 'jzachar' and "
                "'an345'.")
                (default aem-username))

        aem-password
            (askstring
                (prompt "\n\nEnter the password you need to log into your "
                "POP Server.\n\n"
                "NOTE: Your provider may have assigned you your password"
                " or you were allowed to chose your own.\n")
                (help   "This may be the same password that you use to log "
                        "into your Internet Provider.  Consult your Internet "
                        "Provider (ISP) if it is different.")
                (default aem-password))


        continue
            (askbool
                (prompt "Is the following information correct?\n\n"
                    "SMTP Domain name: " aem-domain "\n"
                    "POP Server Name: " aem-popserver "\n"
                    "SMTP Server Name: " aem-smtpserver "\n"
                    "Login name: " aem-username "\n"
                    "Password: " aem-password "\n\n")
                (help "If you have made a mistake on any of the entries you "
                "can select \"No, Enter Again\" or, if eveything is all right, "
                "select \"Yes, Continue\"\n")
                (choices "Yes, Continue" "No, Enter Again"))
        )
    )

    (Set continue 0)

    (set
        aem-from 
            ("%s@%s" aem-username aem-domain))

    (message "\n\nWhen you signed up for your InterNet service you were "
         "also assigned an email address to receive mail with.  You will "
         "be prompted for this now.")


    (while
        (= continue 0)

        (set

        aem-from
            (askstring
                (prompt "\n\nEnter your full email address (user@domain):\n")
                (help "You must give your email address.  The email address "
                    "is what you are known by on the Internet and consists of " 
                    "a username and domain name separated by an '@' sign.\n\n"
                    "NOTE: The username and domain name could be the same "
                    "as the POP login name and SMTP Domain Name you were "
                    "prompted for before, or they MAY NOT be - consult your "
                    "ISP.")
                (default aem-from))

        continue
            (askbool
                (prompt "\n\nIs the following information correct?\n\n"
                    "Email Address: " aem-from "\n\n")
                (help "If you have made a mistake with this entry you "
                "can select \"No, Enter Again\" or, if eveything is all right, "
                "select \"Yes, Continue\"\n")
                (choices "Yes, Continue" "No, Enter Again"))
        )
    )

    (Set continue 0)

    (message "\n\nThere is certain identity information that you "
         "may give to further identify you on the Internet.  These include "
         "your real name, a possible reply address, and the organization "
         "that you belong to.  You will be prompted for these now. These are "
         "all optional parameters and you can leave them blank if you wish.")

    (set aem-replyto aem-from)

    (while
        (= continue 0)

        (set

        aem-realname
            (askstring
                (prompt "\n\nEnter the real name for "aem-from ":\n")
                (help "The real name can contain any characters except "
                    "comma (','), colon (':') or bar ('|').")
                (default aem-realname))

        aem-replyto
            (askstring
                (prompt "\n\nEnter the email address you want replies "
                    "sent to\n\n")
                (help   "This may be the same as your regular email address. "
                        "This address is optional and can be left blank.")
                (default aem-replyto))

        aem-organization
            (askstring
                (prompt "\n\nEnter the organization you belong to (optional):\n")
                (help "The organization is optional and can be left blank.")
                (default aem-organization))

        continue
            (askbool
                (prompt "\n\nIs the following information correct?\n\n"
                    "Real name: " aem-realname "\n"
                    "Reply To Address: " aem-replyto "\n"
                    "Organization: " aem-organization "\n\n")
                (help "If you have made a mistake on any of the entries you "
                "can select \"No, Enter Again\" or, if eveything is all right, "
                "select \"Yes, Continue\"\n")
                (choices "Yes, Continue" "No, Enter Again"))
        )
    )

    (message "\n\nAEMail requires an editor to prepare messages to send.  "
        "You can use the standard AmigaDOS editor, ed, or any "
        "editor of your choice.")


    (set
        aem-editor
            (askfile
                (prompt "Enter the Editor you want to use with AEMail.")
                (help   "AEMail requires an editor to prepare messages to "
                        "send.  After your select the editor from the file "
                        "requester you will be asked to enter parameter "
                        "information required by your editor.\n")
                (default "SYS:c/ed"))

        aem-editor
            (askstring
                (prompt "Add the parameters required for your editor.\n\n"
                        "You must always add '%s' to specify where your "
                        "mail file name goes.\n")
                (help   "You will need to add parmeters that may be "
                        "required by your editor.  One required parameter "
                        "required by ALL editors is '%s' to specify where "
                        "the mail file name goes.\n")
                (default (cat aem-editor " %s")))

        aem-edonwb
            (askbool
                (prompt "Does your editor have to open on the Workbench?"
                (help   "Some editors, like Commodore's ED will always open "
                        "on the Workbench.  Others will open on their own "
                        "screen.  If your editor opens on the Workbench, "
                        "you must reply 'YES' to this request.\n")))

        aem-editor
            (if (= 1 aem-edonwb)
                (cat "WB;" aem-editor)
                ("%s" aem-editor))
    )

    (set 
        aem-neednetscrpts
            (askbool
                (prompt "\n\nDo you want Start Net and/or Stop Net scripts?\n")
                (help   "If you reply 'Yes', you will be prompted for your "
                        "Start Net and Stop Net scripts.\n"
                        "If you reply 'No', AEMail will run without any "
                        "Start Net or Stop Net scripts.\n")))

    (if (= 1 aem-neednetscrpts)
        (if (<> "" aem-startnet)
          (set aem-neednetscrpts
            (askbool
                (prompt "Is your StartNet and/or StopNet scripts other than\n\n"
                        "Start Net: " aem-startnet "\n"
                        "Stop Net:  " aem-stopnet  "\n")
                (help   "Only reply 'YES' if your Start Net and Stop Net scripts "
                        "are not the scripts listed listed below:\n\n"
                         aem-startnet "\n"
                         aem-stopnet "\n"))))
        (set
            aem-needstrtarexx 0
            aem-startnet ""
            aem-needstoparexx 0
            aem-stopnet ""))


    (if (= 1 aem-neednetscrpts)
        ((set
          need-startnet
            (askbool
                (prompt "Do you need a Start Net script?")
                (help   "If you reply 'No' AEMail will run without a Start Net "
                        "script\n\nIf you reply 'YES' you will be prompted "
                        "for the location of your Start Net script")))
        (if (= 1 need-startnet)
             (set
               aem-startnet
                (askfile
                  (prompt "Enter the Start Net script you want to use with AEMail.")
                  (help   "If you are NOT using the standard AmiTCP startnet "
                          "script in AmiTCP:bin or the standard Miami script "
                          "you will have to provide the "
                          "script you are using.\n")
                  (default (tackon aem-default-dest "startnet")))
               aem-needstrtarexx
                (askbool
                    (prompt "Is this an AmigaDOS script or an AREXX script?")
                    (help   "The standard AmiTCP Start Net script is an AmigaDos "
                            "script that calls AREXX\n\n "
                            "The standard Miami script is an AREXX script "
                            "AND must be called from AREXX\n")
                    (choices "AREXX script" "AmigaDOS script")))
             (set aem-startnet ""
                  aem-needstrtarexx 0))

        (set
          need-stopnet
            (askbool
                (prompt "Do you need a Stop Net script?")
                (help   "If you reply 'No' AEMail will run without a Stop Net "
                        "script\n\nIf you reply 'YES' you will be prompted "
                        "for the location of your Stop Net script")))
        (if (= 1 need-stopnet)
            (set
               aem-stopnet
                (askfile
                  (prompt "Enter the Stop Net script you want to use with AEMail.")
                  (help   "If you are NOT using the standard AmiTCP stopnet "
                          "script in AmiTCP:bin or the standard Miami script "
                          "you will have to provide the "
                          "script you are using.\n")
                  (default (tackon aem-default-dest "stopnet")))
               aem-needstoparexx
                (askbool
                    (prompt "Is this an AmigaDOS script or an AREXX script?")
                    (help   "The standard AmiTCP Stop Net script is an AmigaDos "
                            "script that calls AREXX\n\n "
                            "The standard Miami script is an AREXX script "
                            "AND must be called from AREXX\n")
                    (choices "AREXX script" "AmigaDOS script")))
             (set aem-stopnet ""
                  aem-needstoparexx 0))))

    (set aem-options
        (askoptions
            (prompt "Select those AEMail options you want AEMail to open with\n\n")
            (help @askoptions-help)
            (choices "Delete Mail from Server"
                 "Strip Duplicate Messages"
                 "Display Full Header"
                 "Include Header in Reply"
                 "Automatic Connection at Startup"
                 )
            (default 3))
    )))


(if (= 1 aem-needstrtarexx)
    (set
        aem-startnet
            (cat "rx " aem-startnet)))

(if (= 1 aem-needstoparexx)
    (set
        aem-stopnet
            (cat "rx " aem-stopnet)))

(if (= 2 @user-level)
    (set
      aem-needconfig
        (askbool
            (prompt "Do you want to run with your own configuration file?")
            (help   "If you are using the standard s:aemail.cnfg file "
                    "reply 'NO'.\n\n"
                    "If you want to use your own configuration file then "
                    "reply 'YES'")))
    (set aem-needconfig 0))

(if (= 1 aem-needconfig)
    (set
        aem-config
            (askfile
                (prompt "Enter the configuration script you want to use "
                        "with AEMail")
                (help   "If you are using a configuration file other than "
                        "s:aemail.cnfg you can locate and or specify it "
                        "here.")
                (default "s:aemail.cnfg"))))

(set
    aem-docs-dir-dft (tackon @default-dest "documentation")
    aem-rexx-dir-dft (tackon @default-dest "ARexx"))

(if (< 0 @user-level)
    (set
      aem-docs
        (askoptions
            (prompt "Select which AEMail documentation files you want copied\n\n")
            (help @askoptions-help)
            (choices "AEMail.readme"
                     "AEMail.doc"
                     "AEMail.guide"
                     "email.txt"
                     )
            (default 15)))

    (set aem-docs 15))


(if (= 2 @user-level)
    (if (<> 0 aem-docs)
        (set
          aem-docs-dir
            (askdir
                (prompt "Which directory do you want the documentation files "
                        "copied to\n")
                (help   "You may select a different directory than the " 
                        "'documentation' sub-directory in your program's "
                        "directory to copy the documentation files to.\n")
                (newpath)
                (default aem-docs-dir-dft))))
    (set aem-docs-dir aem-docs-dir-dft)
)

(if (= 2 @user-level)
        (set
          aem-rexx-dir
            (askdir
                (prompt "Which directory do you want the ARexx files "
                        "copied to\n")
                (help   "You may select a different directory than the " 
                        "'ARexx' sub-directory in your program's "
                        "directory to copy the ARexx files to.\n")
                (newpath)
                (default aem-rexx-dir-dft)))
    (set aem-rexx-dir aem-rexx-dir-dft)
)

(if (<> 2 (exists aem-mail-dir (noreq)))
    (makedir aem-mail-dir (infos)))

(if (<> 2 (exists aem-docs-dir (noreq)))
    (makedir aem-docs-dir (infos)))

(if (<> 2 (exists aem-rexx-dir (noreq)))
    (makedir aem-rexx-dir (infos)))

(copyfiles
    (prompt "Copying AEMail to " @default-dest)
	(source "RAM:AEMfiles/AEMail")
	(dest   @default-dest))

(copyfiles
    (prompt "Copying AEMail.info to " @default-dest)
	(source "RAM:AEMfiles/AEMail.inf")
	(newname "AEMail.info")
	(dest   @default-dest)
	(noposition))

(copyfiles
    (prompt "copy registration.form to " @default-dest)
	(source (tackon source-dir "registration.form"))
	(dest   @default-dest)
    (noposition)
    (infos))

(if (= 1 aem-have-MIAMI)
    ((copyfiles
        (prompt "Copy Miami Start Net script to " @default-dest)
        (source (tackon source-dir "startnet.miami"))
        (dest   @default-dest))
    (copyfiles
        (prompt "Copy Miami Stop Net script to " @default-dest)
        (source (tackon source-dir "stopnet.miami"))
        (dest   @default-dest))))

(if (= 1 (exists (tackon @default-dest "AEMail.readme") (noreq)))
    (delete (tackon @default-dest "AEMail.readme")
        (prompt "Deleting old AEMail.readme file")
        (infos)))

(if (= 1 (exists (tackon aem-docs-dir "AEMail.readme") (noreq)))
    (delete (tackon aem-docs-dir "AEMail.readme")
        (prompt "Deleting old AEMail.readme file")
        (infos)))

(if (= 1 (exists (tackon @default-dest "AEMail.doc") (noreq)))
    (delete (tackon @default-dest "AEMail.doc")
        (prompt "Deleting old AEMail.doc file")
        (infos)))

(if (= 1 (exists (tackon @default-dest "AEMail.guide") (noreq)))
    (delete (tackon @default-dest "AEMail.guide")
        (prompt "Deleting old AEMail.guide file")
        (infos)))

(set aem-readtool
    (if (= pager-cmd "RAM:More")
        ("more")
        (pager-cmd)))


(if (<> 0 aem-docs)(
    (if (BITAND aem-docs 1)
        ((copyfiles
            (prompt "Copying AEMail.readme file to " @default-dest)
	        (source "RAM:AEMfiles/AEMail.readme")
	        (dest   @default-dest)
	        (infos))
        (tooltype
            (dest (tackon @default-dest "AEMail.readme"))
            (noposition)
            (setdefaulttool aem-readtool))))       

    (if (BITAND aem-docs 2)
        ((copyfiles
            (prompt "Copying AEMail.doc file to " aem-docs-dir)
	        (source "RAM:AEMfiles/AEMail.doc")
	        (dest   aem-docs-dir)
	        (infos))
        (tooltype
            (dest (tackon aem-docs-dir "AEMail.doc"))
            (noposition)
            (setdefaulttool "more"))))       

    (if (BITAND aem-docs 4)
        ((copyfiles
            (prompt "Copying AEMail.guide file to " aem-docs-dir)
	        (source "RAM:AEMfiles/AEMail.guide")
	        (dest   aem-docs-dir)
	        (infos))
        (tooltype
            (dest (tackon aem-docs-dir "AEMail.guide"))
            (noposition))))

    (if (BITAND aem-docs 8)
        ((copyfiles
            (prompt "Copying email.txt file to " aem-docs-dir)
	        (source "RAM:AEMfiles/email.txt")
	        (dest   aem-docs-dir)
	        (infos))
        (tooltype
            (dest (tackon aem-docs-dir "email.txt"))
            (noposition)
            (setdefaulttool "more"))))       

))


(copyfiles
    (prompt "copy ARexx files to " aem-rexx-dir)
	(source "RAM:AEMfiles/ARexx/")
	(dest   aem-rexx-dir)
    (all)
    (noposition)
    (infos))
 
(tooltype
    (prompt "Setting AEMail Tool Types")
    (dest (tackon @default-dest "AEMail"))
    (if (<> "" aem-config)
        (settooltype "CONFIG" aem-config))
    (if (= 1 aem-interlace)
        (settooltype "INTERLACE" "YES"))
    (if (<> "" aem-username)
        (settooltype "USERID" aem-username))
    (if (<> "" aem-password)
        (settooltype "PASSWRD" aem-password))
    (if (<> "" aem-realname)
        (settooltype "REALNAME" aem-realname))
    (if (<> "" aem-from)
        (settooltype "FROM" aem-from))
    (if (<> "" aem-replyto)
        (settooltype "REPLYTO" aem-replyto))
    (if (<> "" aem-organization)
        (settooltype "ORGANIZATION" aem-organization))
    (if (<> "" aem-domain)
        (settooltype "DOMAIN" aem-domain))
    (if (<> "" aem-popserver)
        (settooltype "POP_SERVER" aem-popserver))
    (if (<> "" aem-smtpserver)
        (settooltype "SMTP_SERVER" aem-smtpserver))
    (if (<> "" aem-editor)
        (settooltype "EDITOR" ("\"%s\"" aem-editor)))
    (if (<> "" aem-startnet)
        (settooltype "STARTNET" aem-startnet))
    (if (<> "" aem-stopnet)
        (settooltype "STOPNET" aem-stopnet))
    (if (BITAND aem-options 1)
        (settooltype "DELETEMAIL" "YES"))
    (if (BITAND aem-options 2)
        (settooltype "STRIPDUPS" "YES"))
    (if (BITAND aem-options 4)
        (settooltype "FULLHEADER" "YES"))
    (if (BITAND aem-options 8)
        (settooltype "HDRINREPLY" "YES"))
    (if (BITAND aem-options 16)
        (settooltype "AUTOCONNECT" "YES"))
)

(procedure aemp-build_mailcap

    ((set
        aem-mimetypes
            (askoptions
                (prompt "Indicate those mime types/subtypes you want "
                        "display programs for")
                (help   "Check which types/subtypes that you will specify "
                        "a display program for.  If you specify the type/all "
                        "option you must have a program that can determine "
                        "the appropriate display subtype")
                (choices    "text/all"
                            "images/all"
                            "images/gif"
                            "images/jpeg"
                            "images/x-iff"
                            "audio/all"
                            "audio/basic"
                            "video/all"
                            "video/mpeg"))

        aem-curmailcap 0)

    (delete aem-mailcap_file)

    (while (<> 0 aem-mimetypes)
        ((if (BITAND aem-mimetypes 1)
            ((set
                aem-curmimet
                    (select aem-curmailcap "text/*"
                                           "images/*"
                                           "images/gif"
                                           "images/jpeg"
                                           "images/x-iff"
                                           "audio/*"
                                           "audio/basic"
                                           "video/*"
                                           "video/mpeg")

                aem-mimefile
                    (askfile
                        (prompt "Indicate program to display " aem-curmimet)
                        (help   "Select the program in the file list that will "
                                "be used the display the file described by the "
                                "indicated mime type/subtype")
                        (default ""))

                aem-mimefile
                    (askstring
                        (prompt "Add the parameters required for the mime "
                                "display program you selected\n\n"
                                "You must always add '%s' to specify where "
                                "the file you are displaying goes.\n")
                        (help   "You will need to add parmeters that may be "
                                "required by the display program that you "
                                "specified.  One required parameter required "
                                "by ALL programs is '%s' to specify where "
                                "the file name for the file you are "
                                "displaying goes.\n")
                        (default (cat aem-mimefile " %s")))

                aem-mimeonwb
                    (askbool
                        (prompt "Does the mime display program have to open "
                                "on the Workbench?"
                        (help   "Some programs will always open on the "
                                "Workbench.  Others will open on their own "
                                "screen.  If your display program opens on "
                                "the Workbench, you must reply 'YES' to this "
                                "request.\n")))

                aem-mimefile
                    (if (= 1 aem-mimeonwb)
                        (cat "WB;" aem-mimefile)
                        ("%s" aem-mimefile)))

            (textfile
                (prompt "Creating .mailcap file")
                (help   "Creating .mailcap file")
                (dest   aem-mailcap_file)
                (include aem-mailcap_file)
                (append ("%s; \"%s\"\n" aem-curmimet aem-mimefile)))))
        (set aem-curmailcap (+ 1 aem-curmailcap))
        (set aem-mimetypes (shiftright aem-mimetypes 1))

    )))
)

(set aem-existmailcap 0)

(if (= 2 @user-level)
    (set aem-existmailcap
        (askbool
            (prompt "\nDo you want to use an existing mailcap file used by "
                    "another program?\n\nIf you want to use the default "
                    "mailcap file that comes with AEMail, reply 'NO' to this "
                    "message.")
            (help   "AEMail can run with a mailcap file created for another "
                    "program.  If you reply 'YES' to this message you will "
                    "be prompted for the directory containing your mailcap "
                    "file and the MAILCAP= tool type will be set up in you "
                    "AEMail icon"))))

(if (= 1 aem-existmailcap)
    ((set aem-mailcapdir
        (askdir
            (prompt "Enter the drawer that contains your mailcap file")
            (help   "AEMail can run with a mailcap file created for another "
                    "program.  Enter the directory that contains the mailcap "
                    "file that you want and the MAILCAP= tool type will be set "
                    "up in you AEMail icon")
            (default aem-mail-dir)
            (newpath)))
    (if (= 1 (exists (tackon aem-mailcapdir "mailcap")(noreq)))
        (tooltype
            (prompt "Setting AEMail Tool Types")
            (dest (tackon @default-dest "AEMail"))
            (settooltype "MAILCAP_DIR" aem-mailcapdir))
        (message "A mailcap file does not exist in the directory you have "
                 "specified. Continuing assuming no existing mailcap file."))))

(if (< exec-version version_3_0)
    (if (= 2 @user-level)
        ((set
            aem-createmailcap
            (askbool
                (prompt "\nYou are running under AmigaDos 2.1.  Do you want "
                    "to create your own mailcap file?\n")
                (help   "AEMail is configured either by Tool Types in it's icon "
                    "or by a configuration screen which is automatically "
                    "called up when you first execute AEMail if the Tool "
                    "Type parameters were not given.  By replying "
                    "'Yes, Configure Now' you will be setting the Tool Type "
                    "parameters\n"))
            aem-mailcap_file (tackon aem-mail-dir "mailcap"))
        (if (= 1 aem-createmailcap)
            (aemp-build_mailcap))))
    (copyfiles
        (prompt "Copying mailcap to " aem-mail-dir)
	    (source (tackon source-dir "mailcap"))
	    (dest   aem-mail-dir))
)

(textfile
    (prompt "Creating ENV:AEMail_Dir")
    (help "Creating ENV:AEMail_Dir")
    (dest "ENV:AEMail_Dir")
    (append @default-dest))

(textfile
    (prompt "Creating ENVARC:AEMail_Dir")
    (help "Creating ENVARC:AEMail_Dir")
    (dest "ENVARC:AEMail_Dir")
    (append @default-dest))


(startup
    aem-name
        (prompt "Adding AEMAIL assign to S:User-Startup")
        (help   "An ASSIGN statement for AEMAIL will now be added to the S:User-Startup")
        (command ("ASSIGN %s \"%s\"\n" aem-assign aem-mail-dir))
        (command ("ASSIGN C: sys:REXXC ADD")))

(makeassign aem-name aem-mail-dir)

(set aem-copyold 0)
(if (= 1 (exists "AEMail:folder.config" (noreq)))
    (set aem-copyold
        (askbool
            (prompt "You have an existing folder.config file\n\n"
                "Do you want to save this file as folder.config.old?\n")
            (help "If you are installing over a version of AEMail prior to "
                "Version 1.40 you should reply YES to this prompt\n\n"
                "If you reinstall a version earlier than 1.40 you should "
                "rename folder.config.old to folder.config\n")
            (choices "Yes, save folder.config" "No, Ignore"))))

(if (= 1 aem-copyold)
    (copyfiles
        (prompt "Copying folder.config to folder.config.old")
        (source "AEMail:folder.config")
        (newname "folder.config.old")
        (dest "AEMail:")))

(set continue 0
     aem-regkey ""
     aem-regname aem-realname
     aem-aemr (tackon source-dir "AEMR"))

(if (= 1 (exists aem-aemr (noreq)))

    (while
        (= continue 0)

        (set
            aem-regkey
                (askstring
                    (prompt "You are installing a registered version of "
                            "AEMail.\n\n"
                            "Please enter the key code provided with your "
                            "copy of AEMail.")
                    (help   "You must enter your key code EXACTLY as provided "
                            "using the correct upper and lower cas letters.")
                    (default aem-regkey))

            aem-regname
                (askstring
                    (prompt "Please enter the name you want AEMail registered "
                            "under:")
                    (help   "You must enter a registered name\n\n"
                            "If you entered a 'real name' under the "
                            "configuration previously, it will be the default "
                            "registration name.  You can make any changes to ")
                    (default aem-regname))

            aem-regserno
                (run aem-aemr aem-regkey "\""aem-regname"\""))

        (if (> 100 aem-regserno)
            ((if (= 1 aem-regserno)
                ((message "You did not enter either a key or registration "
                         "name\n\nTry Again!")
                (set continue 0)))
            (if (= 2 aem-regserno)
                ((message "You entered an incorrect key code\n\nTry Again!")
                 (set continue 0)))
            (if (= 50 aem-regserno)
                ((message "Failed to create .registration file\n\n"
                          "AEMail: is probably not assigned.\n\n"
                          "Continuing as an unregistered version.  Contact "
                          "jzachar@calweb.com for further instructions.")
                 (set continue 1))))
            (set continue
                (askbool
                    (prompt "\nIs the following information correct?\n\n"
                            "registration name: " aem-regname "\n"
                            "    serial number: " aem-regserno "\n\n"
                            "If not, you can repeat the registration process")

                    (help   "Check the serial number with the number on the "
                            "provided information sheet.  If it or your "
                            "registration name or incorrect you can select "
                            "\"No, Enter Again\" or, if everything is all "
                            "right, select \"Yes, Repeat Registration\"\n")
                    (choices "Yes, Continue" "No, Repeat Registration"))))))


(message
    "\n\nThe installation of AEMail is now complete.  You can execute AEMail "
    "now by double clicking on it's icon without rebooting your system."
    "  The AEMAIL: assignment has been made and also has been placed in your "
    "S:User-Startup file.  Please read the AEMail.Readme file before "
    "executing AEMail.")

(set AEM-End
    (run pager-cmd "RAM:AEMfiles/AEMail.Readme" (safe)))

(delete
    "RAM:AEMfiles"
    (prompt "Deleting RAM: AEMail files")
    (optional "force")
    (safe)
    (infos)
    (all))

(exit)

