(FILECREATED " 7-Oct-86 20:57:21" {ERIS}<LAFITE>SOURCES>LAFITE.;14 90554  

      changes to:  (FNS RELEASE.LAFITE LAFITE \LAFITE.START.PROC LA.MENU.ITEM)
                   (VARS LAFITECOMS LAFITECOMMANDMENUITEMS LAFITESUBQUITMENUITEMS)

      previous date: " 6-May-86 17:19:54" {ERIS}<LAFITE>SOURCES>LAFITE.;12)


(* "
Copyright (c) 1982, 1983, 1984, 1985, 1986 by Xerox Corporation and Bolt Beranek and Newman Inc..  All rights reserved.
")

(PRETTYCOMPRINT LAFITECOMS)

(RPAQQ LAFITECOMS 
       [(COMS (E (SETQ LAFITESYSTEMDATE (DATE)))
              (VARS LAFITEVERSION# LAFITESYSTEMDATE))
        (COMS (FNS LAFITE \LAFITE.START.PROC LA.CREATE.UPDATE.MENUS \LAFITE.PROCESS 
                   \LAFITE.START.ABORT \LAFITE.QUIT \LAFITE.RESTART \LAFITE.SUBQUIT \LAFITE.QUIT.PROC 
                   \LAFITEDEFAULTHOST&DIR LAFITEDEFAULTHOST&DIR MAKELAFITECOMMANDWINDOW 
                   EXTRACTMENUCOMMAND DOMAINLAFITECOMMAND)
              (PROP ARGNAMES LAFITE)
              (FNS LAFITEMODE \LAFITE.INFER.MODE \LAFITE.SHOW.MODE \LAFITE.MODE.TITLE)
              (PROP VARTYPE LAFITEMODELST)
              (ADDVARS (LAFITEMODELST))
              (INITVARS (\LAFITEMODE)
                     (\LAFITE.AUTHENTICATION.FAILURE)))
        (INITVARS * LAFITEPROFILEVARS)
        (INITVARS * LAFITERANDOMGLOBALS)
        (VARS * LAFITEMARKS)
        (VARS LAFITECOMMANDMENUITEMS LAFITEUPDATEMENUITEMS LAFITECLOSEITEM LAFITEUPDATETOCITEM 
              LAFITECLOSELABELS ANOTHERFOLDERMENUITEM LAFITESUBQUITMENUITEMS)
        (INITVARS (LAFITESTATUSWINDOW)
               (\ACTIVELAFITEFOLDERS)
               (\LAFITEPROFILECHANGED)
               (\LAFITE.TEMPFILES)
               (LAFITEPRIMARYDISPLAYWINDOW)
               (LAFITEMAILFOLDERS)
               (LAFITEFOLDERSMENU)
               (LAFITEUPDATEMENUS)
               (\LAFITE.MODE.CHOICES)
               (LAFITESUBQUITMENU))
        (COMS (* ; "misc utilities")
              (FNS LA.RESETSHADE LA.MENU.ITEM LA.REMOVEDUPLICATES COLLECTOLDFILES LA.SETDIFFERENCE 
                   NTHMESSAGE \LAFITE.MAKE.MSGARRAY \LAFITE.ADDMESSAGES.TO.ARRAY))
        (COMS (* ; "Display aids")
              (CURSORS LA.CROSSCURSOR))
        (COMS (INITVARS (\LAFITE.ACTIVE)
                     (\LAFITE.READY)
                     (\LAFITEDEFAULTHOST&DIR)
                     (\LAFITEUSERDATA))
              (ADDVARS (\SYSTEMCACHEVARS \LAFITE.READY \LAFITEUSERDATA))
              (FNS LAFITE.AROUNDEXIT CHECKLAFITEMAILFOLDERS \LAFITE.REBROWSEFOLDER \LAFITE.AFTERLOGIN
                   ))
        (COMS (* ; "The profile")
              (FNS \LAFITE.WRITE.PROFILE \LAFITE.MERGE.PROFILES \LAFITE.READ.PROFILE PROFILEFILENAME)
              (INITVARS (\LAFITEPROFILEDATE))
              (GLOBALVARS LAFITEPROFILERDTBL LAFITEPROFILE.NAME LAFITEPROFILE.EXT \LAFITEPROFILEDATE)
              )
        (COMS (* ; "Low level file functions")
              (FNS DELETEMAILFOLDER FORGETMAILFILE \LAFITE.UNCACHE.FOLDER 
                   \LAFITE.UNCACHE.FOLDER.MULTIPLE \LAFITE.OPEN.FOLDER \LAFITE.OPENSTREAM 
                   \LAFITE.CREATE.MENU \LAFITE.EOF \LAFITE.CLOSE.FOLDER PROMPTFORFILENAME 
                   \LAFITE.PROMPTFORFOLDER MAKELAFITEMAILFOLDERSMENU MAILFOLDERBUSY LA.LONGFILENAME 
                   TOCFILENAME LA.SHORTFILENAME)
              (FNS COPY7BITFILE FIXLAURELFILE \LAFITE.BROWSE.LAURELFILE \LAFITE.NOTICE.FOLDERS 
                   \LAFITE.MAKE.RANDOM.DISPLAY \LAFITE.GC.FOLDERS \LAFITE.GC.FOLDERS.CONFIRM 
                   \LAFITE.FIX.LAUREL.FOLDER))
        [DECLARE: DOEVAL@COMPILE DONTCOPY (FILES (SOURCE)
                                                 LAFITEDECLS)
               (COMS (FNS RELEASE.LAFITE)
                     (ADDVARS (DONTCOMPILEFNS RELEASE.LAFITE]
        (INITRECORDS MAILFOLDER LAFITEMSG)
        (SYSRECORDS MAILFOLDER LAFITEMSG)
        [COMS (FNS \LAFITE.GLOBAL.INIT)
              (DECLARE: DONTEVAL@LOAD DOCOPY (FILES LAFITEBROWSE LAFITESEND LAFITEMAIL TEDIT 
                                                    ATTACHEDWINDOW)
                     (P (\LAFITE.GLOBAL.INIT]
        (DECLARE: DOEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA)
                                                                          (NLAML)
                                                                          (LAMA LAFITE])

(RPAQQ LAFITEVERSION# 9)

(RPAQQ LAFITESYSTEMDATE " 7-Oct-86 20:57:23")
(DEFINEQ

(LAFITE
  [LAMBDA X                                                  (* bvm: " 7-Oct-86 16:48")
                                                  (* ;;; "The first argument should be ON or OFF.  The second argument, if supplied, is the name of the mailfile Lafite should browse unless the second argument is NIL in which case no mailfile will be browsed.  If there is no second argument then default to DEFAULTMAILFOLDERNAME mailfile -- currently ACTIVE")
    (SELECTQ (COND
                ((ILESSP X 1)                                (* ; "Lafite called with no args")
                 (QUOTE ON))
                (T (ARG X 1)))
        ((ON on) 
             (COND
                (\LAFITE.ACTIVE (TOTOPW LAFITESTATUSWINDOW)
                       (QUOTE ON))
                ((NOT (THIS.PROCESS))
                 "No Processes!")
                (T (COND
                      ((NOT (WINDOWP LAFITESTATUSWINDOW))
                       (MAKELAFITECOMMANDWINDOW)))
                   (PRINTLAFITESTATUS "Initializing")
                   (SETQ \LAFITE.ACTIVE (QUOTE INIT))
                   (\LAFITE.PROCESS [LIST (FUNCTION \LAFITE.START.PROC)
                                          [KWOTE (COND
                                                    ((ILEQ X 1)
                                                     DEFAULTMAILFOLDERNAME)
                                                    (T (ARG X 2]
                                          (KWOTE (for I from 3 to X collect (ARG X I]
                          (QUOTE LAFITE))
                   (QUOTE ON))))
        ((OFF off RESTART) 
             (COND
                (\LAFITE.ACTIVE                              (* ; "Lafite was on")
                       [COND
                          ((EQ \LAFITE.ACTIVE (QUOTE INIT))  (* ; "Zap the initializer")
                           (DEL.PROCESS (QUOTE LAFITE]
                       (\LAFITE.QUIT.PROC (LA.MENU.ITEM (FUNCTION \LAFITE.QUIT)
                                                 LAFITEMAINMENU)
                              (ASSOC (QUOTE Quit)
                                     LAFITECOMMANDMENUITEMS)
                              LAFITEMAINMENU)))
             (COND
                [(EQ (ARG X 1)
                     (QUOTE RESTART))
                 (APPLY (FUNCTION LAFITE)
                        (CONS (QUOTE ON)
                              (for I from 2 to X collect (ARG X I]
                (T (QUOTE OFF))))
        (LISPERROR "ILLEGAL ARG" (ARG X 1])

(\LAFITE.START.PROC
  [LAMBDA (MAILFILE OPTIONS)                                 (* bvm: " 7-Oct-86 16:49")
    (RESETSAVE NIL (LIST (FUNCTION \LAFITE.START.ABORT)))
    (\LAFITEDEFAULTHOST&DIR (OR LAFITEDEFAULTHOST&DIR LOGINHOST/DIR))
    (SETQ \LAFITE.BROWSELOCK (CREATE.MONITORLOCK "Lafite Browser Control"))
                                                  (* ; 
       "Used by anyone creating browsers or otherwise concerned with changes to \ACTIVELAFITEFOLDERS")
    (SETQ \LAFITE.MAINLOCK (CREATE.MONITORLOCK "Lafite Main"))
                                                  (* ; 
       "Used by \LAFITE.CLOSE.OTHER.FOLDERS or anyone who needs access to multiple arbitrary folders")
    (SETQ \LAFITE.PROFILELOCK (CREATE.MONITORLOCK "Lafite Profile"))
    (SETQ \LAFITE.HARDCOPYLOCK (CREATE.MONITORLOCK "Lafite hardcopy"))
                                                  (* ; 
                                               "Used by anyone reading or writing the Lafite profile")
    (SETQ LAFITEMAILFOLDERS (SETQ LAFITEFORMFILES NIL))
    (\LAFITE.READ.PROFILE)
    (SETQ LAFITEUPDATEMENUS (CONS (LA.CREATE.UPDATE.MENUS LAFITEUPDATEMENUITEMS NIL NIL 
                                         "Update Options")
                                  (LA.CREATE.UPDATE.MENUS LAFITEUPDATEMENUITEMS LAFITECLOSELABELS 
                                         LAFITECLOSEITEM "Close/Shrink Options")))
    (SETQ \LAFITE.READY T)
    (pushnew \AFTERLOGINFNS (FUNCTION \LAFITE.AFTERLOGIN))
    (pushnew AROUNDEXITFNS (FUNCTION LAFITE.AROUNDEXIT))
    (SETQ \LAFITE.ACTIVE T)
    (NLSETQ (WITH.MONITOR \LAFITE.MAILSERVERLOCK (\LAFITE.GET.USER.DATA)))
                                                  (* ;; "Authenticate user first, so that MSGFROMMEP works.  NLSETQ so that errors and/or ↑ from break do not leave Lafite in inconsistent state")
    (ADD.PROCESS (CONSTANT (LIST (FUNCTION LAFITEMAILWATCH)))
           (QUOTE RESTARTABLE)
           (QUOTE HARDRESET)
           (QUOTE AFTEREXIT)
           (QUOTE SUSPEND))
    [COND
       ((OR MAILFILE (AND (EQMEMB (QUOTE SHRINK)
                                 OPTIONS)
                          (SETQ MAILFILE DEFAULTMAILFOLDERNAME)))
        (\LAFITE.BROWSE (LA.MENU.ITEM (FUNCTION \LAFITE.BROWSE)
                               LAFITEMAINMENU)
               LAFITEMAINMENU NIL MAILFILE (CONS (QUOTE NOCONFIRM)
                                                 (MKLIST OPTIONS]
                                                             (* ; "Finally, enable menu")
    (replace (MENU WHENSELECTEDFN) of LAFITEMAINMENU with (FUNCTION DOMAINLAFITECOMMAND])

(LA.CREATE.UPDATE.MENUS
  [LAMBDA (MENUITEMS LASTLABELS LASTITEM TITLE)              (* bvm: "29-May-84 15:09")
    (PROG (OTHERMENUS)
          [COND
             (MENUITEMS (SETQ OTHERMENUS (LA.CREATE.UPDATE.MENUS (CDR MENUITEMS)
                                                (CDR LASTLABELS)
                                                LASTITEM TITLE)))
             (T (SETQ MENUITEMS (LIST LAFITEUPDATETOCITEM]
          (RETURN (CONS (\LAFITE.CREATE.MENU (COND
                                                [LASTITEM (APPEND MENUITEMS
                                                                 (LIST (CONS (CAR LASTLABELS)
                                                                             (CDR LASTITEM]
                                                (T MENUITEMS))
                               TITLE)
                        OTHERMENUS])

(\LAFITE.PROCESS
  [LAMBDA (FORM NAME ALLOWLOGOUT RESTARTABLE)                (* bvm: "25-Mar-84 17:16")
          
          (* * Creates a process running FORM which by default is not restartable and 
          will not permit LOGOUT while it is running)

    (ADD.PROCESS FORM (QUOTE NAME)
           NAME
           (QUOTE RESTARTABLE)
           (OR RESTARTABLE (QUOTE NO))
           (QUOTE BEFOREEXIT)
           (COND
              (ALLOWLOGOUT NIL)
              (T (QUOTE DON'T])

(\LAFITE.START.ABORT
  [LAMBDA NIL                                                (* bvm: "25-Mar-84 16:44")
    (COND
       ((AND RESETSTATE (NEQ \LAFITE.ACTIVE T))
        (CLOSEW LAFITESTATUSWINDOW)
        (SETQ LAFITESTATUSWINDOW (SETQ \LAFITE.ACTIVE])

(\LAFITE.QUIT
  [LAMBDA (ITEM MENU BUTTON)                                 (* bvm: " 7-Nov-84 11:48")
    (COND
       ((EQ BUTTON (QUOTE MIDDLE))
        (\LAFITE.SUBQUIT ITEM MENU))
       (T (\LAFITE.PROCESS (LIST (FUNCTION \LAFITE.QUIT.PROC)
                                 (KWOTE ITEM)
                                 (KWOTE MENU))
                 (QUOTE LAFITEQUIT])

(\LAFITE.RESTART
  [LAMBDA (ITEM MENU)                                        (* bvm: " 7-Nov-84 11:56")
    (COND
       ((\LAFITE.QUIT.PROC ITEM MENU)
        (LAFITE (QUOTE ON)
               NIL])

(\LAFITE.SUBQUIT
  [LAMBDA (ITEM MENU)                                        (* bvm: " 7-Nov-84 11:58")
    (PROG ((MODES (for MODE in LAFITEMODELST when (LISTP (CDR MODE))
                     collect (LIST (CONCAT (CAR MODE)
                                          " Mode")
                                   (KWOTE (LIST (CAR MODE)))
                                   "Change to this mode of mail sending/retrieving")))
           COMMAND)
          (COND
             ((NOT (EQUAL \LAFITE.MODE.CHOICES (SETQ \LAFITE.MODE.CHOICES MODES)))
                                                             (* Recompute menu)
              (SETQ LAFITESUBQUITMENU)))
          (COND
             ([LISTP (SETQ COMMAND (MENU (.LAFITEMENU. LAFITESUBQUITMENU (APPEND 
                                                                               LAFITESUBQUITMENUITEMS 
                                                                                MODES)
                                                "Mode Change"]
              (LAFITEMODE (CAR COMMAND)))
             (COMMAND (\LAFITE.PROCESS (LIST COMMAND (KWOTE ITEM)
                                             (KWOTE MENU))
                             (QUOTE LAFITEQUIT])

(\LAFITE.QUIT.PROC
  [LAMBDA (ITEM MENU)                                        (* bvm: " 5-May-86 16:59")
    (RESETLST (LA.RESETSHADE ITEM MENU)
           (OBTAIN.MONITORLOCK \LAFITE.BROWSELOCK NIL T)
           (OBTAIN.MONITORLOCK \LAFITE.MAINLOCK NIL T)
           (PROG ((HOW? 5)
                  MENUREG)
                 (OR \LAFITE.ACTIVE (RETURN T))
                 (COND
                    ([for WINDOW in LAFITEEDITORWINDOWS when (WINDOWP WINDOW)
                        do (COND
                              ((OPENWP WINDOW)
                               (SETQ $$VAL (TOTOPW WINDOW)))
                              ([WINDOWP (SETQ WINDOW (WINDOWPROP WINDOW (QUOTE ICONWINDOW]
                               (SETQ $$VAL (EXPANDW WINDOW]
                     (printout PROMPTWINDOW T 
                            "There are open/undelivered message composition windows -- can't quit")
                     (RETURN)))
                 [for FOLDER in \ACTIVELAFITEFOLDERS bind LEVEL when (fetch (MAILFOLDER BROWSERWINDOW
                                                                                   ) of FOLDER)
                    do 
          
          (* * Determine what to do with open browsers.
          Essentially same as the CLOSEFN for a browser, but we offer a single menu that 
          offers all the choices that the most particular window might need)

                       (COND
                          ((ILESSP (SETQ LEVEL (COND
                                                  ((fetch (MAILFOLDER HARDCOPYSTREAM) of FOLDER)
                                                   1)
                                                  ((fetch (MAILFOLDER FOLDERNEEDSUPDATE) of FOLDER)
                                                   2)
                                                  ((fetch (MAILFOLDER FOLDERNEEDSEXPUNGE)
                                                      of FOLDER)
                                                   3)
                                                  ((NEQ (fetch (MAILFOLDER #OFMESSAGES) of FOLDER)
                                                        (fetch (MAILFOLDER TOCLASTMESSAGE#)
                                                           of FOLDER))
                                                   4)
                                                  (T 5)))
                                  HOW?)
                           (SETQ HOW? LEVEL]
                 [COND
                    [(SETQ HOW? (CAR (NTH (CDR LAFITEUPDATEMENUS)
                                          HOW?)))
                     (SETQ HOW? (\LAFITE.CREATE.MENU [APPEND (fetch (MENU ITEMS) of HOW?)
                                                            (QUOTE (("Don't Quit" NIL 
                                                                           "Abort the Quit command"]
                                       "How should browsers be closed?"))
                     (SETQ MENUREG (WINDOWPROP (WFROMMENU MENU)
                                          (QUOTE REGION)))
                     (SETQ HOW? (OR (MENU HOW? (create POSITION
                                                      XCOORD ← (IDIFFERENCE (fetch (REGION RIGHT)
                                                                               of MENUREG)
                                                                      (fetch (MENU IMAGEWIDTH)
                                                                         of HOW?))
                                                      YCOORD ← (IDIFFERENCE (fetch (REGION BOTTOM)
                                                                               of MENUREG)
                                                                      (fetch (MENU IMAGEHEIGHT)
                                                                         of HOW?)))
                                          T)
                                    (RETURN]
                    (T (SETQ HOW? (FUNCTION \LAFITE.FINISH.UPDATE]
                 [for FOLDER in (APPEND \ACTIVELAFITEFOLDERS) bind BROWSERWINDOW
                    do (COND
                          ((NOT (SETQ BROWSERWINDOW (fetch (MAILFOLDER BROWSERWINDOW) of FOLDER)))
                           (\LAFITE.CLOSE.FOLDER FOLDER T))
                          (T (APPLY* HOW? BROWSERWINDOW FOLDER (QUOTE CLOSE]
                 (SETQ \ACTIVELAFITEFOLDERS)
                 (PROGN [for WINDOW in LAFITEEDITORWINDOWS
                           do                                (* now close the edit and display 
                                                             windows *)
                              (COND
                                 ((WINDOWP WINDOW)
                                  (COND
                                     ((OPENWP WINDOW)
                                      (CLOSEW WINDOW))
                                     ([WINDOWP (SETQ WINDOW (WINDOWPROP WINDOW (QUOTE ICONWINDOW]
                                      (CLOSEW WINDOW]
                        (SETQ LAFITEEDITORWINDOWS NIL))
                 (AND \LAFITE.OUTBOX (CLOSEW (fetch OBWINDOW of \LAFITE.OUTBOX)))
                 (COND
                    (\LAFITEPROFILECHANGED (\LAFITE.WRITE.PROFILE)))
                 (SETQ AROUNDEXITFNS (REMOVE (FUNCTION LAFITE.AROUNDEXIT)
                                            AROUNDEXITFNS))
                 (SETQ \AFTERLOGINFNS (REMOVE (QUOTE \LAFITE.AFTERLOGIN)
                                             \AFTERLOGINFNS))
                 (PROGN (for FILE in \LAFITE.TEMPFILES do    (* delete any temp files laying around 
                                                             *)
                                                          (CLOSEF? FILE)
                                                          (DELFILE FILE))
                        (SETQ \LAFITE.TEMPFILES))
                 (SETQ \LAFITE.ACTIVE NIL)
                 (DEL.PROCESS (FUNCTION LAFITEMAILWATCH))
                 (LAFITECLEARCACHE)
                 (COND
                    ((OPENWP LAFITESTATUSWINDOW)
                     (CLOSEW LAFITESTATUSWINDOW)))
                 [SETQ LAFITESUBQUITMENU (SETQ \LAFITE.MODE.CHOICES (SETQ LAFITEFORMATMENU
                                                                     (SETQ LAFITEFOLDERSMENU
                                                                      (SETQ LAFITEFORMSMENU
                                                                       (SETQ LAFITEFORMFILES
                                                                        (SETQ \LAFITE.LAST.STATUS
                                                                         (SETQ 
                                                                          LAFITEPRIMARYDISPLAYWINDOW
                                                                          (SETQ 
                                                                           \LAFITEDEFAULTHOST&DIR
                                                                           (SETQ LAFITEUPDATEMENUS
                                                                            (SETQ LAFITEMAINMENU
                                                                             (SETQ LAFITESTATUSWINDOW 
                                                                              NIL]
                 (RETURN T])

(\LAFITEDEFAULTHOST&DIR
  [LAMBDA (HOST&DIR)                                         (* bvm: " 5-May-86 16:56")
    (PROG ((OLDHOST&DIR (fetch PACKEDHOST&DIR of \LAFITEDEFAULTHOST&DIR))
           UNPACKED)
          (COND
             ((OR (NULL HOST&DIR)
                  (STRING-EQUAL OLDHOST&DIR HOST&DIR))       (* User wants the value, or there is 
                                                             no change)
              (RETURN HOST&DIR)))                            (* now make sure its a legitimate 
                                                             HOST&DIR *)
          (COND
             ((NOT (HOSTNAMEP HOST&DIR))
              (printout PROMPTWINDOW T "Warning: " HOST&DIR " not a recognized directory")))
                                                             (* set both the visible and invisble 
                                                             variables *)
          (SETQ UNPACKED (UNPACKFILENAME.STRING HOST&DIR))
          (SETQ \LAFITEDEFAULTHOST&DIR (create DEFAULTHOST&DIR
                                              PACKEDHOST&DIR ← (PACKFILENAME UNPACKED)
                                              UNPACKEDHOST&DIR ← UNPACKED))
                                                             (* reset all the appropriate menus *)
          (SETQ LAFITEFOLDERSMENU (SETQ LAFITEFORMSMENU))
          (RETURN OLDHOST&DIR])

(LAFITEDEFAULTHOST&DIR
  [LAMBDA (HOST&DIR)                                         (* bvm: "22-Feb-84 16:27")
          
          (* * Temporary definition until we can do it right)

    (SETQ LAFITEDEFAULTHOST&DIR HOST&DIR])

(MAKELAFITECOMMANDWINDOW
  [LAMBDA NIL                                                (* bvm: " 5-May-86 16:23")
    (PROG ((FONTHEIGHT (FONTPROP LAFITEMENUFONT (QUOTE HEIGHT)))
           MENUW MENUWREGION POSITION HEIGHT WIDTH STATUSWINDOW)
          [SETQ MENUW (MENUWINDOW (SETQ LAFITEMAINMENU (create MENU
                                                              ITEMS ← LAFITECOMMANDMENUITEMS
                                                              WHENSELECTEDFN ← (FUNCTION NILL)
                                                              CENTERFLG ← T
                                                              TITLE ← (OR (\LAFITE.MODE.TITLE)
                                                                          "L a f i t e")
                                                              MENUFONT ← LAFITEMENUFONT
                                                              MENUTITLEFONT ← LAFITETITLEFONT]
          (SETQ WIDTH (IMAX [fetch (REGION WIDTH) of (SETQ MENUWREGION (WINDOWPROP MENUW (QUOTE
                                                                                          REGION]
                            LAFITESTATUSWINDOWMINWIDTH))
          [SETQ HEIGHT (HEIGHTIFWINDOW (FIX (FTIMES FONTHEIGHT 1.5]
          (SETQ POSITION (OR LAFITESTATUSWINDOWPOSITION (GETBOXPOSITION WIDTH
                                                               (IPLUS HEIGHT (fetch (REGION HEIGHT)
                                                                                of MENUWREGION))
                                                               NIL NIL NIL 
                                                       "Specify position of the Lafite Command Menu."
                                                               )))
          [SETQ STATUSWINDOW (CREATEW (MAKEWITHINREGION (create REGION
                                                               LEFT ← (fetch (POSITION XCOORD)
                                                                         of POSITION)
                                                               BOTTOM ← (IPLUS (fetch (POSITION
                                                                                       YCOORD)
                                                                                  of POSITION)
                                                                               (fetch (REGION HEIGHT)
                                                                                  of MENUWREGION))
                                                               WIDTH ← WIDTH
                                                               HEIGHT ← HEIGHT]
          (DSPFONT LAFITEMENUFONT STATUSWINDOW)
          (ATTACHWINDOW MENUW STATUSWINDOW (QUOTE BOTTOM))
          [WINDOWPROP STATUSWINDOW (QUOTE BUTTONEVENTFN)
                 (FUNCTION (LAMBDA (WINDOW)
                             (COND
                                ((LASTMOUSESTATE (NOT UP))
                                 (SETQ \LAFITE.LAST.STATUS)
                                 (\LAFITE.WAKE.WATCHER]
          (WINDOWPROP STATUSWINDOW (QUOTE MAINWINDOWMINSIZE)
                 (CONS 0 HEIGHT))
          (WINDOWPROP STATUSWINDOW (QUOTE MAINWINDOWMAXSIZE)
                 (CONS MAX.SMALLP HEIGHT))
          (OPENW STATUSWINDOW)
          (CLEARW STATUSWINDOW)
          [WINDOWPROP STATUSWINDOW (QUOTE YPOS)
                 (IDIFFERENCE (DSPYPOSITION NIL STATUSWINDOW)
                        (FIXR (FTIMES FONTHEIGHT .2]
          (RETURN (SETQ LAFITESTATUSWINDOW STATUSWINDOW])

(EXTRACTMENUCOMMAND
  [LAMBDA (ITEM)                                             (* DECLARATIONS: (RECORD
                                                             (LABEL FORM HELPSTRING)))
                                                             (* mdy: "20-OCT-82 15:07")
    (COND
       ((NLISTP ITEM)
        ITEM)
       ((fetch FORM of ITEM)
        (EVAL (fetch FORM of ITEM)))
       (T (fetch LABEL of ITEM])

(DOMAINLAFITECOMMAND
  [LAMBDA (ITEM MENU BUTTON)                                 (* bvm: " 5-Nov-84 16:50")
    (APPLY* (EXTRACTMENUCOMMAND ITEM)
           ITEM MENU BUTTON])
)

(PUTPROPS LAFITE ARGNAMES (NIL (ON/OFF MAILFILE . OPTIONS) . U))
(DEFINEQ

(LAFITEMODE
  [LAMBDA (MODE)                                             (* bvm: "21-Dec-84 22:09")
    (PROG1 (fetch LAFITEMODE of \LAFITEMODE)
           (COND
              (MODE (while [LITATOM (CDR (SETQ MODE (OR (ASSOC MODE LAFITEMODELST)
                                                        (\ILLEGAL.ARG MODE]
                       do (SETQ MODE (CDR MODE)))
                    (COND
                       ((NEQ (fetch LAFITEMODE of \LAFITEMODE)
                             (fetch LAFITEMODE of (SETQ \LAFITEMODE MODE)))
                                                             (* Mode changed, kick mailwatcher)
                        (COND
                           (\LAFITE.ACTIVE (\LAFITE.SHOW.MODE)
                                  (WITH.MONITOR \LAFITE.MAILSERVERLOCK (SETQ \LAFITEUSERDATA)
                                         (PRINTLAFITESTATUS "Reinitializing")
                                         (\LAFITE.WAKE.WATCHER])

(\LAFITE.INFER.MODE
  [LAMBDA NIL                                                (* bvm: "21-Dec-84 22:43")
    (COND
       ([SETQ \LAFITEMODE (OR (AND LAFITEMODEDEFAULT (ASSOC LAFITEMODEDEFAULT LAFITEMODELST))
                              (PROG [(CHOICES (for X in LAFITEMODELST collect X
                                                 when (LISTP (CDR X]
                                    (RETURN (AND CHOICES (NULL (CDR CHOICES))
                                                 (CAR CHOICES]
        (AND LAFITESTATUSWINDOW (\LAFITE.SHOW.MODE))
        \LAFITEMODE])

(\LAFITE.SHOW.MODE
  [LAMBDA NIL                                                (* bvm: "30-Oct-84 16:53")
    (PROG ((TITLE (\LAFITE.MODE.TITLE))
           (MENU LAFITEMAINMENU))
          (COND
             (TITLE (replace (MENU TITLE) of MENU with TITLE)
                    (UPDATE/MENU/IMAGE MENU)
                    (REDISPLAYW (WFROMMENU MENU])

(\LAFITE.MODE.TITLE
  [LAMBDA NIL                                                (* bvm: "12-Nov-84 17:03")
          
          (* * If user wants mode shown in Lafite status window, this returns a suitable 
          title for that window)

    (AND \LAFITEMODE [SELECTQ LAFITESHOWMODEFLG
                         (ALWAYS T)
                         (NIL NIL)
                         (CDR (for X in LAFITEMODELST collect X
                                 when (LISTP (CDR (LISTP X]
         (CONCAT "L a f i t e  (" (fetch LAFITEMODE of \LAFITEMODE)
                ")"])
)

(PUTPROPS LAFITEMODELST VARTYPE ALIST)

(ADDTOVAR LAFITEMODELST )

(RPAQ? \LAFITEMODE )

(RPAQ? \LAFITE.AUTHENTICATION.FAILURE )

(RPAQQ LAFITEPROFILEVARS ((LAFITEDEFAULTHOST&DIR)
                          (LAFITEBUFFERSIZE 20)
                          (LAFITEIFFROMMETHENSEENFLG T)
                          [LAFITEMENUFONT (FONTCREATE (QUOTE (HELVETICA 10 BOLD]
                          [LAFITETITLEFONT (FONTCREATE (QUOTE (HELVETICA 12 BOLD]
                          [LAFITEDISPLAYFONT (FONTCREATE (QUOTE (TIMESROMAN 10]
                          (LAFITEHARDCOPYFONT LAFITEDISPLAYFONT)
                          [LAFITEBROWSERFONT (FONTCREATE (QUOTE (GACHA 10]
                          [LAFITEMSGICONFONT (FONTCREATE (QUOTE (HELVETICA 8]
                          (LAFITEPROFILE.NAME (QUOTE LAFITE))
                          (LAFITEPROFILE.EXT (QUOTE PROFILE))
                          (DEFAULTMAILFOLDERNAME (QUOTE ACTIVE.MAIL))
                          (LAFITEMAIL.EXT (QUOTE MAIL))
                          (LAFITESTATUSWINDOWMINWIDTH 200)
                          (LAFITESTATUSWINDOWPOSITION (create POSITION XCOORD ← 735 YCOORD ← 650))
                          (LAFITEDEBUGFLG)
                          (LAFITEMODEDEFAULT)
                          (LAFITESHOWMODEFLG T)))

(RPAQ? LAFITEDEFAULTHOST&DIR )

(RPAQ? LAFITEBUFFERSIZE 20)

(RPAQ? LAFITEIFFROMMETHENSEENFLG T)

(RPAQ? LAFITEMENUFONT (FONTCREATE (QUOTE (HELVETICA 10 BOLD))))

(RPAQ? LAFITETITLEFONT (FONTCREATE (QUOTE (HELVETICA 12 BOLD))))

(RPAQ? LAFITEDISPLAYFONT (FONTCREATE (QUOTE (TIMESROMAN 10))))

(RPAQ? LAFITEHARDCOPYFONT LAFITEDISPLAYFONT)

(RPAQ? LAFITEBROWSERFONT (FONTCREATE (QUOTE (GACHA 10))))

(RPAQ? LAFITEMSGICONFONT (FONTCREATE (QUOTE (HELVETICA 8))))

(RPAQ? LAFITEPROFILE.NAME (QUOTE LAFITE))

(RPAQ? LAFITEPROFILE.EXT (QUOTE PROFILE))

(RPAQ? DEFAULTMAILFOLDERNAME (QUOTE ACTIVE.MAIL))

(RPAQ? LAFITEMAIL.EXT (QUOTE MAIL))

(RPAQ? LAFITESTATUSWINDOWMINWIDTH 200)

(RPAQ? LAFITESTATUSWINDOWPOSITION (create POSITION XCOORD ← 735 YCOORD ← 650))

(RPAQ? LAFITEDEBUGFLG )

(RPAQ? LAFITEMODEDEFAULT )

(RPAQ? LAFITESHOWMODEFLG T)

(RPAQQ LAFITERANDOMGLOBALS ((UNSUPPLIEDFIELDSTR "---")
                            (LAFITEBUSYWAITTIME 1000)
                            (LAFITEITEMBUSYSHADE 43605)
                            (LAFITEEOL "
")))

(RPAQ? UNSUPPLIEDFIELDSTR "---")

(RPAQ? LAFITEBUSYWAITTIME 1000)

(RPAQ? LAFITEITEMBUSYSHADE 43605)

(RPAQ? LAFITEEOL "
")

(RPAQQ LAFITEMARKS ((SEENMARK (CHARCODE SP))
                    (UNSEENMARK (CHARCODE ?))
                    (MOVETOMARK (CHARCODE m))
                    (FORWARDMARK (CHARCODE f))
                    (ANSWERMARK (CHARCODE a))
                    (HARDCOPYBATCHMARK (CHARCODE H))
                    (HARDCOPYMARK (CHARCODE h))
                    (HEARDMARK (CHARCODE @))))

(RPAQ SEENMARK (CHARCODE SP))

(RPAQ UNSEENMARK (CHARCODE ?))

(RPAQ MOVETOMARK (CHARCODE m))

(RPAQ FORWARDMARK (CHARCODE f))

(RPAQ ANSWERMARK (CHARCODE a))

(RPAQ HARDCOPYBATCHMARK (CHARCODE H))

(RPAQ HARDCOPYMARK (CHARCODE h))

(RPAQ HEARDMARK (CHARCODE @))

(RPAQQ LAFITECOMMANDMENUITEMS (("Browse" (QUOTE \LAFITE.BROWSE)
                                      "Browse a mail file; MIDDLE for subcommands")
                               ("Send Mail" (QUOTE \LAFITE.MESSAGEFORM)
                                      "Open a message composition window; MIDDLE for choice of forms"
                                      )
                               ("Quit" (QUOTE \LAFITE.QUIT)
                                      "Update and close all mail files and stop Lafite")))

(RPAQQ LAFITEUPDATEMENUITEMS (("Do Hardcopy Only" (QUOTE \LAFITE.HARDCOPYONLY.PROC)
                                     "Will print batched hardcopy but not update file")
                              ("Write out changes only" (QUOTE \LAFITE.UPDATE.PROC)
                                     "Will update physical file to reflect new marks and deletions")
                              ("Expunge deleted messages" (QUOTE \LAFITE.EXPUNGE.PROC)
                                     "Will rewrite mail file, expunging all deleted messages")))

(RPAQQ LAFITECLOSEITEM ("Don't update file" (QUOTE \LAFITE.FINISH.UPDATE)
                              "Just close/shrink the window - don't update it."))

(RPAQQ LAFITEUPDATETOCITEM ("Update table of contents" (FUNCTION \LAFITE.UPDATE.PROC)
                                  "Write table of contents file to speed next browse of this folder"))

(RPAQQ LAFITECLOSELABELS ("Don't Update or Hardcopy" "Don't update file" "Don't expunge file" 
                                "Just close"))

(RPAQQ ANOTHERFOLDERMENUITEM ("** Other Folder **" (QUOTE ##ANOTHERFILE##)
                                    "You will be asked to specify another mail filename"))

(RPAQQ LAFITESUBQUITMENUITEMS (("Quit" (QUOTE \LAFITE.QUIT)
                                      "Turn Lafite off")
                               ("Restart" (QUOTE \LAFITE.RESTART)
                                      "Turn Lafite off then back on")))

(RPAQ? LAFITESTATUSWINDOW )

(RPAQ? \ACTIVELAFITEFOLDERS )

(RPAQ? \LAFITEPROFILECHANGED )

(RPAQ? \LAFITE.TEMPFILES )

(RPAQ? LAFITEPRIMARYDISPLAYWINDOW )

(RPAQ? LAFITEMAILFOLDERS )

(RPAQ? LAFITEFOLDERSMENU )

(RPAQ? LAFITEUPDATEMENUS )

(RPAQ? \LAFITE.MODE.CHOICES )

(RPAQ? LAFITESUBQUITMENU )



(* ; "misc utilities")

(DEFINEQ

(LA.RESETSHADE
  [LAMBDA (ITEM MENU OLDSHADE)                               (* bvm: " 2-Mar-84 11:43")
          
          (* * Shades ITEM in MENU to indicate Lafite is busy, leaves something on 
          resetlst to unshade it)

    (RESETSAVE (SHADEITEM ITEM MENU LAFITEITEMBUSYSHADE)
           (LIST (FUNCTION SHADEITEM)
                 ITEM MENU (OR OLDSHADE WHITESHADE])

(LA.MENU.ITEM
  [LAMBDA (FN MENU)                                          (* bvm: " 7-Oct-86 16:46")
                                                  (* ;; "Returns the menu item executed by FN in MENU.  This beats searching by the label because someone might want to change the label.  Menu items are assumed to be of the form (label 'fn --)")
    (find ITEM in (fetch (MENU ITEMS) of MENU) suchthat (EQ FN (CADR (LISTP (CADR ITEM])

(LA.REMOVEDUPLICATES
  [LAMBDA (LST)                                              (* bvm: " 9-Dec-85 17:03")
          
          (* * a case-independent intersection of LST and LST * *)

    (for X in LST bind RESULT unless (for GOOD in RESULT thereis (STRING-EQUAL X GOOD))
       do                                                    (* Collect only if we haven't seen 
                                                             this name before)
          (push RESULT X) finally (RETURN (COND
                                             ((CDR RESULT)
                                              (REVERSE RESULT))
                                             (T RESULT])

(COLLECTOLDFILES
  [LAMBDA (FILES EXT)                                        (* bvm: " 6-Jan-84 11:05")
    (for FILE in FILES when (AND FILE (INFILEP (LA.LONGFILENAME FILE EXT))) collect 
                                                             (* use only those mail files that do 
                                                             exist *)
                                                                                  FILE])

(LA.SETDIFFERENCE
  [LAMBDA (X Y)                                              (* bvm: " 9-Dec-85 17:03")
          
          (* * Returns subset of X not in Y, case-independently)

    (for ELT in X collect ELT unless (for OTHER in Y thereis (STRING-EQUAL ELT OTHER])

(NTHMESSAGE
  [LAMBDA (MESSAGES N)                                       (* bvm: " 3-Jan-84 12:11")
    (ELT MESSAGES N])

(\LAFITE.MAKE.MSGARRAY
  [LAMBDA (SIZE OLDARRAY OLDSIZE)                            (* bvm: " 3-Jan-84 11:07")
          
          (* * Creates an array at least large enough to hold SIZE message descriptors.
          If OLDARRAY is given, its elements up to OLDSIZE are copied into the new array)

    (PROG [(NEWARRAY (ARRAY (IMAX (IPLUS SIZE 32)
                                  (CEIL SIZE 64))
                            (QUOTE POINTER]
          [COND
             (OLDARRAY (for I from 1 to OLDSIZE do (SETA NEWARRAY I (ELT OLDARRAY I]
          (RETURN NEWARRAY])

(\LAFITE.ADDMESSAGES.TO.ARRAY
  [LAMBDA (MSGARRAY MESSAGELIST FIRSTMSG# LASTMSG#)          (* bvm: " 3-Jan-84 11:26")
          
          (* * Adds to MSGARRAY the messages from MESSAGELIST, which should be numbered 
          FIRSTMSG# thru LASTMSG# -
          returns a new array if MSGARRAY wasn't large enough)

    [COND
       ((OR (NULL MSGARRAY)
            (IGREATERP LASTMSG# (ARRAYSIZE MSGARRAY)))
        (SETQ MSGARRAY (\LAFITE.MAKE.MSGARRAY LASTMSG# MSGARRAY (SUB1 FIRSTMSG#]
    (COND
       ((NEQ (fetch (LAFITEMSG #) of (CAR MESSAGELIST))
             FIRSTMSG#)
        (SHOULDNT)))
    (for MSG in MESSAGELIST as MSG# from FIRSTMSG# do (SETA MSGARRAY MSG# MSG))
    MSGARRAY])
)



(* ; "Display aids")

(RPAQ LA.CROSSCURSOR (CURSORCREATE (READBITMAP) NIL 8 8))
(16 16
"L@@C"
"N@@G"
"G@@N"
"CHAL"
"ALCH"
"@NG@"
"@GN@"
"@CL@"
"@CL@"
"@GN@"
"@NG@"
"ALCH"
"CHAL"
"G@@N"
"N@@G"
"L@@C")
(RPAQ? \LAFITE.ACTIVE )

(RPAQ? \LAFITE.READY )

(RPAQ? \LAFITEDEFAULTHOST&DIR )

(RPAQ? \LAFITEUSERDATA )

(ADDTOVAR \SYSTEMCACHEVARS \LAFITE.READY \LAFITEUSERDATA)
(DEFINEQ

(LAFITE.AROUNDEXIT
  [LAMBDA (EVENT)                                            (* bvm: " 6-Jan-86 11:28")
    (SELECTQ EVENT
        ((BEFORELOGOUT) 
             (SETQ \LAFITEUSERDATA NIL)
             (RESETLST (for FOLDER in \ACTIVELAFITEFOLDERS when (OBTAIN.MONITORLOCK
                                                                 (fetch (MAILFOLDER FOLDERLOCK)
                                                                    of FOLDER)
                                                                 T T) do (\LAFITE.CLOSE.FOLDER FOLDER 
                                                                                T))))
        ((AFTERLOGOUT AFTERSAVEVM AFTERSYSOUT AFTERMAKESYS) 
             (COND
                ((EQ \LAFITE.ACTIVE T)
                 (PRINTLAFITESTATUS "Reinitializing")
                 (\LAFITE.READ.PROFILE T)
                 (RESTART.PROCESS (QUOTE LAFITEMAILWATCH))
                 (CHECKLAFITEMAILFOLDERS))))
        NIL])

(CHECKLAFITEMAILFOLDERS
  [LAMBDA NIL                                                (* bvm: " 8-Jan-86 11:17")
          
          (* * On returning from LOGOUT check to see that all the mailfiles are in a 
          consistence state -- the user might have run Laurel and screwed up Lafite's 
          data, or run Lafite from another machine * *)

    (COND
       ((AND \ACTIVELAFITEFOLDERS (NOT \LAFITE.READY))
        (WITH.MONITOR \LAFITE.BROWSELOCK
               [COND
                  ((NOT \LAFITE.READY)
                   (SETQ \ACTIVELAFITEFOLDERS
                    (for FOLDER in (APPEND \ACTIVELAFITEFOLDERS) bind NEWESTNAME FULLNAME 
                                                                      BROWSERWINDOW collect FOLDER
                       when (COND
                               ((NULL (SETQ BROWSERWINDOW (fetch (MAILFOLDER BROWSERWINDOW)
                                                             of FOLDER)))
                                                             (* Not really active, forget it)
                                (\LAFITE.CLOSE.FOLDER FOLDER T)
                                NIL)
                               ((COND
                                   ((EQ (SETQ NEWESTNAME (INFILEP (fetch (MAILFOLDER 
                                                                                VERSIONLESSFOLDERNAME
                                                                                ) of FOLDER)))
                                        (SETQ FULLNAME (fetch (MAILFOLDER FULLFOLDERNAME)
                                                          of FOLDER)))
                                    (COND
                                       ((NOT (IEQP (GETFILEINFO FULLNAME (QUOTE LENGTH))
                                                   (fetch (MAILFOLDER FOLDEREOFPTR) of FOLDER)))
                                                             (* If length is different folder must 
                                                             have changed. Might want to check 
                                                             creation dates too)
                                        (\LAFITE.PROCESS (LIST (FUNCTION \LAFITE.REBROWSEFOLDER)
                                                               (KWOTE FOLDER))
                                               (QUOTE LAFITEBROWSE))
                                        T))
                                    T)
                                   ([OR (NOT NEWESTNAME)
                                        (ILESSP (FILENAMEFIELD NEWESTNAME (QUOTE VERSION))
                                               (FILENAMEFIELD FULLNAME (QUOTE VERSION]
                                    (printout PROMPTWINDOW T "Couldn't find file " FULLNAME)
                                    NIL)
                                   (T (printout PROMPTWINDOW T NEWESTNAME 
                                             " is a newer version than is currently being browsed." T
                                             )
                                      NIL))
                                T)
                               (T (printout PROMPTWINDOW " - closing its browser window.")
                                  (CLOSEW (LAB.FLUSHWINDOW BROWSERWINDOW FOLDER))
                                  (\LAFITE.CLOSE.FOLDER FOLDER T)
                                  NIL]
               (SETQ \LAFITE.READY T])

(\LAFITE.REBROWSEFOLDER
  [LAMBDA (FOLDER)                                           (* bvm: " 3-Feb-86 14:52")
    (WITH.MONITOR (fetch (MAILFOLDER FOLDERLOCK) of FOLDER)
           (LET ((BROWSERWINDOW (fetch (MAILFOLDER BROWSERWINDOW) of FOLDER))
                 WASOPEN)
                (COND
                   ((NOT (SETQ WASOPEN (OPENWP BROWSERWINDOW)))
                    (OPENW BROWSERWINDOW)))
                (CLEARW BROWSERWINDOW)
                (LAB.PROMPTPRINT FOLDER T "Folder has changed--rebrowsing...")
                (CLEARW BROWSERWINDOW)
                (LAB.LOADFOLDER FOLDER)
                (COND
                   ((NOT WASOPEN)
                    (\LAFITE.FINISH.UPDATE BROWSERWINDOW FOLDER (QUOTE SHRINK])

(\LAFITE.AFTERLOGIN
  [LAMBDA (HOST USER)                                        (* bvm: "11-Nov-84 18:28")
                                                             (* Called when LOGIN gets new info.
                                                             If HOST = NIL, this is the global 
                                                             login, which means we should get new 
                                                             data)
    (COND
       ((NULL HOST)
        (LAFITECLEARCACHE)
        (\LAFITE.WAKE.WATCHER])
)



(* ; "The profile")

(DEFINEQ

(\LAFITE.WRITE.PROFILE
  [LAMBDA NIL                                                (* bvm: " 1-May-86 12:28")
          
          (* * If "Profile" has changed, write out a new one.
          Profile is set of mail files and form files known to this Lafite)

    (WITH.MONITOR \LAFITE.PROFILELOCK
           (NLSETQ (COND
                      (\LAFITEPROFILECHANGED (LET ((NAME (PROFILEFILENAME))
                                                   OLDNAME OLDDATE OLDFOLDERS PROFILEFILE OVERWRITING
                                                   )
          
          (* Before dumping a new profile, check that a newer one hasn't been written 
          behind our back. This handles two cases --
          same user using Lafite from two machines, and file server having been down when 
          we first tried to read profile)

                                                  [COND
                                                     ([AND (SETQ OLDNAME (INFILEP NAME))
                                                           (SETQ OLDDATE (GETFILEINFO OLDNAME
                                                                                (QUOTE ICREATIONDATE)
                                                                                ))
                                                           (OR (NULL \LAFITEPROFILEDATE)
                                                               (NOT (IEQP \LAFITEPROFILEDATE OLDDATE]
                                                      (printout PROMPTWINDOW T OLDNAME 
                                          " has changed since you started this Lafite, rereading it."
                                                             )
                                                      [SETQ OVERWRITING (SETQ PROFILEFILE
                                                                         (OPENSTREAM OLDNAME
                                                                                (QUOTE BOTH)
                                                                                (QUOTE OLD]
                                                      (SETQ OLDFOLDERS (READ PROFILEFILE FILERDTBL))
                                                      [COND
                                                         ((STRING-EQUAL (CAR OLDFOLDERS)
                                                                 (CAR LAFITEMAILFOLDERS))
                                                             (* Merge old folders with new)
                                                          (RPLACD LAFITEMAILFOLDERS
                                                                 (\LAFITE.MERGE.PROFILES (CDR 
                                                                                           OLDFOLDERS
                                                                                              )
                                                                        (CDR LAFITEMAILFOLDERS]
                                                      (SETQ LAFITEFORMFILES (\LAFITE.MERGE.PROFILES
                                                                             (READ PROFILEFILE 
                                                                                   FILERDTBL)
                                                                             LAFITEFORMFILES))
                                                      (SETFILEPTR PROFILEFILE 0))
                                                     (T (SETQ PROFILEFILE (OPENSTREAM (OR OLDNAME 
                                                                                          NAME)
                                                                                 (QUOTE OUTPUT)
                                                                                 (QUOTE OLD/NEW]
                                                  (PRIN2 LAFITEMAILFOLDERS PROFILEFILE 
                                                         LAFITEPROFILERDTBL)
                                                  (PRIN1 " " PROFILEFILE)
                                                  (PRIN2 LAFITEFORMFILES PROFILEFILE 
                                                         LAFITEPROFILERDTBL)
                                                  [COND
                                                     (OVERWRITING 
                                                             (* Truncate old file to current length)
                                                            (SETFILEINFO PROFILEFILE (QUOTE LENGTH)
                                                                   (GETFILEPTR PROFILEFILE]
                                                  (SETQ \LAFITEPROFILEDATE (GETFILEINFO PROFILEFILE
                                                                                  (QUOTE 
                                                                                        ICREATIONDATE
                                                                                         )))
                                                  (CLOSEF PROFILEFILE)
                                                  (SETQ \LAFITEPROFILECHANGED])

(\LAFITE.MERGE.PROFILES
  [LAMBDA (NAMES1 NAMES2)                                    (* bvm: " 3-Feb-86 11:50")
          
          (* * Remove duplicates from the two lists NAMES1 and NAMES2 and merge them)

    (COND
       ([SETQ NAMES1 (for F in NAMES1 collect F unless (for FOLDER in NAMES2
                                                          thereis (STRING-EQUAL FOLDER F]
        (SORT (APPEND NAMES1 NAMES2)
              (FUNCTION UALPHORDER)))
       (T NAMES2])

(\LAFITE.READ.PROFILE
  [LAMBDA (ONLYIFCHANGED)                                    (* bvm: " 5-May-86 16:57")
    (WITH.MONITOR \LAFITE.PROFILELOCK (PROG (PROFILEFILE NEWDATE)
                                            (SETQ \LAFITEPROFILECHANGED)
                                            (COND
                                               ((AND (SETQ PROFILEFILE (INFILEP (PROFILEFILENAME)))
                                                     (OR (NOT ONLYIFCHANGED)
                                                         (NULL \LAFITEPROFILEDATE)
                                                         [NULL (SETQ NEWDATE (GETFILEINFO
                                                                              PROFILEFILE
                                                                              (QUOTE ICREATIONDATE]
                                                         (IGREATERP NEWDATE \LAFITEPROFILEDATE)))
                                                             (* read in the profile file *)
                                                (SETQ PROFILEFILE (OPENSTREAM PROFILEFILE
                                                                         (QUOTE INPUT)))
                                                (SETQ \LAFITEPROFILEDATE (GETFILEINFO PROFILEFILE
                                                                                (QUOTE ICREATIONDATE)
                                                                                ))
                                                (SETQ LAFITEMAILFOLDERS (READ PROFILEFILE 
                                                                              LAFITEPROFILERDTBL))
                                                (SETQ LAFITEFORMFILES (READ PROFILEFILE 
                                                                            LAFITEPROFILERDTBL))
                                                (CLOSEF PROFILEFILE)
                                                (COND
                                                   ((NOT (STRING-EQUAL (CAR LAFITEMAILFOLDERS)
                                                                (fetch PACKEDHOST&DIR of 
                                                                               \LAFITEDEFAULTHOST&DIR
                                                                       )))
                                                             (* Old format)
                                                    [SETQ LAFITEMAILFOLDERS
                                                     (CONS (fetch PACKEDHOST&DIR of 
                                                                               \LAFITEDEFAULTHOST&DIR
                                                                  )
                                                           (for FILE in LAFITEMAILFOLDERS
                                                              collect (LA.SHORTFILENAME FILE 
                                                                             LAFITEMAIL.EXT]
                                                    (SETQ \LAFITEPROFILECHANGED T)))
                                                (SETQ LAFITEFOLDERSMENU (SETQ LAFITEFORMSMENU NIL)))
                                               ((NULL LAFITEMAILFOLDERS)
                                                (SETQ LAFITEMAILFOLDERS (LIST (fetch PACKEDHOST&DIR
                                                                                 of 
                                                                               \LAFITEDEFAULTHOST&DIR
                                                                                     )))
                                                (SETQ LAFITEFORMFILES NIL])

(PROFILEFILENAME
  [LAMBDA NIL                                                (* bvm: " 6-Jan-86 11:22")
    (PACKFILENAME.STRING (QUOTE DIRECTORY)
           (fetch PACKEDHOST&DIR of \LAFITEDEFAULTHOST&DIR)
           (QUOTE NAME)
           LAFITEPROFILE.NAME
           (QUOTE EXTENSION)
           LAFITEPROFILE.EXT])
)

(RPAQ? \LAFITEPROFILEDATE )
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS LAFITEPROFILERDTBL LAFITEPROFILE.NAME LAFITEPROFILE.EXT \LAFITEPROFILEDATE)
)



(* ; "Low level file functions")

(DEFINEQ

(DELETEMAILFOLDER
  [LAMBDA (MAILFOLDER)                                       (* bvm: "21-Feb-84 14:55")
          
          (* * deletes the associated files and tells Lafite to forget about that mail 
          file * *)

    (PROG (FILE)
          (FORGETMAILFILE (OR (fetch (MAILFOLDER SHORTFOLDERNAME) of MAILFOLDER)
                              (LA.SHORTFILENAME (fetch (MAILFOLDER VERSIONLESSFOLDERNAME)
                                                   of MAILFOLDER)
                                     LAFITEMAIL.EXT)))
          (CLOSEF? (SETQ FILE (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER)))
          (DELFILE FILE)
          (SETQ FILE (TOCFILENAME FILE))
          (CLOSEF? FILE)
          (DELFILE FILE])

(FORGETMAILFILE
  [LAMBDA (FILENAME)                                         (* bvm: " 3-Feb-86 12:45")
          
          (* * removes FILENAME from the list of known mail files and invalidates the 
          menu cache)

    (LET [(KNOWNFILE (OR (find F in (CDR LAFITEMAILFOLDERS) suchthat (STRING-EQUAL F FILENAME))
                         (find F in (CDR LAFITEMAILFOLDERS) bind (SHORTNAME ← (LA.SHORTFILENAME
                                                                               FILENAME 
                                                                               LAFITEMAIL.EXT))
                            suchthat (STRING-EQUAL F SHORTNAME]
         (COND
            (KNOWNFILE (SETQ LAFITEMAILFOLDERS (DREMOVE KNOWNFILE LAFITEMAILFOLDERS))
                   (SETQ \LAFITEPROFILECHANGED T)
                   (SETQ LAFITEFOLDERSMENU])

(\LAFITE.UNCACHE.FOLDER
  [LAMBDA (ITEM MENU MULTFLG)                                (* bvm: "11-Mar-85 23:46")
          
          (* * Remove one or more names from the folder menu.
          If MULTFLG is true, loops until you click outside menu)

    (PROG ((FOLDERMENU (OR LAFITEFOLDERSMENU (MAKELAFITEMAILFOLDERSMENU)))
           FOLDER)
      LP  (COND
             ((SETQ FOLDER (MENU FOLDERMENU))
              (FORGETMAILFILE FOLDER)
              (printout PROMPTWINDOW T FOLDER " forgotten.")
              (COND
                 (MULTFLG (GO LP])

(\LAFITE.UNCACHE.FOLDER.MULTIPLE
  [LAMBDA (ITEM MENU)                                        (* bvm: "11-Mar-85 23:48")
    (\LAFITE.UNCACHE.FOLDER ITEM MENU T])

(\LAFITE.OPEN.FOLDER
  [LAMBDA (FOLDER ACCESS RECOG)                              (* bvm: "12-Jan-84 15:12")
          
          (* * For Interlisp-D its too inefficient to keep opening and closing the mail 
          file so we will keep it open -
          If the file wants to be open for INPUT do just that --
          it may want to be a read-only mail file --
          otherwise open it for BOTH -
          FILE is always a fully qualified file name * *)

    (PROG ((STREAM (fetch (MAILFOLDER FOLDERSTREAM) of FOLDER))
           [DESIREDACCESS (COND
                             ((EQ ACCESS (QUOTE INPUT))
                              ACCESS)
                             (T (QUOTE BOTH]
           FILE)
          (RETURN (COND
                     ((AND STREAM (OPENP STREAM DESIREDACCESS))
                      STREAM)
                     (T (SETQ FILE (\LAFITE.OPENSTREAM (OR [COND
                                                              (STREAM 
                                                             (* Have to close file to reopen for 
                                                             BOTH)
                                                                     (PROG1 (AND (OPENP STREAM)
                                                                                 (CLOSEF STREAM))
                                                                            (replace (MAILFOLDER
                                                                                      FOLDERSTREAM)
                                                                               of FOLDER with NIL]
                                                           (fetch (MAILFOLDER FULLFOLDERNAME)
                                                              of FOLDER))
                                          DESIREDACCESS RECOG (fetch (MAILFOLDER BROWSERWINDOW)
                                                                 of FOLDER)))
                        (AND (EQ DESIREDACCESS (QUOTE BOTH))
                             (LINELENGTH MAX.SMALLP FILE))   (* So that LA.PRINTCOUNT won't 
                                                             introduce CR's. Would be nice if 
                                                             PRINTNUM could be give a PRIN3 mode)
                        (replace (MAILFOLDER FOLDERSTREAM) of FOLDER with FILE])

(\LAFITE.OPENSTREAM
  [LAMBDA (FILE ACCESS RECOG BIGBUFS)                        (* bvm: " 6-Jan-84 12:24")
    [SETQ FILE (OPENSTREAM FILE ACCESS RECOG NIL (CONS (QUOTE (ENDOFSTREAMOP \LAFITE.EOF))
                                                       (AND BIGBUFS (LIST (LIST (QUOTE BUFFERS)
                                                                                LAFITEBUFFERSIZE]
    (WHENCLOSE FILE (QUOTE CLOSEALL)
           (QUOTE NO))
    FILE])

(\LAFITE.CREATE.MENU
  [LAMBDA (ITEMS TITLE)                                      (* bvm: " 5-Mar-84 15:23")
    (create MENU
           ITEMS ← ITEMS
           MENUFONT ← LAFITEMENUFONT
           TITLE ← TITLE
           CENTERFLG ← T])

(\LAFITE.EOF
  [LAMBDA (STREAM)                                           (* bvm: "27-Dec-83 12:05")
                                                             (* End of stream op for Lafite mail 
                                                             folders. Return endless CR's so that 
                                                             parses eventually stop)
    (CHARCODE CR])

(\LAFITE.CLOSE.FOLDER
  [LAMBDA (MAILFOLDER REALLYP)                               (* bvm: " 6-Feb-86 17:33")
          
          (* * If MAILFOLDER is open for output, make sure it is completely written out.
          If REALLYP then actually close the file)

    (LET ((STREAM (fetch (MAILFOLDER FOLDERSTREAM) of MAILFOLDER)))
         (COND
            (STREAM (COND
                       [(OPENP STREAM (QUOTE OUTPUT))
                        (FORCEOUTPUT STREAM T)
                        (COND
                           (REALLYP                          (* Due to Leaf bug, best to do the 
                                                             FORCEOUTPUT first even if we're really 
                                                             closing it)
                                  (CLOSEF STREAM]
                       ((AND REALLYP (OPENP STREAM))
                        (CLOSEF STREAM])

(PROMPTFORFILENAME
  [LAMBDA (WINDOW DEFAULT PROMPT)                            (* bvm: " 3-Feb-86 12:09")
    (RESETLST (OR PROMPT (SETQ PROMPT "Filename (CR to abort): "))
           (RESETSAVE (TTY.PROCESS (THIS.PROCESS)))
           (RESETSAVE NIL (LIST (COND
                                   (WINDOW (FUNCTION CLEARW))
                                   (T [SETQ WINDOW
                                       (PROG ((FONT (DEFAULTFONT (QUOTE DISPLAY)))
                                              WIDTH HEIGHT)
                                             [SETQ WIDTH (WIDTHIFWINDOW
                                                          (IPLUS (STRINGWIDTH PROMPT FONT)
                                                                 (ITIMES 50 (CHARWIDTH (CHARCODE
                                                                                        A)
                                                                                   FONT]
                                             [SETQ HEIGHT (HEIGHTIFWINDOW (FONTPROP FONT (QUOTE
                                                                                          HEIGHT]
                                             (RETURN (CREATEW (create REGION
                                                                     LEFT ← (IMIN LASTMOUSEX
                                                                                  (IDIFFERENCE 
                                                                                         SCREENWIDTH 
                                                                                         WIDTH))
                                                                     BOTTOM ← (IMIN LASTMOUSEY
                                                                                    (IDIFFERENCE
                                                                                     SCREENHEIGHT 
                                                                                     HEIGHT))
                                                                     WIDTH ← WIDTH
                                                                     HEIGHT ← HEIGHT]
                                      (FUNCTION CLOSEW)))
                                WINDOW))
           (PROMPTFORWORD PROMPT DEFAULT NIL WINDOW NIL NIL (CHARCODE (CR ESC])

(\LAFITE.PROMPTFORFOLDER
  [LAMBDA (WINDOW)                                           (* bvm: "27-Dec-83 19:12")
    (PROG [(FILE (MENU (OR LAFITEFOLDERSMENU (MAKELAFITEMAILFOLDERSMENU]
          (RETURN (SELECTQ FILE
                      (NIL NIL)
                      (##ANOTHERFILE## 
                           (PROMPTFORFILENAME WINDOW))
                      FILE])

(MAKELAFITEMAILFOLDERSMENU
  [LAMBDA NIL                                                (* bvm: " 6-Jan-84 11:26")
    (SETQ LAFITEFOLDERSMENU (create MENU
                                   ITEMS ← (APPEND (SORT (CDR LAFITEMAILFOLDERS))
                                                  (LIST ANOTHERFOLDERMENUITEM))
                                   TITLE ← (CONCAT "Folders on " (L-CASE (fetch PACKEDHOST&DIR 
                                                                               \LAFITEDEFAULTHOST&DIR
                                                                                )))
                                   CENTERFLG ← T])

(MAILFOLDERBUSY
  [LAMBDA (MAILFOLDER)                                       (* bvm: "29-Dec-83 18:11")
    (RESETFORM (CURSOR LA.CROSSCURSOR)
           (BLOCK LAFITEBUSYWAITTIME])

(LA.LONGFILENAME
  [LAMBDA (FILENAME EXT)                                     (* bvm: "24-Feb-85 22:20")
          
          (* * Composes a (nearly) full-specified filename, filling in defaults from 
          \LAFITEDEFAULTHOST&DIR)
          
          (* * Would like this to be (PACKFILENAME
          (QUOTE BODY) FILENAME (QUOTE EXTENSION) EXT
          (QUOTE DIRECTORY) (fetch PACKEDHOST&DIR of \LAFITEDEFAULTHOST&DIR)) but 
          PACKFILENAME handles DIRECTORY wrong if FILENAME has a host but no dir)

    (LET ((FILEFIELDS (UNPACKFILENAME.STRING FILENAME))
          (DEFAULTFIELDS (fetch UNPACKEDHOST&DIR of \LAFITEDEFAULTHOST&DIR)))
         (while (AND DEFAULTFIELDS (NEQ (CAR DEFAULTFIELDS)
                                        (CAR FILEFIELDS))) do (NCONC FILEFIELDS (LIST (CAR 
                                                                                        DEFAULTFIELDS
                                                                                           )
                                                                                      (CADR 
                                                                                        DEFAULTFIELDS
                                                                                            )))
                                                              (SETQ DEFAULTFIELDS (CDDR DEFAULTFIELDS
                                                                                        )))
         (PACKFILENAME (NCONC FILEFIELDS (LIST (QUOTE EXTENSION)
                                               EXT])

(TOCFILENAME
  [LAMBDA (MAILFILE)                                         (* M.Yonke "12-APR-83 12:44")
    (COND
       (MAILFILE (PACKFILENAME (QUOTE EXTENSION)
                        (CONCAT (FILENAMEFIELD MAILFILE (QUOTE EXTENSION))
                               LAFITETOC.EXT)
                        (QUOTE BODY)
                        MAILFILE])

(LA.SHORTFILENAME
  [LAMBDA (FILE EXT KEEPVERSIONFLG)                          (* bvm: " 3-Feb-86 12:42")
          
          (* * returns that shortest file name that is compatible with 
          \LAFITEDEFAULTHOST&DIR and EXT and no version number --
          the result is used in menu creation * *)

    (COND
       (FILE (LET ([FILEFIELDS (COND
                                  ((LISTP FILE)              (* Already unpacked)
                                   (APPEND FILE))
                                  (T (UNPACKFILENAME.STRING FILE]
                   MATCHFAILED)
                  [for FILETAIL on FILEFIELDS by (CDDR FILETAIL)
                     as (DEFAULTTAIL ← (fetch UNPACKEDHOST&DIR of \LAFITEDEFAULTHOST&DIR))
                     by (CDDR DEFAULTTAIL)
                     do (COND
                           ((COND
                               ((AND (NOT MATCHFAILED)
                                     (EQ (CAR FILETAIL)
                                         (CAR DEFAULTTAIL)))
                                (STRING-EQUAL (CADR FILETAIL)
                                       (CADR DEFAULTTAIL)))
                               (T (SETQ MATCHFAILED T)
                                  (SELECTQ (CAR FILETAIL)
                                      (EXTENSION (STRING-EQUAL (CADR FILETAIL)
                                                        EXT))
                                      (VERSION (NOT KEEPVERSIONFLG))
                                      NIL)))                 (* Remove a field from the result)
                            (RPLACA (CDR FILETAIL)
                                   NIL))
                           (T                                (* Inhibit further matching in the 
                                                             HOST DEVICE DIRECTORY part)
                              (SETQ MATCHFAILED T]
                  (PACKFILENAME FILEFIELDS])
)
(DEFINEQ

(COPY7BITFILE
  [LAMBDA (SRCFIL DSTFIL)                                    (* bvm: " 5-Jan-84 10:57")
    (RESETLST (PROG (INSTREAM OUTSTREAM CH)
                    [RESETSAVE NIL (LIST (QUOTE CLOSEF)
                                         (SETQ INSTREAM (OPENSTREAM SRCFIL (QUOTE INPUT)
                                                               NIL NIL (QUOTE ((SEQUENTIAL T)
                                                                               (ENDOFSTREAMOP NILL]
                    [RESETSAVE NIL (LIST [FUNCTION (LAMBDA (STREAM)
                                                     (SETQ STREAM (CLOSEF STREAM))
                                                     (AND RESETSTATE (DELFILE STREAM]
                                         (SETQ OUTSTREAM (OPENSTREAM
                                                          (OR DSTFIL (PACKFILENAME (QUOTE VERSION)
                                                                            NIL
                                                                            (QUOTE BODY)
                                                                            (FULLNAME INSTREAM)))
                                                          (QUOTE OUTPUT)
                                                          (QUOTE NEW)
                                                          NIL
                                                          (LIST (QUOTE (SEQUENTIAL T))
                                                                (LIST (QUOTE LENGTH)
                                                                      (GETFILEINFO INSTREAM
                                                                             (QUOTE LENGTH]
                    (while (SETQ CH (BIN INSTREAM)) do (BOUT OUTSTREAM (LOGAND CH 127)))
                    (RETURN (FULLNAME OUTSTREAM])

(FIXLAURELFILE
  [LAMBDA (MAILFILE)                                         (* bvm: "21-Feb-84 14:35")
    (PROG (FOLDER)
          (COND
             ((SETQ FOLDER (WITH.MONITOR \LAFITE.BROWSELOCK (\LAFITE.GETMAILFOLDER MAILFILE)))
              (\LAFITE.FIX.LAUREL.FOLDER FOLDER])

(\LAFITE.BROWSE.LAURELFILE
  [LAMBDA (ITEM MENU)                                        (* bvm: "27-Feb-86 17:27")
    (\LAFITE.BROWSE.PROC ITEM MENU NIL NIL (QUOTE LAUREL])

(\LAFITE.NOTICE.FOLDERS
  [LAMBDA NIL                                                (* bvm: "27-Feb-86 17:49")
    (LET ((PATTERN (PROMPTFORFILENAME NIL (CAR \LAFITEDEFAULTHOST&DIR)
                          "Notice mail folders on directory: "))
          WINDOW FILES)
         (COND
            (PATTERN (SETQ PATTERN (PACKFILENAME.STRING (QUOTE BODY)
                                          PATTERN
                                          (QUOTE NAME)
                                          (QUOTE *)
                                          (QUOTE EXTENSION)
                                          LAFITEMAIL.EXT
                                          (QUOTE VERSION)
                                          ""))               (* Default to *.MAIL;)
                   (SETQ WINDOW (\LAFITE.MAKE.RANDOM.DISPLAY "Noticed Mail Folders" PATTERN
                                       (CONCAT "Enumerating " PATTERN "...
")))
                   (SETQ FILES (DIRECTORY PATTERN))
                   (COND
                      ((NULL FILES)
                       (printout WINDOW T "No matching files found."))
                      ((NULL (SETQ FILES (for F in FILES unless (MEMB (SETQ F (LA.SHORTFILENAME
                                                                               F LAFITEMAIL.EXT))
                                                                      (CDR LAFITEMAILFOLDERS))
                                            collect (printout WINDOW F ", ")
                                                  F)))
                       (printout WINDOW T "No new files found."))
                      ((\LAFITE.GC.FOLDERS.CONFIRM WINDOW 
                              "Click Proceed to add these folders to set of known folders")
                       (RPLACD LAFITEMAILFOLDERS (MERGE (CDR LAFITEMAILFOLDERS)
                                                        FILES
                                                        (FUNCTION UALPHORDER)))
                       (SETQ LAFITEFOLDERSMENU)
                       (SETQ \LAFITEPROFILECHANGED T)
                       (printout WINDOW T "Done."))
                      (T (printout WINDOW T "Aborted."])

(\LAFITE.MAKE.RANDOM.DISPLAY
  [LAMBDA (TITLE SAMPLESTRING INITIALCONTENT)                (* bvm: "27-Feb-86 17:55")
    (LET ((REG (WINDOWREGION LAFITESTATUSWINDOW))
          (HEIGHT (HEIGHTIFWINDOW (TIMES 6 (FONTPROP NIL (QUOTE HEIGHT)))
                         T))
          BOTTOM WINDOW)
         [SETQ WINDOW (OPENTEXTSTREAM INITIALCONTENT
                             (CREATEW (MAKEWITHINREGION
                                       (create REGION
                                              LEFT ← (fetch (REGION LEFT) of REG)
                                              BOTTOM ← (COND
                                                          ((LESSP (SETQ BOTTOM
                                                                   (IDIFFERENCE (fetch (REGION BOTTOM
                                                                                              )
                                                                                   of REG)
                                                                          HEIGHT))
                                                                  0)
                                                             (* tried placing it below status 
                                                             window, but that's off screen)
                                                           (fetch (REGION TOP) of REG))
                                                          (T BOTTOM))
                                              WIDTH ← [IMAX (FIXR (TIMES 1.5 (STRINGWIDTH 
                                                                                    SAMPLESTRING)))
                                                            (TIMES 50 (CHARWIDTH (CHARCODE M]
                                              HEIGHT ← HEIGHT))
                                    TITLE)
                             NIL NIL (QUOTE (PROMPTWINDOW DON'T]
         (SETFILEPTR WINDOW -1)
         (LINELENGTH MAX.SMALLP WINDOW)
         WINDOW])

(\LAFITE.GC.FOLDERS
  [LAMBDA NIL                                                (* bvm: "27-Feb-86 17:58")
    (LET ((WINDOW (\LAFITE.MAKE.RANDOM.DISPLAY "Folders no longer found" (CAR \LAFITEDEFAULTHOST&DIR)
                         ))
          FILES)
         (printout WINDOW "Scanning...")
         (SETQ FILES (for F in (CDR LAFITEMAILFOLDERS) unless (PROGN (printout WINDOW ".")
                                                                     (INFILEP (LA.LONGFILENAME F 
                                                                                     LAFITEMAIL.EXT))
                                                                     )
                        collect (printout WINDOW , F " not found." T)
                              F))
         (COND
            ((NOT FILES)
             (printout WINDOW T "All known folders still exist."))
            ((\LAFITE.GC.FOLDERS.CONFIRM WINDOW 
                    "Click Proceed to remove these names from the set of known folders")
             (RPLACD LAFITEMAILFOLDERS (LDIFFERENCE (CDR LAFITEMAILFOLDERS)
                                              FILES))
             (SETQ LAFITEFOLDERSMENU)
             (SETQ \LAFITEPROFILECHANGED T)
             (printout WINDOW T "Done"))
            (T (printout WINDOW T "Aborted"])

(\LAFITE.GC.FOLDERS.CONFIRM
  [LAMBDA (TEXTSTREAM PROMPT)                                (* bvm: "27-Feb-86 17:58")
          
          (* * Wait for confirming response from Proceed/Abort menu before changing 
          folders menu. PROMPT is instructions to issue in TEXTSTREAM)

    (printout TEXTSTREAM T PROMPT)
    (PROG1 (MENU (create MENU
                        ITEMS ← (QUOTE (("Proceed" T "Yes, change the folder menu as indicated.")
                                        ("Abort" NIL "No, take no action")))
                        MENUROWS ← 1
                        CENTERFLG ← T
                        MENUFONT ← LAFITEMENUFONT
                        MENUBORDERSIZE ← 2)
                 [LET [(REG (WINDOWPROP (CAR (fetch (TEXTOBJ \WINDOW) of (TEXTOBJ TEXTSTREAM)))
                                   (QUOTE REGION]
                      (create POSITION
                             XCOORD ← (fetch (REGION LEFT) of REG)
                             YCOORD ← (IDIFFERENCE (fetch (REGION BOTTOM) of REG)
                                             (IPLUS 2 (FONTPROP LAFITEMENUFONT (QUOTE HEIGHT]
                 T)
           (SETFILEPTR TEXTSTREAM -1])

(\LAFITE.FIX.LAUREL.FOLDER
  [LAMBDA (MAILFOLDER)                                       (* bvm: " 3-Feb-86 15:15")
    (RESETLST (PROG (STREAM CH)
                    (OBTAIN.MONITORLOCK (fetch (MAILFOLDER FOLDERLOCK) of MAILFOLDER)
                           NIL T)
                    (LAB.PROMPTPRINT MAILFOLDER "Laurel scan... ")
                    (SETQ STREAM (\LAFITE.OPEN.FOLDER MAILFOLDER (QUOTE BOTH)))
                    (RESETSAVE NIL (LIST (FUNCTION \LAFITE.CLOSE.FOLDER)
                                         MAILFOLDER T))
                    (SETFILEINFO STREAM (QUOTE ENDOFSTREAMOP)
                           (FUNCTION NILL))
                    [while (SETQ CH (BIN STREAM)) do (COND
                                                        ((EQ CH (LOGOR 128 (CHARCODE SPACE)))
                                                         (\BACKFILEPTR STREAM)
                                                         (BOUT STREAM (CHARCODE SPACE]
                    (RETURN (FULLNAME STREAM])
)
(DECLARE: DOEVAL@COMPILE DONTCOPY 
(FILESLOAD (SOURCE)
       LAFITEDECLS)

(DEFINEQ

(RELEASE.LAFITE
  [LAMBDA NIL                                                (* bvm: " 7-Oct-86 20:57")
    (ADD.PROCESS [LIST (FUNCTION (LAMBDA NIL
                                   (TTYDISPLAYSTREAM (CREATEW (QUOTE (0 248 467 163))
                                                            "Lafite Release"))
                                   (DSPSCROLL T)
                                   (FILESLOAD (SYSLOAD)
                                          COPYFILES)
                                   (COPYFILES "{ERIS}<LAFITE>SOURCES>" "{ERIS}<LISPCORE>LIBRARY>"
                                          (QUOTE (>)))
                                   (printout T T "Lafite Release Complete"]
           (QUOTE BEFOREEXIT)
           (QUOTE DON'T])
)

(ADDTOVAR DONTCOMPILEFNS RELEASE.LAFITE)
)
(/DECLAREDATATYPE (QUOTE MAILFOLDER)
       (QUOTE (FLAG FLAG FLAG FLAG FLAG FLAG FLAG POINTER POINTER POINTER POINTER POINTER POINTER 
                    WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
                    POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER 
                    POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER))
       (QUOTE ((MAILFOLDER 0 (FLAGBITS . 0))
               (MAILFOLDER 0 (FLAGBITS . 16))
               (MAILFOLDER 0 (FLAGBITS . 32))
               (MAILFOLDER 0 (FLAGBITS . 48))
               (MAILFOLDER 0 (FLAGBITS . 64))
               (MAILFOLDER 0 (FLAGBITS . 80))
               (MAILFOLDER 0 (FLAGBITS . 96))
               (MAILFOLDER 0 POINTER)
               (MAILFOLDER 2 POINTER)
               (MAILFOLDER 4 POINTER)
               (MAILFOLDER 6 POINTER)
               (MAILFOLDER 8 POINTER)
               (MAILFOLDER 10 POINTER)
               (MAILFOLDER 12 (BITS . 15))
               (MAILFOLDER 13 (BITS . 15))
               (MAILFOLDER 14 (BITS . 15))
               (MAILFOLDER 15 (BITS . 15))
               (MAILFOLDER 16 (BITS . 15))
               (MAILFOLDER 17 (BITS . 15))
               (MAILFOLDER 18 (BITS . 15))
               (MAILFOLDER 19 (BITS . 15))
               (MAILFOLDER 20 (BITS . 15))
               (MAILFOLDER 21 (BITS . 15))
               (MAILFOLDER 22 (BITS . 15))
               (MAILFOLDER 23 (BITS . 15))
               (MAILFOLDER 24 (BITS . 15))
               (MAILFOLDER 25 (BITS . 15))
               (MAILFOLDER 26 (BITS . 15))
               (MAILFOLDER 27 (BITS . 15))
               (MAILFOLDER 28 POINTER)
               (MAILFOLDER 30 POINTER)
               (MAILFOLDER 32 POINTER)
               (MAILFOLDER 34 POINTER)
               (MAILFOLDER 36 POINTER)
               (MAILFOLDER 38 POINTER)
               (MAILFOLDER 40 POINTER)
               (MAILFOLDER 42 POINTER)
               (MAILFOLDER 44 POINTER)
               (MAILFOLDER 46 POINTER)
               (MAILFOLDER 48 POINTER)
               (MAILFOLDER 50 POINTER)
               (MAILFOLDER 52 POINTER)
               (MAILFOLDER 54 POINTER)
               (MAILFOLDER 56 POINTER)
               (MAILFOLDER 58 POINTER)
               (MAILFOLDER 60 POINTER)
               (MAILFOLDER 62 POINTER)))
       (QUOTE 64))
(/DECLAREDATATYPE (QUOTE LAFITEMSG)
       (QUOTE (FLAG FLAG FLAG FLAG FLAG FLAG FLAG FLAG POINTER BYTE POINTER WORD WORD WORD WORD FLAG 
                    FLAG FLAG FLAG FLAG FLAG FLAG FLAG POINTER POINTER POINTER POINTER))
       (QUOTE ((LAFITEMSG 0 (FLAGBITS . 0))
               (LAFITEMSG 0 (FLAGBITS . 16))
               (LAFITEMSG 0 (FLAGBITS . 32))
               (LAFITEMSG 0 (FLAGBITS . 48))
               (LAFITEMSG 0 (FLAGBITS . 64))
               (LAFITEMSG 0 (FLAGBITS . 80))
               (LAFITEMSG 0 (FLAGBITS . 96))
               (LAFITEMSG 0 (FLAGBITS . 112))
               (LAFITEMSG 0 POINTER)
               (LAFITEMSG 2 (BITS . 7))
               (LAFITEMSG 2 POINTER)
               (LAFITEMSG 4 (BITS . 15))
               (LAFITEMSG 5 (BITS . 15))
               (LAFITEMSG 6 (BITS . 15))
               (LAFITEMSG 7 (BITS . 15))
               (LAFITEMSG 8 (FLAGBITS . 0))
               (LAFITEMSG 8 (FLAGBITS . 16))
               (LAFITEMSG 8 (FLAGBITS . 32))
               (LAFITEMSG 8 (FLAGBITS . 48))
               (LAFITEMSG 8 (FLAGBITS . 64))
               (LAFITEMSG 8 (FLAGBITS . 80))
               (LAFITEMSG 8 (FLAGBITS . 96))
               (LAFITEMSG 8 (FLAGBITS . 112))
               (LAFITEMSG 8 POINTER)
               (LAFITEMSG 10 POINTER)
               (LAFITEMSG 12 POINTER)
               (LAFITEMSG 14 POINTER)))
       (QUOTE 16))
[ADDTOVAR SYSTEMRECLST

(DATATYPE MAILFOLDER ((BROWSERPROMPTDIRTY FLAG)
                      (BROWSERREADY FLAG)
                      (FOLDERNEEDSUPDATE FLAG)
                      (FOLDERNEEDSEXPUNGE FLAG)
                      (FOLDERBEINGUPDATED FLAG)
                      (HARDCOPYPENDING FLAG)
                      (NIL FLAG)
                      (FULLFOLDERNAME POINTER)
                      (VERSIONLESSFOLDERNAME POINTER)
                      (SHORTFOLDERNAME POINTER)
                      (FOLDERSTREAM POINTER)
                      (MESSAGEDESCRIPTORS POINTER)
                      (FOLDERLOCK POINTER)
                      (#OFMESSAGES WORD)
                      (TOCLASTMESSAGE# WORD)
                      (BROWSERFONTHEIGHT WORD)
                      (BROWSERFONTASCENT WORD)
                      (BROWSERFONTDESCENT WORD)
                      (BROWSERMAXXPOS WORD)
                      (ORDINALXPOS WORD)
                      (DATEXPOS WORD)
                      (FROMXPOS WORD)
                      (FROMMAXXPOS WORD)
                      (SUBJECTXPOS WORD)
                      (BROWSERDIGITWIDTH WORD)
                      (FIRSTSELECTEDMESSAGE WORD)
                      (LASTSELECTEDMESSAGE WORD)
                      (FIRSTCHANGEDMESSAGE WORD)
                      (CURRENTEOMLENGTH WORD)
                      (CURRENTDISPLAYEDSTREAM POINTER)
                      (BROWSEREXTENT POINTER)
                      (BROWSERORIGIN POINTER)
                      (BROWSERSELECTIONREGION POINTER)
                      (BROWSERWINDOW POINTER)
                      (BROWSERMENU POINTER)
                      (BROWSERMENUWINDOW POINTER)
                      (BROWSERPROMPTWINDOW POINTER)
                      (ORIGINALBROWSERTITLE POINTER)
                      (FOLDERDISPLAYWINDOWS POINTER)
                      (FOLDEREOFPTR POINTER)
                      (DEFAULTMOVETOFILE POINTER)
                      (CURRENTDISPLAYEDMESSAGE POINTER)
                      (BROWSERUPDATEFROMHERE POINTER)
                      (EXTRAFIELD POINTER)
                      (FOLDERCREATIONDATE POINTER)
                      (HARDCOPYMESSAGES POINTER)
                      (HARDCOPYSTREAM POINTER)))

(DATATYPE LAFITEMSG ((PARSED? FLAG)
                     (DELETED? FLAG)
                     (SEEN? FLAG)
                     (FORMATTED? FLAG)
                     (NIL FLAG)
                     (NIL FLAG)
                     (NIL FLAG)
                     (NIL FLAG)
                     (BEGIN POINTER)
                     (MARKCHAR BYTE)
                     (MESSAGELENGTH POINTER)
                     (# WORD)
                     (STAMPLENGTH WORD)
                     (TOCLENGTH WORD)
                     (NIL WORD)
                     (MESSAGELENGTHCHANGED? FLAG)
                     (NIL FLAG)
                     (SELECTED? FLAG)
                     (MSGFROMMECHECKED? FLAG)
                     (MSGFROMMETRUTH FLAG)
                     (MARKSCHANGEDINFILE? FLAG)
                     (MARKSCHANGEDINTOC? FLAG)
                     (NIL FLAG)
                     (DATE POINTER)
                     (FROM POINTER)
                     (SUBJECT POINTER)
                     (TO POINTER)))
]
(DEFINEQ

(\LAFITE.GLOBAL.INIT
  [LAMBDA NIL                                                (* bvm: " 1-May-86 12:24")
                                                             (* need to do this so you can send a 
                                                             message without "starting" lafite *)
    (DECLARE (GLOBALVARS BackgroundMenu BackgroundMenuCommands))
    (COND
       ((NOT (ASSOC (QUOTE SendMail)
                    BackgroundMenuCommands))
        [SETQ BackgroundMenuCommands (APPEND BackgroundMenuCommands
                                            (LIST (LIST (QUOTE SendMail)
                                                        (KWOTE (LIST (FUNCTION \LAFITE.MESSAGEFORM)))
                                                        "Bring up a message sending form."]
        (SETQ BackgroundMenu NIL)))
    (LAFITE.INIT.PARSETABLES)
    (SETQ \LAFITE.MAILSERVERLOCK (CREATE.MONITORLOCK "Lafite Mail Servers"))
                                                             (* Used by anyone who calls 
                                                             \LAFITE.GET.USER.DATA or otherwise 
                                                             tries to muck with \LAFITEUSERDATA)
    (SETQ LAFITEPROFILERDTBL (COPYREADTABLE (QUOTE ORIG)))   (* For reading and writing the profile)
    NIL])
)
(DECLARE: DONTEVAL@LOAD DOCOPY 
(FILESLOAD LAFITEBROWSE LAFITESEND LAFITEMAIL TEDIT ATTACHEDWINDOW)

(\LAFITE.GLOBAL.INIT)
)
(DECLARE: DOEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA LAFITE)
)
(PUTPROPS LAFITE COPYRIGHT ("Xerox Corporation and Bolt Beranek and Newman Inc." 1982 1983 1984 1985 
1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (4441 26948 (LAFITE 4451 . 7035) (\LAFITE.START.PROC 7037 . 9756) (
LA.CREATE.UPDATE.MENUS 9758 . 10650) (\LAFITE.PROCESS 10652 . 11161) (\LAFITE.START.ABORT 11163 . 
11433) (\LAFITE.QUIT 11435 . 11830) (\LAFITE.RESTART 11832 . 12052) (\LAFITE.SUBQUIT 12054 . 13327) (
\LAFITE.QUIT.PROC 13329 . 20950) (\LAFITEDEFAULTHOST&DIR 20952 . 22397) (LAFITEDEFAULTHOST&DIR 22399
 . 22642) (MAKELAFITECOMMANDWINDOW 22644 . 26285) (EXTRACTMENUCOMMAND 26287 . 26752) (
DOMAINLAFITECOMMAND 26754 . 26946)) (27019 29658 (LAFITEMODE 27029 . 28042) (\LAFITE.INFER.MODE 28044
 . 28652) (\LAFITE.SHOW.MODE 28654 . 29035) (\LAFITE.MODE.TITLE 29037 . 29656)) (35284 39224 (
LA.RESETSHADE 35294 . 35694) (LA.MENU.ITEM 35696 . 36171) (LA.REMOVEDUPLICATES 36173 . 36916) (
COLLECTOLDFILES 36918 . 37405) (LA.SETDIFFERENCE 37407 . 37720) (NTHMESSAGE 37722 . 37855) (
\LAFITE.MAKE.MSGARRAY 37857 . 38467) (\LAFITE.ADDMESSAGES.TO.ARRAY 38469 . 39222)) (39618 45561 (
LAFITE.AROUNDEXIT 39628 . 40647) (CHECKLAFITEMAILFOLDERS 40649 . 44206) (\LAFITE.REBROWSEFOLDER 44208
 . 44974) (\LAFITE.AFTERLOGIN 44976 . 45559)) (45590 55528 (\LAFITE.WRITE.PROFILE 45600 . 50845) (
\LAFITE.MERGE.PROFILES 50847 . 51371) (\LAFITE.READ.PROFILE 51373 . 55183) (PROFILEFILENAME 55185 . 
55526)) (55728 70502 (DELETEMAILFOLDER 55738 . 56527) (FORGETMAILFILE 56529 . 57442) (
\LAFITE.UNCACHE.FOLDER 57444 . 58033) (\LAFITE.UNCACHE.FOLDER.MULTIPLE 58035 . 58213) (
\LAFITE.OPEN.FOLDER 58215 . 60719) (\LAFITE.OPENSTREAM 60721 . 61196) (\LAFITE.CREATE.MENU 61198 . 
61453) (\LAFITE.EOF 61455 . 61880) (\LAFITE.CLOSE.FOLDER 61882 . 62838) (PROMPTFORFILENAME 62840 . 
65207) (\LAFITE.PROMPTFORFOLDER 65209 . 65602) (MAKELAFITEMAILFOLDERSMENU 65604 . 66274) (
MAILFOLDERBUSY 66276 . 66469) (LA.LONGFILENAME 66471 . 68124) (TOCFILENAME 68126 . 68493) (
LA.SHORTFILENAME 68495 . 70500)) (70503 80820 (COPY7BITFILE 70513 . 72389) (FIXLAURELFILE 72391 . 
72689) (\LAFITE.BROWSE.LAURELFILE 72691 . 72876) (\LAFITE.NOTICE.FOLDERS 72878 . 75128) (
\LAFITE.MAKE.RANDOM.DISPLAY 75130 . 77190) (\LAFITE.GC.FOLDERS 77192 . 78537) (
\LAFITE.GC.FOLDERS.CONFIRM 78539 . 79770) (\LAFITE.FIX.LAUREL.FOLDER 79772 . 80818)) (80897 81677 (
RELEASE.LAFITE 80907 . 81675)) (88775 90162 (\LAFITE.GLOBAL.INIT 88785 . 90160)))))
STOP