(FILECREATED "19-Sep-85 02:02:32" {ERIS}<MBENNETT>LISP>MAILOMAT.;3 124424 

      changes to:  (FNS MAILOMAT.MENU.FN.APPLY MAILOMAT.PROCESS.FILE 
			MAILOMAT.PARSEMAILFOLDER1)
		   (VARS MAILOMATCOMS SEENFLAG DELETEDFLAG UNDELETEDFLAG)

      previous date: "18-Sep-85 08:38:53" {ERIS}<LISPUSERS>MAILOMAT.;1)


(* Copyright (c) 1984, 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT MAILOMATCOMS)

(RPAQQ MAILOMATCOMS ((* * MAILOMAT.FORM functions and variables)
	(FNS MAILOMAT.ADD.USER MAILOMAT.APPEND.TIME MAILOMAT.APPENDMESSAGES 
	     MAILOMAT.ENCODE.PERIODIC.PARAMS MAILOMAT.ENCODE.START.TIME 
	     MAILOMAT.ENCODE.TIME.UNIT MAILOMAT.ENCODE.TOD.PARAMS 
	     MAILOMAT.ENCODE.USER.DATA MAILOMAT.EXTRACT.FIELDS MAILOMAT.HARDCOPY 
	     MAILOMAT.MENU.FN.PUT MAILOMAT.INFER.USERNAME MAILOMAT.UPDATECONTENTSFILE 
	     MAILOMAT.UPDATEMAILFOLDER MAILOMAT.BLANKP MAILOMAT.BUTTON.GET.MENU 
	     MAILOMAT.BUTTON.GET.SUBMENU MAILOMAT.BUTTON.OBJ.CREATE 
	     MAILOMAT.BUTTONFN.DOMENU MAILOMAT.BUTTONFN.DOSUBMENU 
	     MAILOMAT.BUTTONFN.SELFIELD MAILOMAT.CHECK.FIELDS MAILOMAT.CHECK.MENU 
	     MAILOMAT.CHECK.SHORTSTRING MAILOMAT.CHECK.SUBMENU MAILOMAT.CONFIRM 
	     MAILOMAT.DELETE.FIELD.VAL MAILOMAT.DISCONNECT.WINDOW MAILOMAT.FIND.BUTTON 
	     MAILOMAT.FIND.EDIT.CHANGES MAILOMAT.FIND.UNPROTECTED.CH# MAILOMAT.FORM.CLEAR 
	     MAILOMAT.FORM.CREATE MAILOMAT.FORM.FILL.INS MAILOMAT.FULLUSERNAME 
	     MAILOMAT.ICONFN MAILOMAT.INDEX.FIRING.TIMES MAILOMAT.INIT 
	     MAILOMAT.INIT.MAIL.USER MAILOMAT.LOAD.FIELDS MAILOMAT.LOAD.FROM.PROFILE 
	     MAILOMAT.LOADMAILFOLDER MAILOMAT.PANEL.CREATE MAILOMAT.PARSE.TIME 
	     MAILOMAT.PARSEMAILFOLDER1 MAILOMAT.FORM.GROUP.CREATE 
	     MAILOMAT.KILL.ATTACHED.TEDIT.CLOSEFN MAILOMAT.FORM.MENU.ACTIONFN 
	     MAILOMAT.GET.MAILOMAT MAILOMAT.GET.PASSWORD MAILOMAT.GETMAILFOLDER 
	     MAILOMAT.GETNEWMAIL MAILOMAT.GETNEWMAIL1 MAILOMAT.FORM.MENU.BUTTONFN 
	     MAILOMAT.FORM.SAVE MAILOMAT.GET.FILENAME 
	     MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL MAILOMAT.GET.ASSOCIATED.MENU.VAL 
	     MAILOMAT.GET.BUTTON.FIELD.AS.TEXT MAILOMAT.GET.BUTTON.FIELD.AS.LIST 
	     MAILOMAT.MARK.ACTIVE MAILOMAT.MARK.HARDCOPIED MAILOMAT.MENU.CR.FN 
	     MAILOMAT.MENU.FN.CLEAR MAILOMAT.MENU.FN.GET MAILOMAT.MENU.FN.APPLY 
	     MAILOMAT.GET.USERNAME MAILOMAT.OPEN.MAILFOLDER MAILOMAT.PRESENT.TIME 
	     MAILOMAT.PROCESS.FILE MAILOMAT.PROMPT MAILOMAT.PROTECT.WARNING 
	     MAILOMAT.PUT.FAILED MAILOMAT.READTOCFILE MAILOMAT.RECONNECT.WINDOW 
	     MAILOMAT.REMOVE.USER MAILOMAT.REPLACE.FIELD.VAL MAILOMAT.REPLACE.FILL.INS 
	     MAILOMAT.RESET.SEL MAILOMAT.SCRATCH.LOAD MAILOMAT.SELECTMESSAGE 
	     MAILOMAT.TEXTSTREAM.LOAD MAILOMAT.TIME.OF.DAY.WAKEUP MAILOMAT.TOBJ.ACTIVEP 
	     MAILOMAT.TRANSMIT.HARDCOPY MAILOMAT.PERIODIC.WAKEUP)
	(CONSTANTS LAFITETOCHEADERLENGTH LAFITETOCPASSWORD TIME.ACCEPTOR UNSEENFLAG 
		   DELETEDFLAG SEENFLAG UNDELETEDFLAG)
	(VARS MAILOMAT.FORM.FIELDS MAILOMAT.FORM.FORMAT MAILOMAT.FORM.SPECS)
	(INITVARS (MAILOMATBUTTONFONT (FONTCREATE (QUOTE HELVETICA)
						  12
						  (QUOTE BOLD)))
		  (MAILOMATFONT (FONTCREATE (QUOTE TIMESROMAN)
					    8))
		  (MAILOMATBOLDFONT (FONTCREATE (QUOTE HELVETICA)
						10
						(QUOTE BOLD)))
		  [MAILOMAT.USER.LIST (QUOTE ((**% OTHER% **]
		  (MAILOMATFORMTEMPLATE NIL))
	(GLOBALVARS MAILOMATFONT MAILOMATBOLDFONT)
	(ADDVARS (BackgroundMenuCommands ("MAILOMAT Panel" (QUOTE (MAILOMAT.PANEL.CREATE))
							   
						    "Bulk mail process a user's mail")))
	(VARS (BackgroundMenu))
	(MACROS MAILOMAT.ENTRY.PTR.TO.KEY.VAL.PTR MAILOMAT.ENTRY.TO.NUM 
		MAILOMAT.INDEX.DATA.CONTEXT MAILOMAT.KEY.VAL.PTR.TO.ENTRY.PTR 
		MAILOMATSPECGET ARSPECPUT FIXPIN FIXPOUT IMAGEOBJPROPS UCASE.STREQUAL 
		WORDIN WORDOUT)
	(RECORDS MAILOMAT.USERDATA DEFAULTHOST&DIR FSM LAFITEMSG LAFITEOPS LAFITEUSERDATA 
		 MAILFOLDER MAILSERVER MAILSERVEROPS OPENEDMAILBOX TRANSITION)
	(UGLYVARS MAILOMAT.FORM.ICON MAILOMAT.FORM.MASK)
	(RESOURCES SCRATCHSTRING)
	(I.S.OPRS SELECTEDIN)
	(P (MAILOMAT.INIT))))
(* * MAILOMAT.FORM functions and variables)

(DEFINEQ

(MAILOMAT.ADD.USER
  [LAMBDA (FORMWINDOW USERNAME)                       (* mbb "18-Sep-85 04:08")
    (PROG (OLD.USER.DATA ENCODED.USER.DATA USER.DATA STARTIME ENCODEDTIMEUNIT FIRING.MODE 
			 ENCODEDATE TIMEUNIT ACTIVATION TIMEPERIOD)
          (SETQ USER.DATA (MAILOMAT.EXTRACT.FIELDS USERNAME FORMWINDOW))
          (OR (SETQ ENCODED.USER.DATA (MAILOMAT.ENCODE.USER.DATA FORMWINDOW USER.DATA))
	      (RETURN NIL))
          (OR (MAILOMAT.INIT.MAIL.USER ENCODED.USER.DATA)
	      (RETURN (MAILOMAT.PROMPT (LIST "User " USERNAME " not authenticated.")
				       FORMWINDOW)))
          (AND (SETQ OLD.USER.DATA (CDR (ASSOC USERNAME MAILOMAT.USER.LIST)))
	       (replace (MAILOMAT.USERDATA ACTIVATION) of OLD.USER.DATA
		  with (QUOTE Off)))
          [replace (MAILOMAT.USERDATA SERVERPROCESS) of ENCODED.USER.DATA
	     with (AND (EQ (fetch (MAILOMAT.USERDATA ACTIVATION) of ENCODED.USER.DATA)
			   (QUOTE On))
		       (ADD.PROCESS
			 (SELECTQ (fetch (MAILOMAT.USERDATA FIRINGMODE) of 
								    ENCODED.USER.DATA)
				  [Time% of% Day (LIST (FUNCTION 
							 MAILOMAT.TIME.OF.DAY.WAKEUP)
						       (KWOTE ENCODED.USER.DATA)
						       (KWOTE (fetch (MAILOMAT.USERDATA
								       FIRINGTIMES)
								 of ENCODED.USER.DATA]
				  [Fixed% Period
				    (LIST (FUNCTION MAILOMAT.PERIODIC.WAKEUP)
					  (KWOTE ENCODED.USER.DATA)
					  (KWOTE (fetch (MAILOMAT.USERDATA STARTIME)
						    of ENCODED.USER.DATA))
					  (KWOTE (ITIMES (fetch (MAILOMAT.USERDATA 
									   TIMEPERIOD)
							    of ENCODED.USER.DATA)
							 (fetch (MAILOMAT.USERDATA 
									     TIMEUNIT)
							    of ENCODED.USER.DATA]
				  (SHOULDNT))
			 (QUOTE NAME)
			 (PACK (LIST (QUOTE MAILOMAT.PROCESS.)
				     USERNAME]
          (PUTASSOC USERNAME USER.DATA MAILOMAT.USER.LIST)
          (RETURN USER.DATA])

(MAILOMAT.APPEND.TIME
  [LAMBDA (LIST HOUR MINUTE SECOND)                   (* mbb "16-Sep-85 12:15")
    (COND
      [LIST (APPEND LIST (LIST (LIST HOUR MINUTE SECOND]
      (T (LIST (LIST HOUR MINUTE SECOND])

(MAILOMAT.APPENDMESSAGES
  [LAMBDA (FOLDERDATA NEWMESSAGEDESCRIPTORS)          (* mbb "24-Jul-85 20:17")
                                                      (* get the new file length *)
    (PROG ((LASTMSG# (fetch (MAILFOLDER #OFMESSAGES) of FOLDERDATA))
	   FIRSTMSG#)
          (SETQ FIRSTMSG# (ADD1 LASTMSG#))
          [replace (MAILFOLDER FOLDEREOFPTR) of FOLDERDATA
	     with (GETEOFPTR (\LAFITE.OPEN.FOLDER FOLDERDATA (QUOTE INPUT]
          (for MSGDESCRIPTOR in NEWMESSAGEDESCRIPTORS
	     do (replace (LAFITEMSG #) of MSGDESCRIPTOR with (add LASTMSG# 1))
		(LAFITE.PARSE.MSG.FOR.TOC MSGDESCRIPTOR FOLDERDATA))
          (replace (MAILFOLDER #OFMESSAGES) of FOLDERDATA with LASTMSG#)
          (replace (MAILFOLDER MESSAGEDESCRIPTORS) of FOLDERDATA
	     with (\LAFITE.ADDMESSAGES.TO.ARRAY (fetch (MAILFOLDER MESSAGEDESCRIPTORS)
						   of FOLDERDATA)
						NEWMESSAGEDESCRIPTORS FIRSTMSG# LASTMSG#])

(MAILOMAT.ENCODE.PERIODIC.PARAMS
  [LAMBDA (FORMWINDOW RAW.USER.DATA)                  (* mbb "13-Sep-85 05:17")
    (PROG (ENCODEDSTARTIME ENCODEDTIMEUNIT ENCODEDTIMEPERIOD)
          (RETURN (AND (SETQ ENCODEDSTARTIME (MAILOMAT.ENCODE.START.TIME FORMWINDOW 
									RAW.USER.DATA))
		       (SETQ ENCODEDTIMEUNIT (MAILOMAT.ENCODE.TIME.UNIT FORMWINDOW 
									RAW.USER.DATA))
		       (COND
			 ((AND [FIXP (SETQ ENCODEDTIMEPERIOD (MKATOM (fetch (
MAILOMAT.USERDATA TIMEPERIOD) of RAW.USER.DATA]
			       (GREATERP ENCODEDTIMEPERIOD 0))
			   (LIST (QUOTE ENCODEDSTARTIME:)
				 ENCODEDSTARTIME
				 (QUOTE ENCODEDTIMEUNIT:)
				 ENCODEDTIMEUNIT
				 (QUOTE ENCODEDTIMEPERIOD:)
				 ENCODEDTIMEPERIOD))
			 (T (MAILOMAT.PROMPT "Time Period must be a nonnegative integer." 
					     FORMWINDOW])

(MAILOMAT.ENCODE.START.TIME
  [LAMBDA (FORMWINDOW RAW.USER.DATA)                  (* mbb "13-Sep-85 02:55")
    (PROG (ENCODEDATE)
          (RETURN (AND (OR [SETQ ENCODEDATE (IDATE (MKATOM (fetch (MAILOMAT.USERDATA
								    STARTIME)
							      of RAW.USER.DATA]
			   (MAILOMAT.PROMPT 
				  "Bad Start Time format, use %"DD-MMM-YY HH:MM:SS%""
					    FORMWINDOW))
		       (COND
			 ((LESSP ENCODEDATE (IPLUS (IDATE)
						   30))
			   (MAILOMAT.PROMPT "Specify a later Start Time." FORMWINDOW))
			 (T ENCODEDATE])

(MAILOMAT.ENCODE.TIME.UNIT
  [LAMBDA (FORMWINDOW RAW.USER.DATA)                  (* mbb "13-Sep-85 03:10")
    (SELECTQ (MKATOM (fetch (MAILOMAT.USERDATA TIMEUNIT) of RAW.USER.DATA))
	     ((QUOTE Days)
	       (ITIMES 24 60 60 1000))
	     ((QUOTE Hours)
	       (ITIMES 60 60 1000))
	     ((QUOTE Minutes)
	       (ITIMES 60 1000))
	     (MAILOMAT.PROMPT "No Time Unit is selected." FORMWINDOW])

(MAILOMAT.ENCODE.TOD.PARAMS
  [LAMBDA (FORMWINDOW RAW.USER.DATA)                  (* mbb "17-Sep-85 22:13")
    (COND
      [(SORT (for TIME in (MAILOMAT.PARSE.TIME (fetch (MAILOMAT.USERDATA FIRINGTIMES)
						  of RAW.USER.DATA))
		collect (PLUS (ITIMES 3600 (CAR TIME))
			      (ITIMES 60 (CADR TIME))
			      (CADDR TIME]
      (T (MAILOMAT.PROMPT "Bad Firing Times." FORMWINDOW])

(MAILOMAT.ENCODE.USER.DATA
  [LAMBDA (FORMWINDOW RAW.USER.DATA)                  (* mbb "17-Sep-85 22:22")
    (PROG (ENCODED.USER.DATA ACTIVATION FIRING.MODE ENCODEDPERIODICPARAMS 
			     ENCODEDFIRINGTIMES HARDCOPY)
          (SELECTC (SETQ ACTIVATION (MKATOM (fetch (MAILOMAT.USERDATA ACTIVATION)
					       of USER.DATA)))
		   ((MKATOM "")
		     (MAILOMAT.PROMPT "No Activation selected." FORMWINDOW)
		     (RETURN NIL))
		   ((QUOTE Off)
		     NIL)
		   [(QUOTE On)
		     (SELECTQ (SETQ FIRINGMODE (MKATOM (fetch (MAILOMAT.USERDATA 
									   FIRINGMODE)
							  of USER.DATA)))
			      (Fixed% Period (if (NULL (SETQ ENCODEDPERIODICPARAMS
							 (MAILOMAT.ENCODE.PERIODIC.PARAMS
							   FORMWINDOW RAW.USER.DATA)))
						 then (RETURN NIL)))
			      (Time% of% Day (if (NULL (SETQ ENCODEDFIRINGTIMES
							 (MAILOMAT.ENCODE.TOD.PARAMS
							   FORMWINDOW RAW.USER.DATA)))
						 then (RETURN NIL)))
			      (SHOULDNT))
		     (if [EQ (QUOTE Yes)
			     (SETQ HARDCOPY (MKATOM (fetch (MAILOMAT.USERDATA HARDCOPY)
						       of USER.DATA]
			 then (OR (CH.LOOKUP.OBJECT (fetch (MAILOMAT.USERDATA PRINTSERVER)
						       of RAW.USER.DATA))
				  (RETURN (MAILOMAT.PROMPT (LIST 
							    "Unknown Print Server %""
								 (fetch (MAILOMAT.USERDATA
									  PRINTSERVER)
								    of RAW.USER.DATA)
								 "%"")
							   FORMWINDOW]
		   (SHOULDNT))
          (RETURN (create MAILOMAT.USERDATA
		     copying RAW.USER.DATA FIRINGMODE ← FIRINGMODE FIRINGTIMES ← 
			     ENCODEDFIRINGTIMES STARTIME ←(LISTGET ENCODEDPERIODICPARAMS
								   (QUOTE 
								     ENCODEDSTARTIME:))
			     TIMEPERIOD ←(LISTGET ENCODEDPERIODICPARAMS (QUOTE 
								   ENCODEDTIMEPERIOD:))
			     TIMEUNIT ←(LISTGET ENCODEDPERIODICPARAMS (QUOTE 
								     ENCODEDTIMEUNIT:))
			     ACTIVATION ← ACTIVATION HARDCOPY ← HARDCOPY])

(MAILOMAT.EXTRACT.FIELDS
  [LAMBDA (USERNAME FORMWINDOW)                       (* mbb "13-Sep-85 05:07")
    (create MAILOMAT.USERDATA
	    USERNAME ← USERNAME
	    PASSWORD ←(WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.PASSWORD))
	    MAILFOLDER ←(U-CASE (MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW
								   (QUOTE Mail% Folder:)))
	    FIRINGMODE ←(MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL FORMWINDOW (QUOTE 
									Firing% Mode:))
	    FIRINGTIMES ←(MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW (QUOTE 
								       Firing% Times:))
	    STARTIME ←(MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW (QUOTE Start% Time:))
	    TIMEPERIOD ←(MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW (QUOTE 
									Time% Period:))
	    TIMEUNIT ←(MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL FORMWINDOW (QUOTE 
									  Time% Unit:))
	    ACTIVATION ←(MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL FORMWINDOW (QUOTE 
									  Activation:))
	    HARDCOPY ←(MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL FORMWINDOW (QUOTE 
									    Hardcopy:))
	    PRINTSERVER ←(U-CASE (MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW
								    (QUOTE Print% Server:]
)

(MAILOMAT.HARDCOPY
  [LAMBDA (MAILFOLDER USER.DATA)                      (* mbb "16-Sep-85 11:20")
    (PROG (LCASEFILENAME TEXTSTREAM MSGLIST)
          (SETQ MSGLIST (for MSGDESCRIPTOR selectedin MAILFOLDER collect MSGDESCRIPTOR))
          (SETQ LCASEFILENAME (L-CASE (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER)))
          [SETQ TEXTSTREAM (COND
	      ((AND LAFITEHARDCOPY.MIN.TOC (IGEQ (LENGTH MSGLST)
						 LAFITEHARDCOPY.MIN.TOC))
		(\LAFITE.HARDCOPY.HEADERS MAILFOLDER LCASEFILENAME MSGLST))
	      (T (OPENTEXTSTREAM "" NIL NIL NIL (LIST (QUOTE FONT)
						      LAFITEHARDCOPYFONT]
          (\LAFITE.HARDCOPY.BODIES MAILFOLDER TEXTSTREAM MSGLIST)
          (MAILOMAT.TRANSMIT.HARDCOPY MAILFOLDER TEXTSTREAM MSGLIST LCASEFILENAME 
				      USER.DATA])

(MAILOMAT.MENU.FN.PUT
  [LAMBDA (FORM.WINDOW)                               (* mbb "18-Sep-85 03:10")
    (PROG (MAILOMAT.DIRECTORY PROFILE.NAME USERNAME USER.LIST)
          (if (NULL (SETQ USERNAME (MAILOMAT.INFER.USERNAME FORM.WINDOW)))
	      then (MAILOMAT.PROMPT (LIST "Put failed for user " USERNAME " ...")
				    FORMWINDOW)
		   (RETURN))
          (MAILOMAT.PROMPT (LIST "Storing data for user " USERNAME " ...")
			   FORMWINDOW)
          (SETQ USER.DATA (MAILOMAT.EXTRACT.FIELDS USERNAME FORMWINDOW))
          (SETQ MAILOMAT.DIRECTORY (OR LAFITEDEFAULTHOST&DIR (MKATOM LOGINHOST/DIR)))
          (SETQ PROFILE.NAME (PACKFILENAME (QUOTE BODY)
					   MAILOMAT.DIRECTORY
					   (QUOTE NAME)
					   (QUOTE MAILOMAT-PROFILE)
					   (QUOTE VERSION)
					   1))
          [COND
	    [(MEMB PROFILE.NAME (DIRECTORY MAILOMAT.DIRECTORY))
	      (SETQ PROFILE.STREAM (OPENSTREAM PROFILE.NAME (QUOTE BOTH)))
	      (SETQ USER.LIST (READ PROFILE.STREAM))
	      (CLOSEF PROFILE.NAME)
	      (DELFILE PROFILE.NAME)
	      (SETQ PROFILE.STREAM (OPENSTREAM PROFILE.NAME (QUOTE BOTH]
	    (T (SETQ PROFILE.STREAM (OPENSTREAM PROFILE.NAME (QUOTE BOTH)))
	       (SETQ USER.LIST (LIST (LIST (fetch (MAILOMAT.USERDATA USERNAME)
					      of USER.DATA)
					   NIL]
          (PUTASSOC USERNAME USER.DATA USER.LIST)
          (PRINT USER.LIST PROFILE.STREAM)
          (CLOSEF PROFILE.NAME)
          (MAILOMAT.PROMPT (LIST "MAILOMAT user data for " USERNAME " stored.")
			   FORMWINDOW)
          (TEDIT.STREAMCHANGEDP FORM.WINDOW T])

(MAILOMAT.INFER.USERNAME
  [LAMBDA (FORMWINDOW)                                (* mbb "17-Sep-85 17:36")
    (PROG [(USERNAME (OR (WINDOWPROP FORMWINDOW (QUOTE USERNAME))
			 (U-CASE (MKATOM (MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW
									    (QUOTE 
									    Username:]
          (if (EQ 0 (NCHARS USERNAME))
	      then (SETQ USERNAME (U-CASE (MAILOMAT.GET.USERNAME FORMWINDOW)))
		   (if USERNAME
		       then (MAILOMAT.REPLACE.FILL.INS FORMWINDOW
						       (LIST (LIST (QUOTE Username:)
								   USERNAME)))
			    (WINDOWPROP FORMWINDOW (QUOTE USERNAME)
					USERNAME)
			    (RETURN USERNAME)
		     else (MAILOMAT.PUT.FAILED "Bad username --- Try again" FORMWINDOW)
			  (RETURN))
	    else (WINDOWPROP FORMWINDOW (QUOTE USERNAME)
			     USERNAME)
		 (RETURN USERNAME])

(MAILOMAT.UPDATECONTENTSFILE
  [LAMBDA (MAILFOLDER LASTUNCHANGEDMESSAGE#)          (* mbb "10-Sep-85 16:34")
                                                      (* Update the TOC file for MAILFOLDER, assuming that entries 
						      up to LASTUNCHANGEDMESSAGE# are okay.)
    (RESETLST (PROG ((TOCFILE (TOCFILENAME (fetch (MAILFOLDER FULLFOLDERNAME)
					      of MAILFOLDER)))
		     (MESSAGES (fetch (MAILFOLDER MESSAGEDESCRIPTORS) of MAILFOLDER))
		     (TOCSTART LAFITETOCHEADERLENGTH)
		     (LASTMSG# (fetch (MAILFOLDER #OFMESSAGES) of MAILFOLDER))
		     FIRSTMSG# TOCSTREAM MSG)
		    (COND
		      ((IGREATERP LASTMSG# 0)
			[RESETSAVE NIL (LIST [FUNCTION (LAMBDA (STREAM)
						 (SETQ STREAM (CLOSEF STREAM))
						 (AND RESETSTATE (DELFILE STREAM]
					     (SETQ TOCSTREAM (OPENSTREAM
						 TOCFILE
						 (QUOTE BOTH)
						 (QUOTE OLD/NEW)
						 NIL
						 (QUOTE ((TYPE BINARY]
			(WHENCLOSE TOCSTREAM (QUOTE CLOSEALL)
				   (QUOTE NO))
			(SETQ LASTUNCHANGEDMESSAGE# (IMIN LASTUNCHANGEDMESSAGE#
							  (fetch (MAILFOLDER 
								      TOCLASTMESSAGE#)
							     of MAILFOLDER)))
			(replace (MAILFOLDER TOCLASTMESSAGE#) of MAILFOLDER with 0)
			[COND
			  ((ZEROP (GETEOFPTR TOCSTREAM))
			    (SETQ LASTUNCHANGEDMESSAGE# 0))
			  ((AND (ZEROP LASTUNCHANGEDMESSAGE#)
				(NEQ (PROGN (SETFILEPTR TOCSTREAM BYTESPERWORD)
					    (WORDIN TOCSTREAM))
				     LAFITEVERSION#))
                                                      (* A version number change, rewrite entire toc)
			    )
			  (T                          (* TOC already existed, just update it)
			     (for MSG# from 1 to LASTUNCHANGEDMESSAGE#
				do (COND
				     ((fetch (LAFITEMSG MARKSCHANGED?)
					 of (SETQ MSG (NTHMESSAGE MESSAGES MSG#)))
                                                      (* Message not compacted out, but its mark bytes have changed)
				       (SETFILEPTR TOCSTREAM (IPLUS TOCSTART 
							      LAFITETOCMARKBYTEOFFSET))
				       (WRITETOCMARKBYTES MSG TOCSTREAM)
				       (replace (LAFITEMSG MARKSCHANGED?) of MSG
					  with NIL)))
				   (add TOCSTART (fetch (LAFITEMSG TOCLENGTH)
						    of MSG]
			(SETFILEPTR TOCSTREAM TOCSTART)
			(for MSG# from (ADD1 LASTUNCHANGEDMESSAGE#) to LASTMSG#
			   do (WRITETOCENTRY (NTHMESSAGE MESSAGES MSG#)
					     TOCSTREAM))
			(SETFILEINFO TOCSTREAM (QUOTE LENGTH)
				     (GETFILEPTR TOCSTREAM))
			(SETFILEPTR TOCSTREAM 0)      (* Now write the header info)
			(WORDOUT TOCSTREAM LAFITETOCPASSWORD)
			(WORDOUT TOCSTREAM LAFITEVERSION#)
			(FIXPOUT TOCSTREAM (fetch (MAILFOLDER FOLDEREOFPTR) of MAILFOLDER)
				 )
			(WORDOUT TOCSTREAM LASTMSG#))
		      ((SETQ TOCFILE (INFILEP TOCFILE))
			(DELFILE TOCFILE)))
		    (replace (MAILFOLDER TOCLASTMESSAGE#) of MAILFOLDER with LASTMSG#)
		    (replace (MAILFOLDER BROWSERPROMPTDIRTY) of MAILFOLDER with T)
		    (replace (MAILFOLDER FOLDERNEEDSUPDATE) of MAILFOLDER with NIL])

(MAILOMAT.UPDATEMAILFOLDER
  [LAMBDA (MAILFOLDER)                                (* mbb "10-Sep-85 16:33")

          (* * Write out any changed marks in MAILFOLDER, but don't expunge deleted messages)


    (PROG ((MESSAGES (fetch (MAILFOLDER MESSAGEDESCRIPTORS) of MAILFOLDER))
	   OUTSTREAM MSG)
          (replace (MAILFOLDER BROWSERPROMPTDIRTY) of MAILFOLDER with T)
          [for MSG# from 1 to (fetch (MAILFOLDER #OFMESSAGES) of MAILFOLDER)
	     do (COND
		  ((fetch (LAFITEMSG MARKSCHANGED?) of (SETQ MSG (NTHMESSAGE MESSAGES 
									     MSG#)))
		    (WRITEFOLDERMARKBYTES MSG MAILFOLDER (OR OUTSTREAM
							     (SETQ OUTSTREAM
							       (\LAFITE.OPEN.FOLDER
								 MAILFOLDER
								 (QUOTE OUTPUT]
          (\LAFITE.CLOSE.FOLDER MAILFOLDER])

(MAILOMAT.BLANKP
  [LAMBDA (CHAR ACCEPTOR)                             (* mbb "16-Sep-85 11:56")
    (MEMB CHAR (fetch (FSM BLANKS) of ACCEPTOR])

(MAILOMAT.BUTTON.GET.MENU
  [LAMBDA (OBJ)                                       (* mbb "16-Jul-85 23:56")
    (if (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PANEL.CREATE))
      else [IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PANEL.CREATE)
			 (create MENU
				 ITEMS ←[APPEND (IMAGEOBJPROP OBJ (QUOTE 
								   MAILOMAT.MENU.LIST))
						(LIST (LIST NIL (KWOTE (PACKC]
				 TITLE ←(IMAGEOBJPROP OBJ (QUOTE MBTEXT]
	   (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PANEL.CREATE])

(MAILOMAT.BUTTON.GET.SUBMENU
  [LAMBDA (OBJ ASSOCIATED.MENU.VAL)                   (* mjs "20-Apr-84 15:02")
    (if (LISTGET (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.SUBMENUS))
		 ASSOCIATED.MENU.VAL)
      else (PROG ((CORRESPONDING.SUBMENU.LIST (LISTGET (IMAGEOBJPROP OBJ (QUOTE 
								MAILOMAT.SUBMENU.LIST))
						       ASSOCIATED.MENU.VAL))
		  CORRESPONDING.SUBMENU)
	         [SETQ CORRESPONDING.SUBMENU (create
		     MENU
		     ITEMS ←[APPEND CORRESPONDING.SUBMENU.LIST
				    (LIST (LIST NIL (KWOTE (PACKC]
		     TITLE ←(IMAGEOBJPROP OBJ (QUOTE MBTEXT]
	         (if (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.SUBMENUS))
		     then (LISTPUT (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.SUBMENUS))
				   ASSOCIATED.MENU.VAL CORRESPONDING.SUBMENU)
		   else (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.SUBMENUS)
				      (LIST ASSOCIATED.MENU.VAL CORRESPONDING.SUBMENU)))
	         (RETURN CORRESPONDING.SUBMENU])

(MAILOMAT.BUTTON.OBJ.CREATE
  [LAMBDA (MAILOMAT.SPECS BUTTON.NAME BUTTON.FONT)    (* edited: "21-Aug-84 14:39")
    (PROG ((BUTTON.TYPE (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME (QUOTE FIELDTYPE)))
	   BUTTON.FN OBJ)
          (if (AND (EQ BUTTON.TYPE (QUOTE STRING))
		   (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME (QUOTE MAXCHARS)))
	      then                                    (* if a string has a max length given, treat it as a 
						      SHORTSTRING)
		   (SETQ BUTTON.TYPE (QUOTE SHORTSTRING)))
          [SETQ BUTTON.FN (if (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME (QUOTE FN))
			    else (SELECTQ BUTTON.TYPE
					  (BUTTON (MAILOMATSPECGET MAILOMAT.SPECS 
								   BUTTON.NAME
								   (QUOTE FN)))
					  (PROTECTEDSTRING (FUNCTION 
							     MAILOMAT.PROTECT.WARNING))
					  ((STRING SHORTSTRING)
					    (FUNCTION MAILOMAT.BUTTONFN.SELFIELD))
					  (MENU (FUNCTION MAILOMAT.BUTTONFN.DOMENU))
					  (SUBMENU (FUNCTION MAILOMAT.BUTTONFN.DOSUBMENU))
					  (ERROR "Bad Button Type" BUTTON.TYPE]
          (SETQ BUTTON.FONT (if (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME (QUOTE FONT))
			      else BUTTON.FONT))
          (SETQ OBJ (MBUTTON.CREATE BUTTON.NAME BUTTON.FN BUTTON.FONT))
          (IMAGEOBJPROPS OBJ (QUOTE MAILOMAT.PRE.FIELD)
			 (SELECTQ BUTTON.TYPE
				  (BUTTON "")
				  ((MENU SUBMENU)
				    "  {")
				  "  ")
			 (QUOTE MAILOMAT.POST.FIELD)
			 (SELECTQ BUTTON.TYPE
				  ((MENU SUBMENU)
				    "}")
				  "")
			 (QUOTE MAILOMAT.CHECK.FN)
			 (SELECTQ BUTTON.TYPE
				  ((BUTTON PROTECTEDSTRING STRING)
				    (FUNCTION NILL))
				  (SHORTSTRING (FUNCTION MAILOMAT.CHECK.SHORTSTRING))
				  (MENU (FUNCTION MAILOMAT.CHECK.MENU))
				  (SUBMENU (FUNCTION MAILOMAT.CHECK.SUBMENU))
				  (ERROR "Bad Button Type" BUTTON.TYPE))
			 (QUOTE MAILOMAT.PROTECTED.FLG)
			 (SELECTQ BUTTON.TYPE
				  ((BUTTON PROTECTEDSTRING MENU SUBMENU)
				    T)
				  NIL))
          (SELECTQ BUTTON.TYPE
		   [SHORTSTRING (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.MAX.LEN)
					      (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME
							       (QUOTE MAXCHARS]
		   [MENU (IMAGEOBJPROPS OBJ (QUOTE MAILOMAT.ASSOCIATED.SUBMENU)
					(MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME
							 (QUOTE ASSOCSUBMENU))
					(QUOTE MAILOMAT.MENU.LIST)
					(MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME
							 (QUOTE MENULIST]
		   [SUBMENU (IMAGEOBJPROPS OBJ (QUOTE MAILOMAT.ASSOCIATED.MENU)
					   (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME
							    (QUOTE ASSOCMENU))
					   (QUOTE MAILOMAT.SUBMENU.LIST)
					   (MAILOMATSPECGET MAILOMAT.SPECS BUTTON.NAME
							    (QUOTE SUBMENULIST]
		   NIL)
          (RETURN OBJ])

(MAILOMAT.BUTTONFN.DOMENU
  [LAMBDA (OBJ SEL WINDOW)                            (* edited: "30-Aug-84 09:57")
    (PROG [(STREAM (WINDOWPROP WINDOW (QUOTE TEXTSTREAM)))
	   (NEWVAL (MENU (MAILOMAT.BUTTON.GET.MENU OBJ)))
	   (ASSOC.SUBMENU (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.ASSOCIATED.SUBMENU]
          [if [AND NEWVAL (NOT (EQUAL NEWVAL (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.VALUE]
	      then (MAILOMAT.REPLACE.FIELD.VAL OBJ (fetch (SELECTION CH#) of SEL)
					       STREAM NEWVAL)
		   (if ASSOC.SUBMENU
		       then (PROG ((BUTTON (MAILOMAT.FIND.BUTTON STREAM ASSOC.SUBMENU)))
			          (if (NULL BUTTON)
				      then (ERROR "Can't find associated submenu button" 
						  ASSOC.SUBMENU))
			          (MAILOMAT.REPLACE.FIELD.VAL (CAR BUTTON)
							      (CDR BUTTON)
							      STREAM
							      (PACKC))
			          (IMAGEOBJPROP (CAR BUTTON)
						(QUOTE MAILOMAT.ASSOCIATED.MENU.VAL)
						NEWVAL]
          (MAILOMAT.RESET.SEL WINDOW])

(MAILOMAT.BUTTONFN.DOSUBMENU
  [LAMBDA (OBJ SEL WINDOW)                            (* edited: "30-Aug-84 09:57")
    (PROG ((STREAM (WINDOWPROP WINDOW (QUOTE TEXTSTREAM)))
	   (ASSOCIATED.MENU.VAL (MAILOMAT.GET.ASSOCIATED.MENU.VAL OBJ WINDOW))
	   NEWVAL)
          (SETQ NEWVAL (MENU (MAILOMAT.BUTTON.GET.SUBMENU OBJ ASSOCIATED.MENU.VAL)))
          (if [AND NEWVAL (NOT (EQUAL NEWVAL (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.VALUE]
	      then (MAILOMAT.REPLACE.FIELD.VAL OBJ (fetch (SELECTION CH#) of SEL)
					       STREAM NEWVAL))
          (MAILOMAT.RESET.SEL WINDOW])

(MAILOMAT.BUTTONFN.SELFIELD
  [LAMBDA (OBJ SEL WINDOW)                            (* edited: "30-Aug-84 09:59")
    (PROG ((TOBJ (fetch (SELECTION \TEXTOBJ) of SEL))
	   FIELD.SEL FIELD.CH# FIELD.LEN)
          (MBUTTON.FIND.NEXT.FIELD TOBJ (fetch (SELECTION CH#) of SEL))
          (SETQ FIELD.SEL (fetch (TEXTOBJ SCRATCHSEL) of TOBJ))
          (SETQ FIELD.CH# (fetch (SELECTION CH#) of FIELD.SEL))
          (SETQ FIELD.LEN (fetch (SELECTION DCH) of FIELD.SEL))
          (TEDIT.SETSEL TOBJ FIELD.CH# FIELD.LEN (QUOTE LEFT)
			T])

(MAILOMAT.CHECK.FIELDS
  [LAMBDA (FORMWINDOW)                                (* edited: "27-Jul-84 10:49")
    (PROG ([TOBJ (TEXTOBJ (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM]
	   (CH# 0)
	   (CHECK.VALUE NIL)
	   OBJ BUTTON SEL FIELD.CH# FIELD.LEN)
          (while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do (BLOCK)
		(SETQ OBJ (CAR BUTTON))
		(SETQ CH# (CDR BUTTON))
		(if (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PROTECTED.FLG))
		    then (SETQ FIELD.CH# (IPLUS (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.START))
						CH#))
			 (SETQ FIELD.LEN (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.LEN)))
		  else (SETQ SEL (MBUTTON.FIND.NEXT.FIELD TOBJ CH#))
		       (SETQ FIELD.CH# (fetch (SELECTION CH#) of SEL))
		       (SETQ FIELD.LEN (fetch (SELECTION DCH) of SEL)))
	     repeatuntil (SETQ CHECK.VALUE (APPLY* (IMAGEOBJPROP OBJ (QUOTE 
								    MAILOMAT.CHECK.FN))
						   FORMWINDOW OBJ CH# FIELD.CH# FIELD.LEN)
			   ))
          (if CHECK.VALUE
	      then (RETURN (APPEND (LIST "Bad value for field [" (IMAGEOBJPROP
					   OBJ
					   (QUOTE MBTEXT))
					 "] --- ")
				   CHECK.VALUE))
	    else (RETURN NIL])

(MAILOMAT.CHECK.MENU
  [LAMBDA (FORMWINDOW OBJ CH# FIELD.CH# FIELD.LEN)    (* mbb "16-Jul-85 23:56")
    (PROG ((CLIST NIL)
	   (TSTREAM (TEXTSTREAM FORMWINDOW))
	   VAL)
          (SETFILEPTR TSTREAM (SUB1 FIELD.CH#))
          (SETQ CLIST (for X from 1 to FIELD.LEN until (EOFP TSTREAM)
			 collect (BIN TSTREAM)))
          (if (EOFP TSTREAM)
	      then (SHOULDNT "Reached end of textstream while retrieving menu value"))
          (if (NULL CLIST)
	      then                                    (* a null menu value of always correct)
		   (RETURN NIL))
          (SETQ VAL (PACKC CLIST))
          (if (MEMB VAL (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.MENU.LIST)))
	      then (RETURN NIL)
	    else (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PANEL.CREATE)
			       NIL)
		 (RETURN (LIST "bad menu value: " VAL " --- please reset"])

(MAILOMAT.CHECK.SHORTSTRING
  [LAMBDA (FORMWINDOW OBJ CH# FIELD.CH# FIELD.LEN)    (* edited: "27-Jul-84 10:51")
    (if (ILEQ FIELD.LEN (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.MAX.LEN)))
	then NIL
      else (LIST "max length= " (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.MAX.LEN))
		 "; current length= " FIELD.LEN])

(MAILOMAT.CHECK.SUBMENU
  [LAMBDA (FORMWINDOW OBJ CH# FIELD.CH# FIELD.LEN)    (* edited: "21-Aug-84 14:42")
    (PROG ((CLIST NIL)
	   (TSTREAM (TEXTSTREAM FORMWINDOW))
	   VAL)
          (SETFILEPTR TSTREAM (SUB1 FIELD.CH#))
          (SETQ CLIST (for X from 1 to FIELD.LEN until (EOFP TSTREAM)
			 collect (BIN TSTREAM)))
          (if (EOFP TSTREAM)
	      then (SHOULDNT "Reached end of textstream while retrieving submenu value"))
          (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.ASSOCIATED.MENU.VAL)
			NIL)
          (if (NULL CLIST)
	      then                                    (* a null menu value of always correct)
		   (RETURN NIL))
          (SETQ VAL (PACKC CLIST))
          (if (MEMB VAL (LISTGET (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.SUBMENU.LIST))
				 (MAILOMAT.GET.ASSOCIATED.MENU.VAL OBJ FORMWINDOW)))
	      then (RETURN NIL)
	    else (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.SUBMENUS)
			       NIL)
		 (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.ASSOCIATED.MENU.VAL)
			       NIL)
		 (RETURN (LIST "bad menu value: " VAL " --- please reset"])

(MAILOMAT.CONFIRM
  [LAMBDA (WORDS FORMWINDOW)                          (* mjs " 4-May-84 14:51")
    (MAILOMAT.PROMPT WORDS FORMWINDOW)
    (MOUSECONFIRM NIL NIL (GETPROMPTWINDOW FORMWINDOW 2])

(MAILOMAT.DELETE.FIELD.VAL
  [LAMBDA (OBJ CH# WINDOW)                            (* edited: "30-Aug-84 09:57")
    (PROG ((STREAM (WINDOWPROP WINDOW (QUOTE TEXTSTREAM)))
	   SEL)
          (if (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PROTECTED.FLG))
	      then (TEDIT.DELETE STREAM (IPLUS (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.START))
					       CH#)
				 (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.LEN)))
		   (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.LEN)
				 0)
		   (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.VALUE)
				 (PACKC))
	    else (SETQ SEL (MBUTTON.FIND.NEXT.FIELD (TEXTOBJ STREAM)
						    CH#))
		 (if (NULL SEL)
		     then (SHOULDNT "Can't find field for button"))
		 (TEDIT.DELETE STREAM (fetch (SELECTION CH#) of SEL)
			       (fetch (SELECTION DCH) of SEL])

(MAILOMAT.DISCONNECT.WINDOW
  [LAMBDA (FORMWINDOW)                                (* mjs "17-Feb-85 16:03")
    (replace (TEXTOBJ \WINDOW) of (TEXTOBJ (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM)))
       with NIL])

(MAILOMAT.FIND.BUTTON
  [LAMBDA (WINDOW NAME)                               (* edited: "30-Aug-84 09:57")
    (PROG ((TOBJ (TEXTOBJ WINDOW))
	   (CH# 0)
	   OBJ BUTTON)
          [while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do (SETQ OBJ (CAR BUTTON))
		(SETQ CH# (CDR BUTTON))
	     repeatuntil (EQ NAME (IMAGEOBJPROP OBJ (QUOTE MBTEXT]
          (RETURN BUTTON])

(MAILOMAT.FIND.EDIT.CHANGES
  [LAMBDA (FORMWINDOW)                                (* edited: "22-Aug-84 16:09")
    (PROG ((SCRATCH.STREAM (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.STREAM)))
	   (SCRATCH.MAP (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.MAP)))
	   (FORMSTREAM (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM)))
	   (CH# 0)
	   OBJ BUTTON BUTTON.NAME PROTECT.FIELD.FLG FIELD.CH# FIELD.LEN TOBJ 
	   SCRATCH.MAP.SPEC SCRATCH.PTR SCRATCH.FIELD.LEN (EDIT.CHANGES NIL))
          (if (NULL SCRATCH.MAP)
	      then (RETURN NIL))
          (SETQ TOBJ (TEXTOBJ FORMSTREAM))
          [while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do
	      (BLOCK)
	      (SETQ OBJ (CAR BUTTON))
	      (SETQ CH# (CDR BUTTON))
	      (SETQ BUTTON.NAME (IMAGEOBJPROP OBJ (QUOTE MBTEXT)))
	      (SETQ PROTECT.FIELD.FLG (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PROTECTED.FLG)))
	      [if PROTECT.FIELD.FLG
		  then (SETQ FIELD.CH# (IPLUS (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.START))
					      CH#))
		       (SETQ FIELD.LEN (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.LEN)))
		else (PROG ((SEL (MBUTTON.FIND.NEXT.FIELD TOBJ CH#)))
		           (if (NULL SEL)
			       then (SHOULDNT "Can't find field for button"))
		           (SETQ FIELD.CH# (fetch (SELECTION CH#) of SEL))
		           (SETQ FIELD.LEN (fetch (SELECTION DCH) of SEL]
	      (SETFILEPTR FORMSTREAM (SUB1 FIELD.CH#))
	      (SETQ SCRATCH.MAP.SPEC (ASSOC BUTTON.NAME SCRATCH.MAP)) 
                                                      (* note that you default to a zero-length field if it is not 
						      specified in the file)
	      (SETQ SCRATCH.PTR (if (CADR SCRATCH.MAP.SPEC)
				  else 0))
	      (SETQ SCRATCH.FIELD.LEN (if (CADDR SCRATCH.MAP.SPEC)
					else 0))
	      (if [OR (NOT (EQP FIELD.LEN SCRATCH.FIELD.LEN))
		      (NOT (for X from 1 to FIELD.LEN
			      first (SETFILEPTR FORMSTREAM (SUB1 FIELD.CH#))
				    (SETFILEPTR SCRATCH.STREAM SCRATCH.PTR)
			      always (EQ (BIN FORMSTREAM)
					 (BIN SCRATCH.STREAM]
		  then                                (* we know that the current value of the field is not equal to
						      the value when loaded)
		   (push EDIT.CHANGES BUTTON.NAME)
		   (if (MEMB (MAILOMATSPECGET MAILOMAT.FORM.SPECS BUTTON.NAME
					      (QUOTE FIELDTYPE))
			     (QUOTE (MENU SUBMENU)))
		       then
			(push EDIT.CHANGES
			      (LIST (PACKC (NCONC (for X from 1 to SCRATCH.FIELD.LEN
						     first (SETFILEPTR SCRATCH.STREAM 
								       SCRATCH.PTR)
						     collect (BIN SCRATCH.STREAM))
						  (APPEND (CHARCODE (- >)))
						  (NCONC (for X from 1 to FIELD.LEN
							    first (SETFILEPTR
								    FORMSTREAM
								    (SUB1 FIELD.CH#))
							    collect (BIN FORMSTREAM]
          (RETURN (DREVERSE EDIT.CHANGES])

(MAILOMAT.FIND.UNPROTECTED.CH#
  [LAMBDA (STREAM)                                    (* edited: "21-Aug-84 14:41")
    (PROG ((TOBJ (TEXTOBJ STREAM))
	   (CH# 0)
	   OBJ BUTTON SEL)
          (while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do (SETQ OBJ (CAR BUTTON))
		(SETQ CH# (CDR BUTTON))
	     repeatwhile (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PROTECTED.FLG)))
          (if (NULL BUTTON)
	      then (SHOULDNT "Can't find unprotected button field"))
          (SETQ SEL (MBUTTON.FIND.NEXT.FIELD TOBJ CH#))
          (RETURN (fetch (SELECTION CH#) of SEL])

(MAILOMAT.FORM.CLEAR
  [LAMBDA (FORMWINDOW FILL.INS)                       (* edited: " 7-Jun-84 14:21")
    (PROG ([TOBJ (TEXTOBJ (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM]
	   (CH# 0)
	   OBJ BUTTON)
          (while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do (BLOCK)
		(SETQ OBJ (CAR BUTTON))
		(SETQ CH# (CDR BUTTON))
		(MAILOMAT.DELETE.FIELD.VAL OBJ CH# FORMWINDOW))
          (MAILOMAT.REPLACE.FILL.INS FORMWINDOW FILL.INS)
          (TEDIT.STREAMCHANGEDP (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM))
				T])

(MAILOMAT.FORM.CREATE
  [LAMBDA (FORMWINDOW BUTTONFONT FORM.SPECS FORM.FORMAT)
                                                      (* mbb "17-Sep-85 18:56")
    (PROG [(FORMSTREAM (OPENTEXTSTREAM "" NIL NIL NIL (LIST (QUOTE FONT)
							    MAILOMATFONT
							    (QUOTE TEDIT.TENTATIVE)
							    NIL)))
	   (TABS 0)
	   (TAB.CH# NIL)
	   (MAILOMAT.PARALOOKS NIL)
	   (MAILOMAT.CHARLOOKS NIL)
	   (FORMWINDOW.WIDTH (WINDOWPROP FORMWINDOW (QUOTE WIDTH]
          (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.STREAM)
		      NIL)
          (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.TEDIT.TITLEMENUFN)
		      (FUNCTION NILL))
          [for FIELD.OR.SPACE in FORM.FORMAT
	     do (BLOCK)
		(if (EQ FIELD.OR.SPACE (QUOTE TAB))
		    then (SETQ TAB.CH# (ADD1 (GETFILEPTR FORMSTREAM)))
			 (BOUT FORMSTREAM (CHARCODE TAB))
			 (add TABS 1)
		  elseif (EQ FIELD.OR.SPACE (QUOTE CR))
		    then (if (IGREATERP TABS 0)
			     then (push MAILOMAT.PARALOOKS
					[LIST (QUOTE TABS)
					      (CONS NIL
						    (for I from 1 to TABS
						       bind (TABWIDTH
							      ←(IQUOTIENT 
								     FORMWINDOW.WIDTH
									  (ADD1 TABS)))
						       collect (CONS (ITIMES I TABWIDTH)
								     (QUOTE LEFT]
					TAB.CH# 1))
			 (SETQ TABS 0)
			 (BOUT FORMSTREAM (CHARCODE CR))
		  elseif (STRINGP FIELD.OR.SPACE)
		    then (PRIN1 FIELD.OR.SPACE FORMSTREAM)
		  else (PROG ((BUTTON.OBJ (MAILOMAT.BUTTON.OBJ.CREATE FORM.SPECS 
								      FIELD.OR.SPACE 
								      BUTTONFONT))
			      (CH# (ADD1 (GETFILEPTR FORMSTREAM)))
			      PRE.FIELD.NCHARS POST.FIELD.NCHARS FIELD.LEN)
			     (BLOCK)
			     (TEDIT.INSERT.OBJECT BUTTON.OBJ FORMSTREAM CH#)
			     (push MAILOMAT.CHARLOOKS (QUOTE (PROTECTED OFF))
				   CH# 1)
			     (add CH# 1)
			     (SETFILEPTR FORMSTREAM (SUB1 CH#))
			     (PRIN1 (IMAGEOBJPROP BUTTON.OBJ (QUOTE MAILOMAT.PRE.FIELD))
				    FORMSTREAM)
			     (SETQ PRE.FIELD.NCHARS (IDIFFERENCE (ADD1 (GETFILEPTR 
									   FORMSTREAM))
								 CH#))
			     (IMAGEOBJPROP BUTTON.OBJ (QUOTE MAILOMAT.FIELD.START)
					   (ADD1 PRE.FIELD.NCHARS))
			     (IMAGEOBJPROP BUTTON.OBJ (QUOTE MAILOMAT.FIELD.LEN)
					   0)
			     (if (NOT (IMAGEOBJPROP BUTTON.OBJ (QUOTE 
							       MAILOMAT.PROTECTED.FLG)))
				 then (push MAILOMAT.CHARLOOKS
					    (QUOTE (PROTECTED ON SELECTPOINT ON))
					    (IPLUS CH# (SUB1 PRE.FIELD.NCHARS))
					    1))
			     (PRIN1 (IMAGEOBJPROP BUTTON.OBJ (QUOTE MAILOMAT.POST.FIELD))
				    FORMSTREAM]
          (TEDIT.PARALOOKS FORMSTREAM (LIST (QUOTE PARALEADING)
					    2)
			   1
			   (GETEOFPTR FORMSTREAM))    (* default char looks: PROTECTED ON)
          (TEDIT.LOOKS FORMSTREAM (QUOTE (PROTECTED ON))
		       1
		       (GETEOFPTR FORMSTREAM))
          (while MAILOMAT.CHARLOOKS bind (LOOKS CH# LEN)
	     do (BLOCK)
		(SETQ LOOKS (pop MAILOMAT.CHARLOOKS))
		(SETQ CH# (pop MAILOMAT.CHARLOOKS))
		(SETQ LEN (pop MAILOMAT.CHARLOOKS))
		(TEDIT.LOOKS FORMSTREAM LOOKS CH# LEN))
          (while MAILOMAT.PARALOOKS bind (LOOKS CH# LEN)
	     do (BLOCK)
		(SETQ LOOKS (pop MAILOMAT.PARALOOKS))
		(SETQ CH# (pop MAILOMAT.PARALOOKS))
		(SETQ LEN (pop MAILOMAT.PARALOOKS))
		(TEDIT.PARALOOKS FORMSTREAM LOOKS CH# LEN))
          (TEDIT.STREAMCHANGEDP FORMSTREAM T)
          (replace (TEXTOBJ MENUFLG) of (TEXTOBJ FORMSTREAM) with T)
          (PROG ((FORMWINDOW.PROC (WINDOWPROP FORMWINDOW (QUOTE PROCESS)))
		 (FORMWINDOW.PROC.NAME (WINDOWPROP FORMWINDOW (QUOTE 
							    MAILOMAT.WINDOW.PROC.NAME)))
		 (SAFE.CH#                            (* MAILOMAT.FIND.UNPROTECTED.CH#))
		 NEWPROC TEDIT.PROCS)
	        (COND
		  ((AND FORMWINDOW.PROC (PROCESSP FORMWINDOW.PROC))
		    (TEDIT.KILL FORMWINDOW)))
	        (SETQ TEDIT.PROCS (LIST (QUOTE LEAVETTY)
					T
					(QUOTE FONT)
					MAILOMATFONT
					(QUOTE TEDIT.TENTATIVE)
					NIL))
	        [if (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.TEDIT.READTABLE))
		    then (push TEDIT.PROCS (QUOTE READTABLE)
			       (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.TEDIT.READTABLE]
	        [if (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.TEDIT.TITLEMENUFN))
		    then (push TEDIT.PROCS (QUOTE TITLEMENUFN)
			       (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.TEDIT.TITLEMENUFN]
	        (SETQ NEWPROC (TEDIT FORMSTREAM FORMWINDOW NIL TEDIT.PROCS))
	        (TEDIT.SHOWSEL FORMSTREAM NIL NIL)
	        (if FORMWINDOW.PROC.NAME
		    then (PROCESSPROP NEWPROC (QUOTE NAME)
				      FORMWINDOW.PROC.NAME])

(MAILOMAT.FORM.FILL.INS
  [LAMBDA NIL                                         (* edited: " 4-Jul-84 18:17")
    (PROG NIL])

(MAILOMAT.FULLUSERNAME
  [LAMBDA (USER.DATA UNPACKEDFLG)                     (* mbb "23-Jul-85 22:00")
    (COND
      (T (PROG (DOT USER REGISTRY SIMPLENAME)
	       (SETQ USER (fetch (MAILOMAT.USERDATA USERNAME) of USER.DATA))
	       [COND
		 ((NOT (SETQ DOT (STRPOS "." USER)))
		   (SETQ SIMPLENAME USER)
		   (SETQ REGISTRY DEFAULTREGISTRY))
		 ((NULL UNPACKEDFLG)                  (* Have registry, return right now)
		   (RETURN USER))
		 (T (SETQ SIMPLENAME (SUBSTRING USER 1 (SUB1 DOT)))
		    (SETQ REGISTRY (SUBATOM USER (ADD1 DOT]
	       [COND
		 ((U-CASEP SIMPLENAME)
		   (SETQ SIMPLENAME (L-CASE SIMPLENAME T]
	       (SETQ REGISTRY (L-CASE REGISTRY))
	       (RETURN (COND
			 (UNPACKEDFLG (CONS SIMPLENAME REGISTRY))
			 (T (CONCAT SIMPLENAME "." REGISTRY])

(MAILOMAT.ICONFN
  [LAMBDA (WINDOW OLDICON)                            (* mbb "17-Sep-85 17:39")

          (* * the holding place for all the fancy stuff for making an icon for a MAILOMAT form window * *)


    (OR (WINDOWP (WINDOWPROP WINDOW (QUOTE ICONWINDOW)))
	(PROG ((FORMWINDOW (WINDOWPROP WINDOW (QUOTE REGION)))
	       (USERNAME (MAILOMAT.INFER.USERNAME WINDOW)))
	      (RETURN (TITLEDICONW [OR MAILOMATFORMTEMPLATE
				       (SETQ MAILOMATFORMTEMPLATE
					 (create TITLEDICON
						 ICON ← MAILOMAT.FORM.ICON
						 MASK ← MAILOMAT.FORM.MASK
						 TITLEREG ←(create REGION
								   LEFT ← 3
								   BOTTOM ← 3
								   WIDTH ← 89
								   HEIGHT ← 32]
				   (COND
				     [(MKSTRING (WINDOWPROP WINDOW (QUOTE USERNAME]
				     (T ""))
				   (FONTCREATE (QUOTE HELVETICA)
					       8)
				   (GETBOXPOSITION (BITMAPWIDTH MAILOMAT.FORM.ICON)
						   (BITMAPHEIGHT MAILOMAT.FORM.ICON))
				   T])

(MAILOMAT.INDEX.FIRING.TIMES
  [LAMBDA (FIRING.TIMES DATE)                         (* mbb "16-Sep-85 16:20")
    (COND
      ((for TIME on FIRING.TIMES thereis (GREATERP TIME PRESENT.TIME)))
      (T FIRING.TIMES])

(MAILOMAT.INIT
  [LAMBDA NIL                                         (* mbb "18-Sep-85 04:23")
    (PROG (MAILOMAT.DIRECTORY PROFILE.NAME USERNAME USER.LIST)
          [SETQ MAILOMAT.USER.LIST (COPYALL (QUOTE ((**% OTHER% **]
          (SETQ MAILOMAT.DIRECTORY (OR LAFITEDEFAULTHOST&DIR (MKATOM LOGINHOST/DIR)))
          (SETQ PROFILE.NAME (PACKFILENAME (QUOTE BODY)
					   MAILOMAT.DIRECTORY
					   (QUOTE NAME)
					   (QUOTE MAILOMAT-PROFILE)
					   (QUOTE VERSION)
					   1))
          (COND
	    ((MEMB PROFILE.NAME (DIRECTORY MAILOMAT.DIRECTORY))
	      (SETQ PROFILE.STREAM (OPENSTREAM PROFILE.NAME (QUOTE BOTH)))
	      (SETQ USER.LIST (READ PROFILE.STREAM))
	      (CLOSEF PROFILE.NAME))
	    (T (RETURN)))
          (for ASSOC.PAIR in USER.LIST do (PUTASSOC (CAR ASSOC.PAIR)
						    (CDR ASSOC.PAIR)
						    MAILOMAT.USER.LIST])

(MAILOMAT.INIT.MAIL.USER
  [LAMBDA (USER.DATA)                                 (* mbb "23-Jul-85 22:00")
    (PROG (GVUSERNAME FULLNAME PASS MAILSERVERS AUTHENTICATED?)
          (SETQ GVUSERNAME (MAILOMAT.FULLUSERNAME USER.DATA T))
          (SETQ FULLNAME (CONCAT (CAR GVUSERNAME)
				 "."
				 (CDR GVUSERNAME)))
          (COND
	    ((NEQ [SETQ AUTHENTICATED? (GV.AUTHENTICATE GVUSERNAME
							(SETQ PASS
							  (GV.MAKEKEY
							    (fetch (MAILOMAT.USERDATA
								     PASSWORD)
							       of USER.DATA]
		  T)
	      (printout PROMPTWINDOW T "Cannot authenticate user " FULLNAME " because: "
			(SETQ \LAFITE.AUTHENTICATION.FAILURE AUTHENTICATED?)
			".")
	      NIL)
	    ([NULL (SETQ MAILSERVERS (CDR (GV.EXPAND GVUSERNAME]
	      (printout PROMPTWINDOW T "There are no mail servers for user " FULLNAME))
	    (T (replace (MAILOMAT.USERDATA LAFITE.USERDATA) of USER.DATA
		  with (create LAFITEUSERDATA
			       FULLUSERNAME ← FULLNAME
			       UNPACKEDUSERNAME ← GVUSERNAME
			       ENCRYPTEDPASSWORD ← PASS
			       SHORTUSERNAME ← FULLNAME
			       MAILSERVERS ←(for MAILSERVER in MAILSERVERS
					       bind SERVEROPS SERVERPORT SERVERDEF
					       when
						[COND
						  ((NULL (SETQ SERVEROPS (
							     GETMAILSERVEROPS MAILSERVER))
							 )
						    NIL)
						  ((NULL (SETQ SERVERPORT
							   (APPLY* (fetch (MAILSERVEROPS
									    
								   SERVERPORTFROMNAME)
								      of SERVEROPS)
								   MAILSERVER)))
						    (printout PROMPTWINDOW T 
							     "Can't find address of "
							      MAILSERVER)
						    NIL)
						  (T (SETQ SERVERDEF
						       (create MAILSERVER
							       MAILPORT ← SERVERPORT
							       MAILSERVERNAME ← 
							       MAILSERVER
							       MAILSERVEROPS ← SERVEROPS]
					       collect SERVERDEF)))
	       (RETURN (fetch (MAILOMAT.USERDATA LAFITE.USERDATA) of USER.DATA])

(MAILOMAT.LOAD.FIELDS
  [LAMBDA (FORMWINDOW USER.DATA)                      (* mbb "18-Sep-85 03:01")
    (PROG ((PASSWORD (fetch (MAILOMAT.USERDATA PASSWORD) of USER.DATA))
	   (USERNAME (fetch (MAILOMAT.USERDATA USERNAME) of USER.DATA)))
          (RETURN (AND [MAILOMAT.REPLACE.FILL.INS
			 FORMWINDOW
			 (for FIELD in MAILOMAT.FORM.FIELDS
			    collect (LIST (CAR FIELD)
					  (RECORDACCESS (CADR FIELD)
							USER.DATA
							(RECLOOK (QUOTE MAILOMAT.USERDATA)
								 )
							(QUOTE FETCH]
		       (if USERNAME
			   then (WINDOWPROP FORMWINDOW (QUOTE USERNAME)
					    USERNAME)
				T)
		       (if PASSWORD
			   then (COND
				  ([MAILOMAT.REPLACE.FILL.INS FORMWINDOW
							      (QUOTE ((Password: "???"]
				    (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.PASSWORD)
						PASSWORD)
				    T))
			 else T)
		       (TEDIT.STREAMCHANGEDP FORMWINDOW T])

(MAILOMAT.LOAD.FROM.PROFILE
  [LAMBDA (FORM.WINDOW)                               (* mbb "18-Sep-85 02:06")
    (PROG (MAILOMAT.DIRECTORY PROFILE.NAME USERNAME USER.LIST)
          (if (NULL (SETQ USERNAME (MAILOMAT.INFER.USERNAME FORM.WINDOW)))
	      then (MAILOMAT.PROMPT (LIST "Get failed for unknown user.")
				    FORMWINDOW)
		   (RETURN))
          (MAILOMAT.PROMPT (LIST "Retrieving data for user " USERNAME " ...")
			   FORMWINDOW)
          (SETQ MAILOMAT.DIRECTORY (OR LAFITEDEFAULTHOST&DIR (MKATOM LOGINHOST/DIR)))
          (SETQ PROFILE.NAME (PACKFILENAME (QUOTE BODY)
					   MAILOMAT.DIRECTORY
					   (QUOTE NAME)
					   (QUOTE MAILOMAT-PROFILE)
					   (QUOTE VERSION)
					   1))
          (COND
	    ((MEMB PROFILE.NAME (DIRECTORY MAILOMAT.DIRECTORY))
	      (SETQ PROFILE.STREAM (OPENSTREAM PROFILE.NAME (QUOTE BOTH)))
	      (SETQ USER.LIST (READ PROFILE.STREAM))
	      (CLOSEF PROFILE.NAME))
	    (T (MAILOMAT.PROMPT (LIST "Get failed for user " USERNAME " ...")
				FORMWINDOW)
	       (RETURN)))
          (if (AND (SETQ USER.DATA (ASSOC USERNAME USER.LIST))
		   (PUTASSOC USERNAME (CDR USER.DATA)
			     MAILOMAT.USER.LIST)
		   (MAILOMAT.LOAD.FIELDS FORMWINDOW (CDR USER.DATA)))
	      then (RETURN T)
	    else (MAILOMAT.PROMPT (LIST "Get failed for user " USERNAME " ...")
				  FORMWINDOW)
		 (RETURN])

(MAILOMAT.LOADMAILFOLDER
  [LAMBDA (MAILFOLDER)                                (* mbb "10-Sep-85 17:55")
    (COND
      ([PROG ((MAILFILE (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER))
	      CONTENTSFILE)
	     (RETURN (COND
		       ((OR (AND (INFILEP (SETQ CONTENTSFILE (TOCFILENAME MAILFILE)))
				 (MAILOMAT.READTOCFILE MAILFOLDER CONTENTSFILE))
			    (MAILOMAT.PARSEMAILFOLDER MAILFOLDER))
			 [replace (MAILFOLDER FOLDERNEEDSEXPUNGE) of MAILFOLDER
			    with (for I from 1 to (fetch (MAILFOLDER #OFMESSAGES)
						     of MAILFOLDER)
				    bind (MESSAGES ←(fetch (MAILFOLDER MESSAGEDESCRIPTORS)
						       of MAILFOLDER))
				    thereis (fetch (LAFITEMSG DELETED?)
					       of (NTHMESSAGE MESSAGES I]
			 MAILFOLDER)
		       (T (printout T "MAILOMAT Load of Mailfolder " (fetch (MAILFOLDER
									      
								  BROWSERPROMPTWINDOW)
									of MAILFOLDER)
				    " Failed.")
			  NIL]
	(replace (MAILFOLDER FIRSTSELECTEDMESSAGE) of MAILFOLDER with 1)
	(replace (MAILFOLDER LASTSELECTEDMESSAGE) of MAILFOLDER with 0])

(MAILOMAT.PANEL.CREATE
  [LAMBDA NIL                                         (* mbb "18-Sep-85 04:45")
    (PROG NIL
          (if (NOT \LAFITE.ACTIVE)
	      then (PROMPTPRINT "Turn LAFITE on.")
	    else (MENU (create MENU
			       ITEMS ← MAILOMAT.USER.LIST
			       WHENSELECTEDFN ←(QUOTE MAILOMAT.FORM.GROUP.CREATE)
			       TITLE ← "MAILOMAT Panel"
			       CENTERFLG ← T])

(MAILOMAT.PARSE.TIME
  [LAMBDA (TIMES)                                     (* mbb "17-Sep-85 22:13")
    (PROG ((STATE (fetch (FSM START.STATE) of TIME.ACCEPTOR))
	   (INPUT (UNPACK (MKATOM TIMES)))
	   (HOUR 0)
	   (MINUTE 0)
	   (SECOND 0)
	   TIME.LIST ERROR ACCEPT)
          [for CHARIN in INPUT repeatuntil ERROR bind VALID.TRANSITION
	     do (COND
		  ([NOT (SETQ ERROR (NULL (SETQ VALID.TRANSITION
					    (for TRANSITION
					       in (for TRANSITIONS
						     in (fetch (FSM TRANSITIONS)
							   of TIME.ACCEPTOR)
						     when (EQ STATE (fetch (TRANSITION
									     
									CURRENT.STATE)
								       of TRANSITIONS))
						     collect TRANSITIONS)
					       thereis (APPLY (fetch (TRANSITION 
									    PREDICATE)
								 of TRANSITION)
							      (LIST CHARIN]
		    (SETQ STATE (fetch (TRANSITION NEXT.STATE) of VALID.TRANSITION))
		    (SETQ ACCEPT (MEMB STATE (fetch (FSM ACCEPT.STATES) of TIME.ACCEPTOR]
          (RETURN (COND
		    ((OR ERROR (NULL ACCEPT))
		      NIL)
		    (T (APPLY (CAR (fetch (FSM ACCEPT.RESULT) of TIME.ACCEPTOR))
			      (MAPCAR (CADR (fetch (FSM ACCEPT.RESULT) of TIME.ACCEPTOR))
				      (QUOTE EVAL])

(MAILOMAT.PARSEMAILFOLDER1
  [LAMBDA (MAILFOLDER STREAM EOFPTR START FIRSTMSG# NOERROR)
                                                      (* mbb "19-Sep-85 01:34")

          (* * Parse MAILFOLDER starting at byte START until end of file at EOFPTR. FIRSTMSG# is the ordinal to assign to the 
	  first message. Returns (lastmsg# . messagedescriptors), or NIL if there was any problem. If NOERROR is true, does 
	  not publicly complain about errors, but quietly returns NIL)


    (replace (MAILFOLDER BROWSERPROMPTDIRTY) of MAILFOLDER with T)
    (bind CHCOUNT STAMPCOUNT MARK SEEN STARTFLG DELETED LASTMSG (HERE ← START)
       for MSG# from FIRSTMSG# while (ILESSP HERE EOFPTR)
       collect (SETFILEPTR STREAM HERE) 

          (* * the format of the stamp field of a laurel message is -
	  (*stamp* <c.r.> <length.of.message.in.5.ascii.chars> <sp><length.of.stamp.in.5.ascii.chars> <sp> <the.char.U.or.D> 
	  <the.char.S.or.U> <any.char> <c.r.>) -
	  U.or.D is Undeleted or Deleted -
	  S.or.U is Seen or Unseen * *)


	       [COND
		 ((AND (LA.READSTAMP STREAM)
		       (SETQ CHCOUNT (LA.READCOUNT STREAM))
		       (SETQ STAMPCOUNT (LA.READCOUNT STREAM))
		       (IGEQ CHCOUNT STAMPCOUNT)))
		 (T (RETURN (BADMAILFILE MAILFOLDER HERE MSG# 
				 "Bad header or previous message length is incorrect"
					 LASTMSG NOERROR]

          (* * now read in the status characters and save their pointers * *)


	       (SETQ DELETED (SELECTC (BIN STREAM)
				      (UNDELETEDFLAG NIL)
				      (DELETEDFLAG T)
				      (BADMAILFILE.FLAGBYTE MAILFOLDER MSG#)))
                                                      (* read the U for Undeleted *)
	       (SETQ SEEN (SELECTC (BIN STREAM)
				   (UNSEENFLAG NIL)
				   (SEENFLAG T)
				   ((CHARCODE N)      (* For some reason, there are files with this for the Seen 
						      mark, so allow it)
				     T)
				   (BADMAILFILE.FLAGBYTE MAILFOLDER MSG#)))
                                                      (* read the U for unseen *)
	       (SETQ MARK (BIN STREAM))               (* read the mark char *)
	       (PROG1 (SETQ LASTMSG
			(create LAFITEMSG
				# ← MSG#
				BEGIN ← HERE
				MESSAGELENGTH ← CHCOUNT
				MARKCHAR ←(OR (AND (NOT SEEN)
						   UNSEENMARK)
					      MARK)
				SEEN? ← SEEN
				DELETED? ← DELETED
				STAMPLENGTH ← STAMPCOUNT))
		      (LAFITE.PARSE.MSG.FOR.TOC LASTMSG MAILFOLDER)
		      (add HERE CHCOUNT))
       finally [COND
		 ((NOT (IEQP HERE EOFPTR))
		   (LAB.PROMPTPRINT MAILFOLDER "Warning: last message truncated from "
				    (fetch (LAFITEMSG MESSAGELENGTH) of LASTMSG)
				    " to "
				    (replace (LAFITEMSG MESSAGELENGTH) of LASTMSG
				       with (IDIFFERENCE (fetch (LAFITEMSG MESSAGELENGTH)
							    of LASTMSG)
							 (IDIFFERENCE HERE EOFPTR)))
				    " bytes. ")
		   (replace (LAFITEMSG MESSAGELENGTHCHANGED?) of LASTMSG
		      with (replace (LAFITEMSG MARKSCHANGED?) of LASTMSG with T]
	       (RETURN (CONS (fetch (LAFITEMSG #) of LASTMSG)
			     $$VAL])

(MAILOMAT.FORM.GROUP.CREATE
  [LAMBDA (USER.DATA)                                 (* mbb "18-Sep-85 03:54")
    (PROG ((FORMWINDOW (CREATEW (GETREGION 490 125)
				"New Bulk Mail Process Form"))
	   MENUW WREG)

          (* * set up main window)


          (WINDOWPROP FORMWINDOW (QUOTE MINSIZE)
		      (CONS 450 60))
          (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.WINDOW.PROC.NAME)
		      (QUOTE MAILOMAT.FORM))
          (WINDOWPROP FORMWINDOW (QUOTE ICONFN)
		      (QUOTE MAILOMAT.ICONFN))

          (* * set up menu window)


          (SETQ WREG (WINDOWPROP FORMWINDOW (QUOTE REGION)))
          (SETQ MENUW (CREATEW (create REGION
				       LEFT ←(fetch (REGION LEFT) of WREG)
				       BOTTOM ←(fetch (REGION TOP) of WREG)
				       WIDTH ←(fetch (REGION WIDTH) of WREG)
				       HEIGHT ← 40)
			       "MAILOMAT Form Editor"))
          (ATTACHWINDOW MENUW FORMWINDOW (QUOTE TOP)
			(QUOTE JUSTIFY)
			NIL)
          (WINDOWPROP MENUW (QUOTE MAXSIZE)
		      (CONS 0 40))
          (WINDOWPROP MENUW (QUOTE MINSIZE)
		      (CONS 0 40))
          (WINDOWPROP MENUW (QUOTE ICONFN)
		      (QUOTE MAILOMAT.ICONFN))
          (WINDOWPROP MENUW (QUOTE MAILOMAT.WINDOW.PROC.NAME)
		      (QUOTE MAILOMAT.FORM.MENU))
          (if (NOT (AND (BOUNDP (QUOTE MAILOMAT.MENU.READTABLE))
			(READTABLEP MAILOMAT.MENU.READTABLE)))
	      then (SETQ MAILOMAT.MENU.READTABLE (COPYREADTABLE TEDIT.READTABLE))
		   (TEDIT.SETFUNCTION (CHARCODE CR)
				      (FUNCTION MAILOMAT.MENU.CR.FN)
				      MAILOMAT.MENU.READTABLE))
          (WINDOWPROP MENUW (QUOTE MAILOMAT.TEDIT.READTABLE)
		      MAILOMAT.MENU.READTABLE)
          (WINDOWPROP MENUW (QUOTE MAILOMAT.TEDIT.TITLEMENUFN)
		      (FUNCTION MAILOMAT.FORM.MENU.TITLEMENUFN))
          (GETPROMPTWINDOW FORMWINDOW 2)

          (* * create MAILOMAT forms for main and menu windows)


          (MAILOMAT.FORM.CREATE FORMWINDOW MAILOMATBOLDFONT MAILOMAT.FORM.SPECS 
				MAILOMAT.FORM.FORMAT)
          (MAILOMAT.FORM.CREATE MENUW MAILOMATBUTTONFONT
				(QUOTE ((Apply FIELDTYPE BUTTON FN 
					       MAILOMAT.FORM.MENU.BUTTONFN)
					 (Get FIELDTYPE BUTTON FN 
					      MAILOMAT.FORM.MENU.BUTTONFN)
					 (Put FIELDTYPE BUTTON FN 
					      MAILOMAT.FORM.MENU.BUTTONFN)))
				(QUOTE (Apply TAB Put TAB Get CR)))
          (until (AND (WINDOWPROP FORMWINDOW (QUOTE LINES))
		      (WINDOWPROP MENUW (QUOTE LINES)))
	     do                                       (* wait until the two Tedit windows are totally initialized)
		(BLOCK 200))
          (WINDOWPROP FORMWINDOW (QUOTE CLOSEFN)
		      (FUNCTION MAILOMAT.KILL.ATTACHED.TEDIT.CLOSEFN))
          (if (EQ (CAR USER.DATA)
		  (QUOTE **% OTHER% **))
	      then (MAILOMAT.FORM.MENU.ACTIONFN MENUW (QUOTE New))
	    else (MAILOMAT.FORM.MENU.ACTIONFN MENUW (QUOTE Get)
					      USER.DATA])

(MAILOMAT.KILL.ATTACHED.TEDIT.CLOSEFN
  [LAMBDA (FORMWINDOW)                                (* mbb "18-Sep-85 02:45")
    (PROG NIL
          [if (AND (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM))
		   (TEDIT.STREAMCHANGEDP (TEXTSTREAM FORMWINDOW)))
	      then (if (NULL (MAILOMAT.CONFIRM "Form has been changed  --- confirm QUIT" 
					       FORMWINDOW))
		       then (MAILOMAT.PROMPT "Quit aborted." FORMWINDOW)
			    (RETURN (QUOTE DON'T]
          (for AW in (ATTACHEDWINDOWS FORMWINDOW) bind TSTREAM
	     do (DETACHWINDOW AW)
		(if (SETQ TSTREAM (WINDOWPROP AW (QUOTE TEXTSTREAM)))
		    then (TEDIT.KILL (TEXTOBJ TSTREAM)))
		(WINDOWDELPROP AW (QUOTE CLOSEFN)
			       (QUOTE DON'T))
		(CLOSEW AW))
          (if (SETQ TSTREAM (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM)))
	      then (TEDIT.KILL (TEXTOBJ TSTREAM])

(MAILOMAT.FORM.MENU.ACTIONFN
  [LAMBDA (MENUWINDOW OPERATION USER.ASSOC.PAIR)      (* mbb "18-Sep-85 03:52")
    (ALLOW.BUTTON.EVENTS)
    (PROG ((MENUWINDOW.TEXTOBJ (WINDOWPROP MENUWINDOW (QUOTE TEXTOBJ)))
	   (FORMWINDOW (WINDOWPROP MENUWINDOW (QUOTE MAINWINDOW)))
	   FORMWINDOW.TEXTOBJ)
          (DECLARE (SPECVARS MENUWINDOW.TEXTOBJ FORMWINDOW FORMWINDOW.TEXTOBJ))
          (SETQ FORMWINDOW.TEXTOBJ (WINDOWPROP FORMWINDOW (QUOTE TEXTOBJ)))
          (if (OR (NOT (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM)))
		  (NULL MENUWINDOW.TEXTOBJ)
		  (NULL FORMWINDOW.TEXTOBJ))
	      then (MAILOMAT.PROMPT 
	   "MAILOMAT form munged!! --- Close this MAILOMAT window and create another"
				    FORMWINDOW)
		   (RETURN))
          (if (OR (MAILOMAT.TOBJ.ACTIVEP MENUWINDOW.TEXTOBJ)
		  (MAILOMAT.TOBJ.ACTIVEP FORMWINDOW.TEXTOBJ))
	      then (MAILOMAT.PROMPT 
			      "Edit or MAILOMAT operation in progress -- please wait"
				    FORMWINDOW)
		   (RETURN))
          (MAILOMAT.MARK.ACTIVE MENUWINDOW.TEXTOBJ OPERATION)
          (MAILOMAT.MARK.ACTIVE FORMWINDOW.TEXTOBJ OPERATION)
          (DSPFILL NIL 72 (QUOTE PAINT)
		   MENUWINDOW)
          (CLEARW FORMWINDOW)
          (TEDIT.SHOWSEL (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM))
			 NIL NIL)
          (MAILOMAT.DISCONNECT.WINDOW FORMWINDOW)
          (MAILOMAT.PROMPT (LIST OPERATION " initiated...")
			   FORMWINDOW)
          (NLSETQ (SELECTQ OPERATION
			   (New (MAILOMAT.MENU.FN.CLEAR FORMWINDOW (
							  MAILOMAT.FORM.FILL.INS)))
			   (Get (MAILOMAT.MENU.FN.GET FORMWINDOW USER.ASSOC.PAIR))
			   (Put (MAILOMAT.MENU.FN.PUT FORMWINDOW))
			   (Apply (MAILOMAT.MENU.FN.APPLY MENUWINDOW FORMWINDOW))
			   (MAILOMAT.PROMPT "Unknown MAILOMAT.FORM button name!" 
					    FORMWINDOW)))
          (MAILOMAT.MARK.ACTIVE MENUWINDOW.TEXTOBJ NIL)
          (MAILOMAT.MARK.ACTIVE FORMWINDOW.TEXTOBJ NIL)
          (REDISPLAYW MENUWINDOW)
          (TEDIT.SHOWSEL (WINDOWPROP MENUWINDOW (QUOTE TEXTSTREAM))
			 NIL NIL)
          (MAILOMAT.RECONNECT.WINDOW FORMWINDOW)
          (SCROLLW FORMWINDOW 0.0 0.0)
          (TEDIT.SHOWSEL (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM))
			 NIL NIL])

(MAILOMAT.GET.MAILOMAT
  [LAMBDA (FORMWINDOW USER.ASSOC.PAIR)                (* mbb "18-Sep-85 02:15")
    (PROG (LOAD.ERROR FILE MAILOMATSTREAM)
          (MAILOMAT.PROMPT (LIST "Retrieving data for user " (CAR USER.ASSOC.PAIR)
				 " ...")
			   FORMWINDOW)
          (if (NULL (MAILOMAT.LOAD.FIELDS FORMWINDOW (CDR USER.ASSOC.PAIR)))
	      then (MAILOMAT.PROMPT "Form in inconsistent state --- Get aborted." 
				    FORMWINDOW)
		   (WINDOWPROP FORMWINDOW (QUOTE TITLE)
			       "--- form inconsistent --- Please type in entries or QUIT")
		   (RETURN)
	    else (RETURN T])

(MAILOMAT.GET.PASSWORD
  [LAMBDA (IMAGEOBJ SEL)                              (* mbb "24-Jul-85 15:19")
    (PROG ((FORMWINDOW (\TEDIT.PRIMARYW (fetch (SELECTION \TEXTOBJ) of SEL))
		       2)
	   PWINDOW PASSWORD)
          (SETQ PWINDOW (GETPROMPTWINDOW FORMWINDOW 2))
          (CLEARW PWINDOW)
          (GIVE.TTY.PROCESS PWINDOW)
          [COND
	    [(SETQ PASSWORD (\ENCRYPT.PWD (PROMPTFORWORD "Enter password:" NIL NIL 
							 PWINDOW "*")))
	      (MAILOMAT.REPLACE.FILL.INS FORMWINDOW (QUOTE ((Password: "???"]
	    (T (MAILOMAT.REPLACE.FILL.INS FORMWINDOW (QUOTE ((Password: ""]
          (TEDIT.SHOWSEL (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM))
			 NIL NIL)
          (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.PASSWORD)
		      PASSWORD])

(MAILOMAT.GETMAILFOLDER
  [LAMBDA (FOLDERNAME)                                (* bvm: "12-Jan-84 15:08")

          (* * Locates a MAILFOLDER on FOLDERNAME, or creates one if there is none. The newly created folder does not have a 
	  full name unless FOLDERNAME itself has a version)


    (OR (for FOLDER in \ACTIVELAFITEFOLDERS when (OR (EQ (fetch (MAILFOLDER 
								VERSIONLESSFOLDERNAME)
							    of FOLDER)
							 FOLDERNAME)
						     (EQ (fetch (MAILFOLDER 
								       FULLFOLDERNAME)
							    of FOLDER)
							 FOLDERNAME))
	   do (RETURN FOLDER))
	(PROG ((UNPACKEDNAME (UNPACKFILENAME FOLDERNAME))
	       VERSIONLESSNAME SHORTNAME NEWFOLDER)
	      (LISTPUT UNPACKEDNAME (QUOTE VERSION)
		       NIL)
	      (SETQ VERSIONLESSNAME (PACKFILENAME UNPACKEDNAME))
	      [COND
		[(AND (NEQ VERSIONLESSNAME FOLDERNAME)
		      (find old NEWFOLDER in \ACTIVELAFITEFOLDERS
			 suchthat (EQ (fetch (MAILFOLDER VERSIONLESSFOLDERNAME)
					 of NEWFOLDER)
				      VERSIONLESSNAME)))
                                                      (* Found a folder describing a different version)
		  (COND
		    ((fetch (MAILFOLDER BROWSERWINDOW) of NEWFOLDER)
		      (printout PROMPTWINDOW T "A different version of " FOLDERNAME 
				" is already being browsed."
				"Multiple versions may not be manipulated at once.")
		      (RETURN NIL))
		    (T                                (* Not being browsed, so just smash the full name)
		       (replace (MAILFOLDER FULLFOLDERNAME) of NEWFOLDER with FOLDERNAME]
		(T (SETQ SHORTNAME (LA.SHORTFILENAME UNPACKEDNAME LAFITEMAIL.EXT))
		   (SETQ NEWFOLDER (create MAILFOLDER
					   FULLFOLDERNAME ←(AND (NEQ FOLDERNAME 
								     VERSIONLESSNAME)
								FOLDERNAME)
					   VERSIONLESSFOLDERNAME ← VERSIONLESSNAME
					   SHORTFOLDERNAME ← SHORTNAME
					   FOLDERLOCK ←(CREATE.MONITORLOCK 
								      VERSIONLESSNAME)))
		   (push \ACTIVELAFITEFOLDERS NEWFOLDER)
		   (COND
		     ((NOT (FMEMB SHORTNAME (CDR LAFITEMAILFOLDERS)))
		       (push (CDR LAFITEMAILFOLDERS)
			     SHORTNAME)
		       (SETQ \LAFITEPROFILECHANGED T)
		       (SETQ LAFITEFOLDERSMENU]
	      (RETURN NEWFOLDER])

(MAILOMAT.GETNEWMAIL
  [LAMBDA (MAILFOLDER USER.DATA)                      (* mbb "10-Sep-85 22:57")
    (PROG ((OUTSTREAM (\LAFITE.OPEN.FOLDER MAILFOLDER (QUOTE APPEND)))
	   FIRSTMESSAGE)
          [for MAILSERVER in [fetch (LAFITEUSERDATA MAILSERVERS)
				of (OR \LAFITEUSERDATA (PROGN (printout
								PROMPTWINDOW 
					     "MAILOMAT: No MAILBOXES known for user "
								(fetch (MAILOMAT.USERDATA
									 USERNAME)
								   of USER.DATA))
							      (RETURN NIL]
	     bind MESSAGELIST when (SETQ MESSAGELIST (MAILOMAT.GETNEWMAIL1 MAILSERVER 
									   MAILFOLDER 
									   OUTSTREAM 
									 FIRSTMESSAGE))
	     do (MAILOMAT.APPENDMESSAGES MAILFOLDER MESSAGELIST)
		(COND
		  ((NOT FIRSTMESSAGE)                 (* select the first new message -- all former messages have 
						      already been unselected)
		    (MAILOMAT.SELECTMESSAGE (SETQ FIRSTMESSAGE (CAR MESSAGELIST))
					    MAILFOLDER)
		    (AND LAFITE.AFTER.GETMAIL.FN (APPLY* LAFITE.AFTER.GETMAIL.FN 
							 MAILFOLDER MESSAGELIST]
          (RETURN FIRSTMESSAGE])

(MAILOMAT.GETNEWMAIL1
  [LAMBDA (MAILSERVER MAILFOLDER OUTSTREAM NTHTIME)   (* mbb "10-Sep-85 22:58")
    (PROG (MESSAGELIST OPENRESULT MAILBOX #OFMESSAGES)
          (SETQ OPENRESULT (APPLY* (fetch (MAILSERVER OPENMAILBOX) of MAILSERVER)
				   (fetch (MAILSERVER MAILPORT) of MAILSERVER)
				   (fetch (LAFITEUSERDATA FULLUSERNAME) of 
								      \LAFITEUSERDATA)
				   (fetch (LAFITEUSERDATA ENCRYPTEDPASSWORD)
				      of \LAFITEUSERDATA)
				   MAILSERVER))
          (SELECTQ (COND
		     ((LISTP OPENRESULT)
		       (SETQ MAILBOX (CAR OPENRESULT)))
		     (T OPENRESULT))
		   (EMPTY (RETURN))
		   (NIL                               (* No response))
		   (COND
		     (MAILBOX (COND
				((NOT NTHTIME)
				  (UNSELECTALLMESSAGES MAILFOLDER)))
			      (SETQ #OFMESSAGES (fetch (OPENEDMAILBOX #OFMESSAGES)
						   of OPENRESULT))
			      (RETURN (COND
					((SETQ MESSAGELIST (\LAFITE.RETRIEVEMESSAGES
					      MAILSERVER MAILBOX OUTSTREAM MAILFOLDER))
                                                      (* first flush the file back out to disk before calling FLUSH 
						      *)
					  (\LAFITE.CLOSE.FOLDER MAILFOLDER)
					  (APPLY* (fetch (MAILSERVER CLOSEMAILBOX)
						     of MAILSERVER)
						  MAILBOX LAFITEFLUSHMAILFLG)
					  [COND
					    ((NULL #OFMESSAGES)
					      (\LAFITE.GETNEWMAIL# REPORTWINDOW
								   (LENGTH MESSAGELIST]
					  MESSAGELIST)
					(T            (* \LAFITE.RETRIEVEMESSAGES already set the file ptr back, etc
						      *)
					   (APPLY* (fetch (MAILSERVER CLOSEMAILBOX)
						      of MAILSERVER)
						   MAILBOX NIL)
					   NIL])

(MAILOMAT.FORM.MENU.BUTTONFN
  [LAMBDA (OBJ SEL WINDOW)                            (* jds "14-Feb-85 10:43")
    (MAILOMAT.FORM.MENU.ACTIONFN (\TEDIT.PRIMARYW (fetch (SELECTION \TEXTOBJ)
						     of SEL))
				 (IMAGEOBJPROP OBJ (QUOTE MBTEXT])

(MAILOMAT.FORM.SAVE
  [LAMBDA (FORMWINDOW FILENAME)                       (* mjs "22-Jul-84 12:45")
    (PROG ((OUTSTREAM (OPENSTREAM FILENAME (QUOTE OUTPUT)
				  (QUOTE NEW)))
	   OUTSTREAMNAME)
          (DECLARE (SPECVARS OUTSTREAM OUTSTREAMNAME))
          (SETQ OUTSTREAMNAME (FULLNAME OUTSTREAM))
          (RESETLST (RESETSAVE (RADIX 10))
		    [RESETSAVE NIL (LIST (FUNCTION (LAMBDA NIL
					     (if RESETSTATE
						 then (if (OPENP OUTSTREAM)
							  then (CLOSEF OUTSTREAM))
						      (DELFILE (FULLNAME OUTSTREAM))
						      (MAILOMAT.PROMPT
							(LIST 
					      "SAVE ERROR - bad bulk mail form file "
							      (FULLNAME OUTSTREAM)
							      " deleted")
							FORMWINDOW)
						      (SETQ OUTSTREAMNAME NIL]
		    (PROG ((FORMSTREAM (TEXTSTREAM FORMWINDOW))
			   (TOBJ (TEXTOBJ FORMWINDOW))
			   (CH# 1)
			   BUTTON.OBJ FIELD.START FIELD.LEN SEL TOBJ)
		          (LINELENGTH MAX.SMALLP OUTSTREAM)
		      loop(BLOCK)
		          (SETQ CH# (CDR (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
		          (if (NULL CH#)
			      then (CLOSEF OUTSTREAM)
				   (RETURN))
		          (SETFILEPTR FORMSTREAM (SUB1 CH#))
		          (SETQ BUTTON.OBJ (BIN FORMSTREAM))
		          (PRIN1 (IMAGEOBJPROP BUTTON.OBJ (QUOTE MBTEXT))
				 OUTSTREAM)
		          (BOUT OUTSTREAM (CHARCODE SPACE))
		          (if (IMAGEOBJPROP BUTTON.OBJ (QUOTE MAILOMAT.PROTECTED.FLG))
			      then (SETQ FIELD.START (IPLUS (IMAGEOBJPROP BUTTON.OBJ
									  (QUOTE 
								 MAILOMAT.FIELD.START))
							    CH#))
				   (SETQ FIELD.LEN (IMAGEOBJPROP BUTTON.OBJ (QUOTE 
								   MAILOMAT.FIELD.LEN)))
			    else (SETQ SEL (MBUTTON.FIND.NEXT.FIELD TOBJ CH#))
				 (SETQ FIELD.START (fetch (SELECTION CH#) of SEL))
				 (SETQ FIELD.LEN (fetch (SELECTION DCH) of SEL)))
		          (SETFILEPTR FORMSTREAM (SUB1 FIELD.START))
		          (for X from 1 to FIELD.LEN bind C
			     do (SETQ C (BIN FORMSTREAM))
				(if (NOT (FIXP C))
				    then (MAILOMAT.PROMPT (LIST "non-char found in "
								(IMAGEOBJPROP
								  BUTTON.OBJ
								  (QUOTE MBTEXT))
								" field -- ignored")
							  FORMWINDOW)
				  elseif (FMEMB C (CHARCODE (CR : "'")))
				    then (BLOCK)
					 (BOUT OUTSTREAM (CHARCODE "'"))
					 (BOUT OUTSTREAM C)
				  else (BOUT OUTSTREAM C)))
		          (TERPRI OUTSTREAM)
		          (TERPRI OUTSTREAM)
		          (SETQ CH# (ADD1 CH#))
		          (GO loop)))
          (RETURN OUTSTREAMNAME])

(MAILOMAT.GET.FILENAME
  [LAMBDA (USERNAME)                                  (* mbb "16-Jul-85 16:17")
    (PACKFILENAME (QUOTE DIRECTORY)
		  (fetch PACKEDHOST&DIR of \LAFITEDEFAULTHOST&DIR)
		  (QUOTE NAME)
		  USERNAME
		  (QUOTE EXTENSION)
		  MAILOMATFORM.EXT
		  (QUOTE VERSION)
		  1])

(MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL
  [LAMBDA (WINDOW BUTTON.NAME)                        (* mbb "22-Jul-85 16:11")
    (PROG ((BUTTON (MAILOMAT.FIND.BUTTON (WINDOWPROP WINDOW (QUOTE TEXTSTREAM))
					 BUTTON.NAME)))
          (if (NULL BUTTON)
	      then (ERROR "Can't find associated menu value" BUTTON.NAME))
          (RETURN (IMAGEOBJPROP (CAR BUTTON)
				(QUOTE MAILOMAT.FIELD.VALUE])

(MAILOMAT.GET.ASSOCIATED.MENU.VAL
  [LAMBDA (OBJ WINDOW)                                (* edited: "30-Aug-84 09:58")
    (PROG [(BUTTON (MAILOMAT.FIND.BUTTON (WINDOWPROP WINDOW (QUOTE TEXTSTREAM))
					 (IMAGEOBJPROP OBJ (QUOTE 
							     MAILOMAT.ASSOCIATED.MENU]
          [if (NULL BUTTON)
	      then (ERROR "Can't find associated menu value" (IMAGEOBJPROP OBJ
									   (QUOTE 
							     MAILOMAT.ASSOCIATED.MENU]
          (RETURN (IMAGEOBJPROP (CAR BUTTON)
				(QUOTE MAILOMAT.FIELD.VALUE])

(MAILOMAT.GET.BUTTON.FIELD.AS.TEXT
  [LAMBDA (WINDOW BUTTON.NAME)                        (* mbb "22-Jul-85 14:58")
    (PROG ([TOBJ (TEXTOBJ (WINDOWPROP WINDOW (QUOTE TEXTSTREAM]
	   (CH# 0)
	   OBJ BUTTON SEL)
          [while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do (SETQ OBJ (CAR BUTTON))
		(SETQ CH# (CDR BUTTON))
	     repeatuntil (EQ BUTTON.NAME (IMAGEOBJPROP OBJ (QUOTE MBTEXT]
          (RETURN (if BUTTON
		      then (MBUTTON.NEXT.FIELD.AS.TEXT TOBJ CH#)
		    else (ERROR "Can't find named button" BUTTON.NAME])

(MAILOMAT.GET.BUTTON.FIELD.AS.LIST
  [LAMBDA (FORMWINDOW FIELD.NAME)                     (* mjs " 8-Aug-84 15:18")
    (bind READ.VAL (STR ←(OPENSTRINGSTREAM (MAILOMAT.GET.BUTTON.FIELD.AS.TEXT FORMWINDOW 
									   FIELD.NAME)))
       while (SETQ READ.VAL (NLSETQ (READ STR))) collect (CAR READ.VAL])

(MAILOMAT.MARK.ACTIVE
  [LAMBDA (TOBJ OP)                                   (* edited: "16-May-84 16:13")
    (if TOBJ
	then (replace (TEXTOBJ EDITOPACTIVE) of TOBJ with OP])

(MAILOMAT.MARK.HARDCOPIED
  [LAMBDA (MAILFOLDER MSGS MARK)                      (* mbb "26-Jul-85 02:18")
    (WITH.MONITOR (fetch (MAILFOLDER FOLDERLOCK) of MAILFOLDER)
		  (AND LAFITEIMMEDIATECHANGESFLG (CHANGEFLAGINFOLDER MAILFOLDER
								     (fetch (LAFITEMSG
									      MARKFILEPTR)
									of MSGDESCRIPTOR)
								     MARK))
		  (for MSGDESCRIPTOR in MSGS
		     do (replace (LAFITEMSG MARKCHAR) of MSGDESCRIPTOR with MARK)
			(replace (LAFITEMSG SEEN?) of MSGDESCRIPTOR
			   with (NEQ MARK UNSEENMARK))
			(replace (LAFITEMSG MARKSCHANGED?) of MSGDESCRIPTOR with T)
			(replace (MAILFOLDER FOLDERNEEDSUPDATE) of MAILFOLDER
			   with T])

(MAILOMAT.MENU.CR.FN
  [LAMBDA (TSTREAM TOBJ)                              (* jds "14-Feb-85 10:47")
    (MAILOMAT.MARK.ACTIVE TOBJ NIL)
    (MAILOMAT.FORM.MENU.ACTIONFN (\TEDIT.PRIMARYW TOBJ)
				 (QUOTE Get])

(MAILOMAT.MENU.FN.CLEAR
  [LAMBDA (FORMWINDOW FILL.INS)                       (* mbb "18-Sep-85 02:16")
    (PROG NIL
          (CLEARW FORMWINDOW)
          (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.USERNAME)
		      NIL)
          (MAILOMAT.FORM.CLEAR FORMWINDOW FILL.INS)
          (WINDOWPROP FORMWINDOW (QUOTE TITLE)
		      "New Bulk Mail Process Form")
          (MAILOMAT.PROMPT "New form cleared." FORMWINDOW])

(MAILOMAT.MENU.FN.GET
  [LAMBDA (FORMWINDOW USER.ASSOC.PAIR)                (* mbb "18-Sep-85 02:15")
    (PROG NIL
          [if (TEDIT.STREAMCHANGEDP (TEXTSTREAM FORMWINDOW))
	      then (if (NULL (MAILOMAT.CONFIRM "Form has been changed  --- confirm GET" 
					       FORMWINDOW))
		       then (MAILOMAT.PROMPT "Get aborted." FORMWINDOW)
			    (RETURN (QUOTE DON'T]
          (if (COND
		(USER.ASSOC.PAIR (MAILOMAT.GET.MAILOMAT FORMWINDOW USER.ASSOC.PAIR))
		(T (MAILOMAT.LOAD.FROM.PROFILE FORMWINDOW)))
	      then (MAILOMAT.PROMPT (LIST "MAILOMAT user data for " (WINDOWPROP
					    FORMWINDOW
					    (QUOTE USERNAME))
					  " retrieved.")
				    FORMWINDOW)
		   [WINDOWPROP FORMWINDOW (QUOTE TITLE)
			       (CONCAT "Editting MAILOMAT form for user "
				       (WINDOWPROP FORMWINDOW (QUOTE USERNAME]
		   (RETURN T)
	    else (RETURN])

(MAILOMAT.MENU.FN.APPLY
  [LAMBDA (MENUWINDOW FORMWINDOW)                     (* mbb "19-Sep-85 01:12")
    (PROG (USERNAME FILENAME CHECK.VALUE SAVE.VALUE EDIT.CHANGES.STRING)
          (if (NOT (TEDIT.STREAMCHANGEDP FORMWINDOW))
	      then (if (NULL (MAILOMAT.CONFIRM 
				       "Form has NOT been changed  --- confirm APPLY"
					       FORMWINDOW))
		       then (MAILOMAT.PROMPT "APPLY aborted" FORMWINDOW)
			    (RETURN)))
          (if (NULL (SETQ USERNAME (MAILOMAT.INFER.USERNAME FORMWINDOW)))
	      then (RETURN))
          (CLEARW FORMWINDOW)
          (if (SETQ CHECK.VALUE (MAILOMAT.CHECK.FIELDS FORMWINDOW))
	      then (MAILOMAT.PUT.FAILED (CONCAT "Bad MAILOMAT form: " CHECK.VALUE 
						" --- Put Aborted")
					FORMWINDOW)
		   (RETURN))
          (MAILOMAT.PROMPT (LIST "Applying MAILOMAT form for " USERNAME " ...")
			   FORMWINDOW)
          (WINDOWPROP FORMWINDOW (QUOTE USERNAME)
		      USERNAME)
          (SETQ SAVE.VALUE (MAILOMAT.ADD.USER FORMWINDOW USERNAME))
          (TEDIT.STREAMCHANGEDP FORMWINDOW T)
          (if SAVE.VALUE
	      then (MAILOMAT.PROMPT (LIST "Application of MAILOMAT form for " USERNAME 
					  " complete.")
				    FORMWINDOW)
		   (WINDOWPROP FORMWINDOW (QUOTE TITLE)
			       (CONCAT "Editting MAILOMAT form for " USERNAME 
				       "  --- saved"))
	    else (WINDOWPROP FORMWINDOW (QUOTE TITLE)
			     (CONCAT "MAILOMAT form for " USERNAME " not applied.")))
          (REDISPLAYW FORMWINDOW])

(MAILOMAT.GET.USERNAME
  [LAMBDA (FORMWINDOW)                                (* mbb "23-Jul-85 22:54")
    (PROG (USERNAME (PWINDOW (GETPROMPTWINDOW FORMWINDOW 2)))
          (CLEARW PWINDOW)
          (GIVE.TTY.PROCESS PWINDOW)
          (SETQ USERNAME (PROMPTFORWORD "Which user should be assigned this form? " NIL 
					NIL PWINDOW))
          (if USERNAME
	      then (RETURN (U-CASE (MKATOM USERNAME)))
	    else (RETURN NIL])

(MAILOMAT.OPEN.MAILFOLDER
  [LAMBDA (FOLDERNAME)                                (* mbb "10-Sep-85 23:02")
    (WITH.MONITOR
      \LAFITE.BROWSELOCK
      (PROG (MAILFOLDER)
	    (RETURN
	      (COND
		((NULL (SETQ MAILFOLDER (\LAFITE.GETMAILFOLDER FOLDERNAME)))
                                                      (* Error occurred)
		  NIL)
		((SETQ BROWSERWINDOW (fetch (MAILFOLDER BROWSERWINDOW) of MAILFOLDER))
		  (printout PROMPTWINDOW T "MAILOMAT couldn't use " FOLDERNAME 
			    " because of browse.")
		  NIL)
		(T (PROG ((STREAM (fetch (MAILFOLDER FOLDERSTREAM) of MAILFOLDER))
			  ERRN)
		         (COND
			   (STREAM                    (* Already have folder open, e.g., from MOVETO, but no browser
						      yet)
				   (SETFILEINFO STREAM (QUOTE BUFFERS)
						LAFITEBUFFERSIZE))
			   (T [COND
				([NULL (SETQ STREAM (CAR (NLSETQ (\LAFITE.OPENSTREAM
								   FOLDERNAME
								   (QUOTE INPUT)
								   (QUOTE OLD)
								   T]
				  (COND
				    ((OR (NEQ (CAR (SETQ ERRN (ERRORN)))
					      (PROG1 23 
                                                      (* File not found)))
					 (NEQ (CADR ERRN)
					      FOLDERNAME))
				      (printout PROMPTWINDOW T "MAILOMAT Could not open " 
						FOLDERNAME)
				      (RETURN))
				    (T (SETQ STREAM (\LAFITE.OPENSTREAM FOLDERNAME
									(QUOTE BOTH)
									(QUOTE NEW)
									T)))
				    (T (FORGETMAILFILE FOLDERNAME)
				       (RETURN]
			      (replace (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER
				 with (FULLNAME STREAM))
			      (replace (MAILFOLDER FOLDERSTREAM) of MAILFOLDER
				 with STREAM)))
		         (RETURN MAILFOLDER])

(MAILOMAT.PRESENT.TIME
  [LAMBDA NIL                                         (* mbb "16-Sep-85 20:43")
    (PROG (PTIME)
          (RETURN (COND
		    ([MINUSP (SETQ PTIME (DIFFERENCE (IDATE)
						     (IDATE (CONCAT (DATE (DATEFORMAT
									    NO.TIME))
								    " 00:00:00"]
		      0)
		    (T PTIME])

(MAILOMAT.PROCESS.FILE
  [LAMBDA (USER.DATA)                                 (* mbb "16-Sep-85 19:12")
    (PROG (FOLDERNAME MAILFOLDER LAFITEUSERDATA #NEWMESSAGES)
          (SETQ LAFITE.USERDATA (fetch (MAILOMAT.USERDATA LAFITE.USERDATA) of USER.DATA))
          (if (for MAILSERVER in (fetch (LAFITEUSERDATA MAILSERVERS)
				    of (fetch (MAILOMAT.USERDATA LAFITE.USERDATA)
					  of USER.DATA))
		 thereis (EQ T (APPLY* (fetch (MAILSERVER POLLNEWMAIL) of MAILSERVER)
				       (fetch (MAILSERVER MAILPORT) of MAILSERVER)
				       (fetch (LAFITEUSERDATA FULLUSERNAME) of 
								      LAFITE.USERDATA)
				       (fetch (LAFITEUSERDATA ENCRYPTEDPASSWORD)
					  of LAFITE.USERDATA)
				       MAILSERVER)))
	      then
	       (SETQ FOLDERNAME (LA.LONGFILENAME (fetch MAILFOLDER of USER.DATA)
						 LAFITEMAIL.EXT))
	       (WITH.MONITOR
		 \LAFITE.BROWSELOCK
		 (if (SETQ MAILFOLDER (MAILOMAT.OPEN.MAILFOLDER FOLDERNAME))
		     then
		      (WITH.MONITOR
			(fetch (MAILFOLDER FOLDERLOCK) of MAILFOLDER)
			[RESETLST
			  (RESETSAVE \LAFITEUSERDATA LAFITE.USERDATA)
			  (MAILOMAT.LOADMAILFOLDER MAILFOLDER)
			  (WITH.MONITOR
			    \LAFITE.MAILSERVERLOCK
			    (if (MAILOMAT.GETNEWMAIL MAILFOLDER USER.DATA)
				then (LA.SELECTRANGE MAILFOLDER (fetch (MAILFOLDER 
								 FIRSTSELECTEDMESSAGE)
								   of MAILFOLDER)
						     (fetch (MAILFOLDER #OFMESSAGES)
							of MAILFOLDER))
				     (if (EQ (fetch (MAILOMAT.USERDATA HARDCOPY)
						of USER.DATA)
					     (QUOTE Yes))
					 then (MAILOMAT.HARDCOPY MAILFOLDER USER.DATA)
				       else (printout
					      PROMPTWINDOW T
					      [SETQ #NEWMESSAGES
						(PLUS 1 (DIFFERENCE (fetch (MAILFOLDER
									     #OFMESSAGES)
								       of MAILFOLDER)
								    (fetch (MAILFOLDER
									     
								 FIRSTSELECTEDMESSAGE)
								       of MAILFOLDER]
					      " new message"
					      (COND
						((NEQ #NEWMESSAGES 1)
						  "s")
						(T ""))
					      " received into "
					      (fetch (MAILFOLDER FULLFOLDERNAME)
						 of MAILFOLDER)))
				     (MAILOMAT.UPDATEMAILFOLDER MAILFOLDER)
				     (MAILOMAT.UPDATECONTENTSFILE MAILFOLDER
								  (fetch (MAILFOLDER
									   #OFMESSAGES)
								     of MAILFOLDER]
			(\LAFITE.CLOSE.FOLDER MAILFOLDER T])

(MAILOMAT.PROMPT
  [LAMBDA (WORDS FORMWINDOW)                          (* mjs "27-Apr-84 12:22")
    (PROG ((PWINDOW (GETPROMPTWINDOW FORMWINDOW 2)))
          (CLEARW PWINDOW)
          (if (LISTP WORDS)
	      then (for X in WORDS do (PRIN1 X PWINDOW))
	    else (PRIN1 WORDS PWINDOW])

(MAILOMAT.PROTECT.WARNING
  [LAMBDA (OBJ SEL WINDOW)                            (* edited: "30-Aug-84 09:58")
    (MAILOMAT.PROMPT (LIST "The field %"" (IMAGEOBJPROP OBJ (QUOTE MBTEXT))
			   "%" is protected from editing")
		     WINDOW])

(MAILOMAT.PUT.FAILED
  [LAMBDA (MSG FORMWINDOW)                            (* mbb "22-Jul-85 14:47")
    (RINGBELLS)
    (MAILOMAT.PROMPT (MKLIST MSG)
		     FORMWINDOW)
    (WINDOWPROP FORMWINDOW (QUOTE TITLE)
		(MKSTRING MSG])

(MAILOMAT.READTOCFILE
  [LAMBDA (MAILFOLDER TOCFILE)                        (* mbb "10-Sep-85 17:53")

          (* * Read TOCFILE into MAILFOLDER)



          (* * Format of TOCFILE -
	  -
	  <LafitePassword word> <LafiteVersion word> -
	  <EOF of mailfile integer> -
	  <last msg# in toc word> -
	  -
	  followed by one entry per message, of the form -
	  -
	  <messagelength 3 bytes> <stamplength byte> <del&seen flags byte> <mark byte> <date 6 bytes> -
	  <subject ShortString> <From ShortString> <To ShortString>)


    (DECLARE (SPECVARS MAILFOLDER TOCSTREAM))
    (RESETLST (replace (MAILFOLDER BROWSERPROMPTDIRTY) of MAILFOLDER with T)
	      (PROG ([TOCSTREAM (OPENSTREAM TOCFILE (QUOTE INPUT)
					    (QUOTE OLD)
					    NIL
					    (QUOTE ((ENDOFSTREAMOP \LAFITE.TOCEOF]
		     (FOLDERSTREAM (\LAFITE.OPEN.FOLDER MAILFOLDER (QUOTE INPUT)))
		     (MSGCOUNTGUESS 0)
		     END FOLDEREOFPTR MESSAGES EXTRAMESSAGES LASTMSG# READMORE TOCVERSION 
		     OLDTOCFORMAT)
		    (RESETSAVE NIL (LIST (FUNCTION CLOSEF?)
					 TOCSTREAM))
		    (WHENCLOSE TOCSTREAM (QUOTE CLOSEALL)
			       (QUOTE NO))
		    (SETFILEPTR TOCSTREAM 0)          (* Just in case it was already open)
		    [COND
		      ((OR (NEQ (WORDIN TOCSTREAM)
				LAFITETOCPASSWORD)
			   (NEQ (SETQ TOCVERSION (WORDIN TOCSTREAM))
				LAFITEVERSION#))
			(COND
			  ((EQ TOCVERSION 8)          (* A slightly different format, still readable)
			    (SETQ OLDTOCFORMAT T))
			  (T (RETURN (BADTOCFILE "Format obsolete, discarding..."]
		    [COND
		      ([NOT (IEQP (SETQ END (FIXPIN TOCSTREAM))
				  (SETQ FOLDEREOFPTR (GETEOFPTR FOLDERSTREAM]
                                                      (* Maybe new messages have been added to file)
			(SETFILEPTR FOLDERSTREAM END)
			(COND
			  ((NOT (LA.READSTAMP FOLDERSTREAM))
			    (RETURN (BADTOCFILE "It does not agree with mail folder...")))
			  (T (SETQ READMORE T)
			     (SETQ MSGCOUNTGUESS (IQUOTIENT (IDIFFERENCE FOLDEREOFPTR END)
							    500]
		    (add MSGCOUNTGUESS (SETQ LASTMSG# (WORDIN TOCSTREAM)))
		    (SETQ MESSAGES (\LAFITE.MAKE.MSGARRAY MSGCOUNTGUESS))
		    (for I from 1 to LASTMSG# bind MSG LENGTH (START ←(GETFILEPTR 
									    TOCSTREAM))
						   (MESSAGESTART ← 0)
		       do                             (* Message length is 3 bytes long because it can be greater 
						      than MAX.SMALLP, though most unlikely)
			  [SETQ LENGTH (COND
			      ((ZEROP (SETQ LENGTH (BIN TOCSTREAM)))
				(WORDIN TOCSTREAM))
			      (T (\MAKENUMBER LENGTH (WORDIN TOCSTREAM]
			  (SETQ MSG
			    (create LAFITEMSG
				    # ← I
				    BEGIN ← MESSAGESTART
				    MESSAGELENGTH ← LENGTH))
			  (add MESSAGESTART LENGTH)
			  (replace (LAFITEMSG STAMPLENGTH) of MSG with (BIN TOCSTREAM))
			  [COND
			    (OLDTOCFORMAT (replace (LAFITEMSG PARSED&DELETED&SEENBITS)
					     of MSG with (BIN TOCSTREAM)))
			    (T (replace (LAFITEMSG MSGFLAGBITS) of MSG
				  with (BIN TOCSTREAM]
			  (replace (LAFITEMSG MARKCHAR) of MSG with (BIN TOCSTREAM))
			  (replace (LAFITEMSG DATE) of MSG with (LA.READSTRING TOCSTREAM 
									       6))
			  (replace (LAFITEMSG SUBJECT) of MSG with (LA.READSHORTSTRING
								     TOCSTREAM))
			  (replace (LAFITEMSG FROM) of MSG with (LA.READSHORTSTRING
								  TOCSTREAM))
			  (replace (LAFITEMSG TO) of MSG with (LA.READSHORTSTRING 
									    TOCSTREAM))
			  [replace (LAFITEMSG TOCLENGTH) of MSG
			     with (IMINUS (IDIFFERENCE START (SETQ START (GETFILEPTR
							   TOCSTREAM]
			  (SETA MESSAGES I MSG))
		    (replace (MAILFOLDER TOCLASTMESSAGE#) of MAILFOLDER
		       with (COND
			      ((EQ TOCVERSION LAFITEVERSION#)
				LASTMSG#)
			      (T                      (* Will have to rewrite toc next time)
				 0)))
		    [COND
		      (READMORE (COND
				  [(SETQ EXTRAMESSAGES (MAILOMAT.PARSEMAILFOLDER1
					MAILFOLDER FOLDERSTREAM FOLDEREOFPTR END
					(ADD1 LASTMSG#)
					T))
				    (SETQ MESSAGES (\LAFITE.ADDMESSAGES.TO.ARRAY
					MESSAGES
					(CDR EXTRAMESSAGES)
					(ADD1 LASTMSG#)
					(SETQ LASTMSG# (CAR EXTRAMESSAGES]
				  (T (RETURN (BADTOCFILE 
				"Couldn't parse new messages, trying from scratch..."
							 T]
		    (replace (MAILFOLDER MESSAGEDESCRIPTORS) of MAILFOLDER with MESSAGES)
		    (replace (MAILFOLDER #OFMESSAGES) of MAILFOLDER with LASTMSG#)
		    (replace (MAILFOLDER FOLDEREOFPTR) of MAILFOLDER with FOLDEREOFPTR)
		    (replace (MAILFOLDER BROWSERREADY) of MAILFOLDER with T)
		    (RETURN T])

(MAILOMAT.RECONNECT.WINDOW
  [LAMBDA (FORMWINDOW)                                (* mjs "17-Feb-85 16:02")
    (PROG [(TOBJ (TEXTOBJ (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM]
          (replace (TEXTOBJ \WINDOW) of TOBJ with (LIST FORMWINDOW))
          [\TEDIT.MARK.LINES.DIRTY TOBJ 1 (ADD1 (GETEOFPTR (WINDOWPROP FORMWINDOW
								       (QUOTE TEXTSTREAM]
          (TEDIT.UPDATE.SCREEN TOBJ])

(MAILOMAT.REMOVE.USER
  [LAMBDA (USERNAME)                                  (* mbb "16-Jul-85 16:17")
    (PROG (USER.PAIR)
          (if (SETQ USER.PAIR (ASSOC USERNAME MAILOMAT.USER.LIST))
	      then (RETURN (SETQ MAILOMAT.USER.LIST (REMOVE USER.PAIR MAILOMAT.USER.LIST))
			   )
	    else (RETURN (ERROR USERNAME "is not a known username"])

(MAILOMAT.REPLACE.FIELD.VAL
  [LAMBDA (OBJ CH# WINDOW NEWVAL)                     (* mjs "25-Oct-84 12:27")
    (DECLARE (SPECVARS OBJ CH# WINDOW NEWVAL))
    (RESETFORM (RADIX 10)
	       (PROG ((STREAM (TEXTSTREAM WINDOW))
		      (NEWVAL.NCHARS (NCHARS NEWVAL))
		      INSERT.CH# SEL)
		     (if (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PROTECTED.FLG))
			 then (SETQ INSERT.CH# (IPLUS (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.START))
						      CH#))
			      (TEDIT.DELETE STREAM INSERT.CH# (IMAGEOBJPROP OBJ
									    (QUOTE 
								   MAILOMAT.FIELD.LEN)))
			      (if (IGREATERP NEWVAL.NCHARS 0)
				  then (TEDIT.INSERT STREAM (if (NUMBERP NEWVAL)
								then (MKSTRING NEWVAL)
							      else NEWVAL)
						     INSERT.CH#)
				       (TEDIT.LOOKS STREAM (QUOTE (PROTECTED ON))
						    INSERT.CH# NEWVAL.NCHARS))
			      (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.LEN)
					    NEWVAL.NCHARS)
			      (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.VALUE)
					    NEWVAL)
		       else (SETQ SEL (MBUTTON.FIND.NEXT.FIELD (TEXTOBJ STREAM)
							       CH#))
			    (if (NULL SEL)
				then (SHOULDNT "Can't find button field"))
			    (SETQ INSERT.CH# (fetch (SELECTION CH#) of SEL))
			    (TEDIT.DELETE STREAM INSERT.CH# (fetch (SELECTION DCH)
							       of SEL))
			    (if (IGREATERP NEWVAL.NCHARS 0)
				then (TEDIT.INSERT STREAM (if (NUMBERP NEWVAL)
							      then (MKSTRING NEWVAL)
							    else NEWVAL)
						   INSERT.CH#)
				     (TEDIT.LOOKS STREAM (QUOTE (PROTECTED OFF))
						  INSERT.CH# NEWVAL.NCHARS])

(MAILOMAT.REPLACE.FILL.INS
  [LAMBDA (FORMWINDOW FILL.INS)                       (* mbb "24-Jul-85 02:09")
    (PROG (BUTTON)
          (for X in FILL.INS bind (FORMSTREAM ←(TEXTSTREAM FORMWINDOW))
	     do (BLOCK)
		(SETQ BUTTON (MAILOMAT.FIND.BUTTON FORMSTREAM (CAR X)))
		(if BUTTON
		    then (MAILOMAT.REPLACE.FIELD.VAL (CAR BUTTON)
						     (CDR BUTTON)
						     FORMSTREAM
						     (CADR X)))
	     repeatwhile BUTTON)
          (RETURN BUTTON])

(MAILOMAT.RESET.SEL
  [LAMBDA (WINDOW)                                    (* edited: "30-Aug-84 09:58")
                                                      (* (TEDIT.SHOWSEL WINDOW) (replace 
						      (SELECTION SET) of TEDIT.SELECTION with NIL))

          (* * for now, since I can't figure out how to turn off the selection, just put the selection in the first safe <i.e.
	  unprotected> place)


    (TEDIT.SETSEL (WINDOWPROP WINDOW (QUOTE TEXTSTREAM))
		  (MAILOMAT.FIND.UNPROTECTED.CH# (WINDOWPROP WINDOW (QUOTE TEXTSTREAM)))
		  0
		  (QUOTE LEFT])

(MAILOMAT.SCRATCH.LOAD
  [LAMBDA (FORMWINDOW MAILOMATSTREAM)                 (* mbb "11-Jul-85 22:32")
    (PROG [(SCRATCH.STREAM (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.STREAM]
          [if (NOT (AND SCRATCH.STREAM (OPENP SCRATCH.STREAM)))
	      then (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.STREAM)
			       (SETQ SCRATCH.STREAM (OPENSTREAM (QUOTE {NODIRCORE})
								(QUOTE BOTH)
								(QUOTE NEW]
          (SETFILEPTR SCRATCH.STREAM 0)
          (SETFILEPTR MAILOMATSTREAM 0)
          (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.MAP)
		      (MAILOMAT.COPY.AND.INDEX.MAILOMAT MAILOMATSTREAM SCRATCH.STREAM])

(MAILOMAT.SELECTMESSAGE
  [LAMBDA (MSGDESCRIPTOR MAILFOLDER)                  (* bvm: "15-Feb-84 12:34")
    (PROG ((N (fetch (LAFITEMSG #) of MSGDESCRIPTOR)))
          (LA.SELECTRANGE MAILFOLDER N N T])

(MAILOMAT.TEXTSTREAM.LOAD
  [LAMBDA (FORMWINDOW FILL.INS)                       (* edited: "20-Aug-84 10:44")
    (PROG ((SCRATCH.STREAM (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.STREAM)))
	   (SCRATCH.MAP (WINDOWPROP FORMWINDOW (QUOTE MAILOMAT.FORM.SCRATCH.MAP)))
	   (FORMSTREAM (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM)))
	   (CH# 0)
	   (FIELD.LEN 0)
	   OBJ BUTTON PROTECT.FIELD.FLG FIELD.CH# TOBJ SEL SCRATCH.MAP.SPEC SCRATCH.PTR)
          (SETQ TOBJ (TEXTOBJ FORMSTREAM))
          [while (PROGN (add CH# 1)
			(SETQ BUTTON (MBUTTON.FIND.NEXT.BUTTON TOBJ CH#)))
	     do (BLOCK)
		(SETQ OBJ (CAR BUTTON))
		(SETQ CH# (CDR BUTTON))
		(SETQ PROTECT.FIELD.FLG (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.PROTECTED.FLG)))
		(if PROTECT.FIELD.FLG
		    then (SETQ FIELD.CH# (IPLUS (IMAGEOBJPROP OBJ (QUOTE 
								 MAILOMAT.FIELD.START))
						CH#))
		  else (SETQ SEL (MBUTTON.FIND.NEXT.FIELD TOBJ CH#))
		       (if (NULL SEL)
			   then (HELP "Can't find field for button"))
		       (SETQ FIELD.CH# (fetch (SELECTION CH#) of SEL)))
		(SETFILEPTR FORMSTREAM (SUB1 FIELD.CH#))
		(SETQ SCRATCH.MAP.SPEC (ASSOC (IMAGEOBJPROP OBJ (QUOTE MBTEXT))
					      SCRATCH.MAP))
		(if (NULL SCRATCH.MAP.SPEC)
		    then (HELP "Null scatch map spec")
			 (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.VALUE)
				       NIL)
		  else (SETQ SCRATCH.PTR (CADR SCRATCH.MAP.SPEC))
		       (SETQ FIELD.LEN (CADDR SCRATCH.MAP.SPEC))
		       (TEDIT.SETSEL FORMSTREAM FIELD.CH# 0 (QUOTE LEFT)
				     NIL T)
		       (if (IGREATERP FIELD.LEN 0)
			   then (TEDIT.INCLUDE FORMSTREAM SCRATCH.STREAM SCRATCH.PTR
					       (IPLUS SCRATCH.PTR FIELD.LEN)))
		       [if PROTECT.FIELD.FLG
			   then (IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.LEN)
					      FIELD.LEN)
				(IMAGEOBJPROP OBJ (QUOTE MAILOMAT.FIELD.VALUE)
					      (PROGN (SETFILEPTR SCRATCH.STREAM 
								 SCRATCH.PTR)
						     (PACKC (for X from 1 to FIELD.LEN
							       collect (BIN 
								       SCRATCH.STREAM]
		       (if (NOT (EQP FIELD.LEN 0))
			   then (TEDIT.LOOKS FORMSTREAM (if PROTECT.FIELD.FLG
							    then (QUOTE (PROTECTED ON))
							  else (QUOTE (PROTECTED OFF)))
					     FIELD.CH# FIELD.LEN]
          (MAILOMAT.REPLACE.FILL.INS FORMWINDOW FILL.INS)
          (TEDIT.STREAMCHANGEDP (WINDOWPROP FORMWINDOW (QUOTE TEXTSTREAM))
				T])

(MAILOMAT.TIME.OF.DAY.WAKEUP
  [LAMBDA (USER.DATA FIRING.TIMES)                    (* mbb "18-Sep-85 04:12")
    (PROG (PRESENT.TIME TIME.LIST ROLLOVER WAIT)
          (SETQ PRESENT.TIME (MAILOMAT.PRESENT.TIME))
          (SETQ TIME.LIST (COND
	      ((for TIME on FIRING.TIMES thereis (GREATERP (CAR TIME)
							   PRESENT.TIME)))
	      (T FIRING.TIMES)))
      loop[SETQ WAIT (ITIMES 1000 (IDIFFERENCE (CAR TIME.LIST)
					       (MAILOMAT.PRESENT.TIME]
          [SETQ TIME.LIST (COND
	      ((CDR TIME.LIST))
	      (T (AND (SETQ ROLLOVER T)
		      FIRING.TIMES]
          [COND
	    ((GREATERP WAIT 0)
	      (DISMISS WAIT))
	    ((AND ROLLOVER (LESSP WAIT (ITIMES -1 1000 60 3)))
	      (DISMISS (PLUS WAIT (ITIMES 1000 60 60 24]
          (if (EQ (fetch (MAILOMAT.USERDATA ACTIVATION) of USER.DATA)
		  (QUOTE Off))
	      then (RETURN))
          (MAILOMAT.PROCESS.FILE USER.DATA)
          (SETQ PRESENT.TIME (MAILOMAT.PRESENT.TIME))
          (GO loop])

(MAILOMAT.TOBJ.ACTIVEP
  [LAMBDA (TOBJ)                                      (* edited: "16-May-84 16:15")
    (if (NULL TOBJ)
	then NIL
      else (fetch (TEXTOBJ EDITOPACTIVE) of TOBJ])

(MAILOMAT.TRANSMIT.HARDCOPY
  [LAMBDA (MAILFOLDER TEXTSTREAM MSGLST LCASEFILENAME USER.DATA)
                                                      (* mbb "26-Jul-85 02:19")

          (* * Sends TEXTSTREAM off to be hardcopied, then deletes it)


    (WITH.MONITOR \LAFITE.HARDCOPYLOCK                (* Because press isn't reentrant yet)
		  (TEDIT.HARDCOPY TEXTSTREAM NIL NIL
				  [CONCAT [COND
					    ((CDR MSGLST)
					      (CONCAT (LENGTH MSGLST)
						      " messages"))
					    (T (CONCAT "Message #" (fetch (LAFITEMSG
									    #)
								      of (CAR MSGLST]
					  " from "
					  (OR LCASEFILENAME (L-CASE (fetch (MAILFOLDER
									     
								       FULLFOLDERNAME)
								       of MAILFOLDER]
				  (fetch (MAILOMAT.USERDATA PRINTSERVER) of USER.DATA)))
    (CLOSEF TEXTSTREAM)
    (DELFILE TEXTSTREAM)
    (MAILOMAT.MARK.HARDCOPIED MAILFOLDER MSGLST HARDCOPYMARK])

(MAILOMAT.PERIODIC.WAKEUP
  [LAMBDA (USER.DATA START.TIME TIME.PERIOD)          (* mbb "13-Sep-85 05:37")
    (PROG (EXPECTEDTIME WAIT)
          (SETQ EXPECTEDTIME (ITIMES 1000 START.TIME))
          [SETQ WAIT (IDIFFERENCE EXPECTEDTIME (ITIMES 1000 (IDATE]
      loop(if (GREATERP WAIT 0)
	      then (DISMISS WAIT))
          (if (EQ (fetch (MAILOMAT.USERDATA ACTIVATION) of USER.DATA)
		  (QUOTE Off))
	      then (RINGBELLS)
		   (RETURN))
          (MAILOMAT.PROCESS.FILE USER.DATA)
          (SETQ WAIT (DIFFERENCE TIME.PERIOD (IDIFFERENCE (ITIMES 1000 (IDATE))
							  EXPECTEDTIME)))
          (SETQ EXPECTEDTIME (PLUS EXPECTEDTIME TIME.PERIOD))
          (GO loop])
)
(DECLARE: EVAL@COMPILE 

(RPAQQ LAFITETOCHEADERLENGTH 10)

(RPAQQ LAFITETOCPASSWORD 45610)

(RPAQQ TIME.ACCEPTOR (((0 [LAMBDA (X)
				  (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			  0)
		       (0 [LAMBDA (X)
				  (AND (NUMBERP X)
				       (SETQ HOUR X]
			  1)
		       (1 [LAMBDA (X)
				  (AND (NUMBERP X)
				       (LESSP (SETQ HOUR (PLUS X (ITIMES 10 HOUR)))
					      24]
			  2)
		       (1 [LAMBDA (X)
				  (EQ X (QUOTE :]
			  3)
		       (2 [LAMBDA (X)
				  (EQ X (QUOTE :]
			  3)
		       (3 [LAMBDA (X)
				  (AND (NUMBERP X)
				       (SETQ MINUTE X]
			  4)
		       (4 [LAMBDA (X)
				  (AND (NUMBERP X)
				       (LESSP (SETQ MINUTE (PLUS X (ITIMES 10 MINUTE)))
					      60]
			  5)
		       (4 [LAMBDA (X)
				  (EQ X (QUOTE :]
			  6)
		       (4 [LAMBDA (X)
				  (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			  12)
		       (4 [LAMBDA (X)
				  (UCASE.STREQUAL X (QUOTE A]
			  11)
		       (4 [LAMBDA (X)
				  (UCASE.STREQUAL X (QUOTE P]
			  9)
		       (5 [LAMBDA (X)
				  (EQ X (QUOTE :]
			  6)
		       (5 [LAMBDA (X)
				  (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			  12)
		       (5 [LAMBDA (X)
				  (UCASE.STREQUAL X (QUOTE A]
			  11)
		       (5 [LAMBDA (X)
				  (UCASE.STREQUAL X (QUOTE P]
			  9)
		       (6 [LAMBDA (X)
				  (AND (NUMBERP X)
				       (SETQ SECOND X]
			  7)
		       (7 [LAMBDA (X)
				  (AND (NUMBERP X)
				       (LESSP (SETQ SECOND (PLUS X (ITIMES 10 SECOND)))
					      60]
			  8)
		       (7 [LAMBDA (X)
				  (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			  12)
		       (8 [LAMBDA (X)
				  (UCASE.STREQUAL X (QUOTE A]
			  11)
		       (8 [LAMBDA (X)
				  (UCASE.STREQUAL X (QUOTE P]
			  9)
		       (8 [LAMBDA (X)
				  (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			  12)
		       (9 [LAMBDA (X)
				  (AND (UCASE.STREQUAL X (QUOTE M))
				       (COND ((LESSP HOUR 12)
					      (SETQ HOUR (PLUS HOUR 12)))
					     (T T]
			  10)
		       (10 [LAMBDA (X)
				   (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			   12)
		       (11 [LAMBDA (X)
				   (AND (UCASE.STREQUAL X (QUOTE M))
					(LESSP HOUR 13)
					(COND ((EQ HOUR 12)
					       (SETQ HOUR 0))
					      (T T]
			   10)
		       (12 [LAMBDA (X)
				   (MAILOMAT.BLANKP X TIME.ACCEPTOR]
			   12)
		       (12 [LAMBDA (X)
				   (AND (NUMBERP X)
					(SETQ TIME.LIST (MAILOMAT.APPEND.TIME TIME.LIST 
									      HOUR MINUTE 
									      SECOND))
					(SETQ HOUR X)
					(SETQ MINUTE 0)
					(SETQ SECOND 0]
			   1))
		      0
		      (4 5 7 8 10 12)
		      (MAILOMAT.APPEND.TIME (TIME.LIST HOUR MINUTE SECOND))
		      (%  %
 % )))

(RPAQQ UNSEENFLAG 85)

(RPAQQ DELETEDFLAG 68)

(RPAQQ SEENFLAG 83)

(RPAQQ UNDELETEDFLAG 85)

(CONSTANTS LAFITETOCHEADERLENGTH LAFITETOCPASSWORD TIME.ACCEPTOR UNSEENFLAG DELETEDFLAG 
	   SEENFLAG UNDELETEDFLAG)
)

(RPAQQ MAILOMAT.FORM.FIELDS ((Mail% Folder: MAILFOLDER)
			     (Username: USERNAME)
			     (Hardcopy: HARDCOPY)
			     (Print% Server: PRINTSERVER)
			     (Firing% Mode: FIRINGMODE)
			     (Firing% Times: FIRINGTIMES)
			     (Start% Time: STARTIME)
			     (Time% Period: TIMEPERIOD)
			     (Time% Unit: TIMEUNIT)
			     (Activation: ACTIVATION)))

(RPAQQ MAILOMAT.FORM.FORMAT (Mail% Folder: CR Username: TAB Password: CR Hardcopy: TAB 
					   Print% Server: CR Firing% Mode: CR 
					   Firing% Times: CR Start% Time: TAB 
					   Time% Period: CR Time% Unit: TAB Activation: 
					   CR))

(RPAQQ MAILOMAT.FORM.SPECS ((Mail% Folder: FIELDTYPE STRING)
			    (Username: FIELDTYPE STRING)
			    (Password: FIELDTYPE STRING FN MAILOMAT.GET.PASSWORD)
			    (Hardcopy: FIELDTYPE MENU MENULIST (Yes No))
			    (Print% Server: FIELDTYPE STRING)
			    (Firing% Mode: FIELDTYPE MENU MENULIST (Time% of% Day 
									Fixed% Period))
			    (Firing% Times: FIELDTYPE STRING)
			    (Start% Time: FIELDTYPE STRING)
			    (Time% Period: FIELDTYPE STRING)
			    (Time% Unit: FIELDTYPE MENU MENULIST (Days Hours Minutes))
			    (Activation: FIELDTYPE MENU MENULIST (On Off))))

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

(RPAQ? MAILOMATFONT (FONTCREATE (QUOTE TIMESROMAN)
				8))

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

(RPAQ? MAILOMAT.USER.LIST (QUOTE ((**% OTHER% **))))

(RPAQ? MAILOMATFORMTEMPLATE NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS MAILOMATFONT MAILOMATBOLDFONT)
)

(ADDTOVAR BackgroundMenuCommands ("MAILOMAT Panel" (QUOTE (MAILOMAT.PANEL.CREATE))
						   "Bulk mail process a user's mail"))

(RPAQQ BackgroundMenu NIL)
(DECLARE: EVAL@COMPILE 

(PUTPROPS MAILOMAT.ENTRY.PTR.TO.KEY.VAL.PTR MACRO [X
	    (BQUOTE (IPLUS , (CADR X)
			   (IQUOTIENT (IDIFFERENCE , (CAR X)
						   MAILOMAT.INDEX.ENTRY.BEGIN.PTR)
				      MAILOMAT.INDEX.ENTRY.SIZE])

(PUTPROPS MAILOMAT.ENTRY.TO.NUM MACRO [X (BQUOTE (PROGN (SETFILEPTR MAILOMAT.INDEX.FILE ,
								    (CAR X))
							(\DWIN MAILOMAT.INDEX.FILE])

(PUTPROPS MAILOMAT.INDEX.DATA.CONTEXT MACRO [X
	    (BQUOTE (WITH.MONITOR MAILOMAT.INDEX.MONITORLOCK
				  (PROG (MAILOMAT.INDEX.FILE 
						       MAILOMAT.INDEX.ENTRY.BEGIN.PTR 
							 MAILOMAT.INDEX.ENTRY.END.PTR 
							    MAILOMAT.INDEX.ENTRY.SIZE 
							   MAILOMAT.INDEX.FIELD.SPECS 
							    MAILOMAT.INDEX.FIELD.LIST)
				        (DECLARE (SPECVARS MAILOMAT.INDEX.FILE 
						       MAILOMAT.INDEX.ENTRY.BEGIN.PTR 
							 MAILOMAT.INDEX.ENTRY.END.PTR 
							   MAILOMAT.INDEX.ENTRY.SIZE 
							   MAILOMAT.INDEX.FIELD.SPECS 
							   MAILOMAT.INDEX.FIELD.LIST))
				        (MAILOMAT.INDEX.DATA.UNPACK (WINDOWPROP
								      ,
								      (CAR X)
								      (QUOTE 
								  MAILOMAT.INDEX.DATA)))
				        (MAILOMAT.INDEX.FILE.REOPEN , (CAR X))
				        (RETURN (PROGN ,@(CDR X])

(PUTPROPS MAILOMAT.KEY.VAL.PTR.TO.ENTRY.PTR MACRO (X
	    (BQUOTE (IPLUS (ITIMES MAILOMAT.INDEX.ENTRY.SIZE (IDIFFERENCE , (CAR X)
									  ,
									  (CADR X)))
			   MAILOMAT.INDEX.ENTRY.BEGIN.PTR))))

(PUTPROPS MAILOMATSPECGET MACRO [X (BQUOTE (LISTGET (CDR (ASSOC , (CADR X)
								,
								(CAR X)))
						    ,
						    (CADDR X])

(PUTPROPS ARSPECPUT MACRO [X (BQUOTE (LISTPUT (CDR (ASSOC , (CADR X)
							  ,
							  (CAR X)))
					      ,
					      (CADDR X)
					      ,
					      (CADDDR X])

(PUTPROPS FIXPIN DMACRO (OPENLAMBDA (STREAM)
				    (\MAKENUMBER (WORDIN STREAM)
						 (WORDIN STREAM))))

(PUTPROPS FIXPOUT DMACRO [OPENLAMBDA (STREAM N)
				     (PROGN (WORDOUT STREAM (LRSH N 16))
					    (WORDOUT STREAM (LOGAND N 65535])

(PUTPROPS IMAGEOBJPROPS MACRO (X (IMAGEOBJPROPS.MACRO X)))

(PUTPROPS UCASE.STREQUAL MACRO ((X Y)
				(EQ (ALPHORDER X Y UPPERCASEARRAY)
				    (QUOTE EQUAL))))

(PUTPROPS WORDIN DMACRO (= . \WIN))

(PUTPROPS WORDIN MACRO (= . \WIN))

(PUTPROPS WORDOUT DMACRO (= . \WOUT))
)
[DECLARE: EVAL@COMPILE 

(RECORD MAILOMAT.USERDATA (LAFITE.USERDATA USERNAME PASSWORD MAILFOLDER HARDCOPY 
					   PRINTSERVER FIRINGMODE FIRINGTIMES STARTIME 
					   TIMEPERIOD TIMEUNIT ACTIVATION SERVERPROCESS))

(RECORD DEFAULTHOST&DIR (PACKEDHOST&DIR . UNPACKEDHOST&DIR)
			(PROPRECORD UNPACKEDHOST&DIR (DEFAULTDIR DEFAULTHOST DEFAULTDEV)))

(RECORD FSM (TRANSITIONS START.STATE ACCEPT.STATES ACCEPT.RESULT BLANKS))

(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)
		     (MARKSCHANGED? FLAG)
		     (SELECTED? FLAG)
		     (MSGFROMMECHECKED? FLAG)
		     (MSGFROMMETRUTH FLAG)
		     (NIL FLAG)
		     (NIL FLAG)
		     (NIL FLAG)
		     (DATE POINTER)
		     (FROM POINTER)
		     (SUBJECT POINTER)
		     (TO POINTER))                    (* BEGIN is the only absolute pointer into the message file --
						      all other positions are relative to BEGIN -- see the ACCESSFNS
						      *)
		    (BLOCKRECORD LAFITEMSG ((PARSED&DELETED&SEENBITS BITS 3)
				  (NIL BITS 5)
				  (NIL POINTER)))
		    (BLOCKRECORD LAFITEMSG ((MSGFLAGBITS BITS 8)
				  (NIL POINTER)))
		    [ACCESSFNS LAFITEMSG ((END (IPLUS (fetch (LAFITEMSG MESSAGELENGTH)
							 of DATUM)
						      (fetch (LAFITEMSG BEGIN)
							 of DATUM)))
				(START (IPLUS (fetch (LAFITEMSG BEGIN) of DATUM)
					      (fetch (LAFITEMSG STAMPLENGTH)
						 of DATUM)))
				(SEENFILEPTR (IPLUS (fetch (LAFITEMSG BEGIN)
						       of DATUM)
						    LAFITESEENPOSITION))
				(MARKFILEPTR (IPLUS (fetch (LAFITEMSG BEGIN)
						       of DATUM)
						    LAFITEMARKPOSITION))
				(DELETEFILEPTR (IPLUS (fetch (LAFITEMSG BEGIN)
							 of DATUM)
						      LAFITEDELETEPOSITION))
				(MSGFROMMEP (COND
					      ((fetch (LAFITEMSG MSGFROMMECHECKED?)
						  of DATUM)
						(fetch (LAFITEMSG MSGFROMMETRUTH)
						   of DATUM))
					      (T (LA.MSGFROMMEP DATUM)))
					    (PROG1 (replace (LAFITEMSG MSGFROMMETRUTH)
						      of DATUM with NEWVALUE)
						   (replace (LAFITEMSG MSGFROMMECHECKED?)
						      of DATUM with T])

(RECORD LAFITEOPS (LAFITEMODE SENDPARSER SENDER ANSWERER AUTHENTICATOR))

(RECORD LAFITEUSERDATA (FULLUSERNAME UNPACKEDUSERNAME ENCRYPTEDPASSWORD SHORTUSERNAME . 
				     MAILSERVERS))

(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)))

(RECORD MAILSERVER (MAILSERVEROPS MAILPORT MAILSERVERNAME CONTINUANCE . MAILSTATE))

(RECORD MAILSERVEROPS (POLLNEWMAIL OPENMAILBOX NEXTMESSAGE RETRIEVEMESSAGE CLOSEMAILBOX 
				   SERVERPORTFROMNAME))

(RECORD OPENEDMAILBOX (MAILBOX . PROPERTIES)
		      (PROPRECORD PROPERTIES (#OFMESSAGES)))

(RECORD TRANSITION (CURRENT.STATE PREDICATE NEXT.STATE))
]
(/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))
(/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))
(READVARS MAILOMAT.FORM.ICON MAILOMAT.FORM.MASK)
({(READBITMAP)(105 103
"@@COOOOOOOOOOOOOOOOOOOOOOOH@"
"@@O@@@@@@@@@@@@@@@@@@@@@@OH@"
"@@O@@@@@@@@@@@@@@@@@@@@@@OH@"
"@CL@@@@@@@@@@@@@@@@@@@@@CLH@"
"@CL@@@@@@@@@@@@@@@@@@@@@CLH@"
"@O@@@@@@@@@@@@@@@@@@@@@@O@H@"
"@O@@@@@@@@@@@@@@@@@@@@@@O@H@"
"CL@@@@@@@@@@@@@@@@@@@@@CL@H@"
"CL@@@@@@@@@@@@@@@@@@@@@CL@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OCOOOOOOO@@C@@@@@@@@@@@O@@H@"
"OCOOOOOOO@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@OOOOOOOOOC@OOOOO@@@@@O@@H@"
"O@OOOOOOOOOC@OOOOO@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OCOOOOOOOO@C@OOOOOOOOL@O@@H@"
"OCOOOOOOOO@C@OOOOOOOOL@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@OOOOCCOOOOL@@@@@O@@H@"
"O@@@@@@OOOOCCOOOOL@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@COOOOOOO@C@@OOOOOOO@@O@@H@"
"O@COOOOOOO@C@@OOOOOOO@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OCOOOOOOOOLCCOOOOO@@@@@O@@H@"
"OCOOOOOOOOLCCOOOOO@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@COOOOL@@@O@@H@"
"O@@@@@@@@@@C@@COOOOL@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OCOOOOOOOL@C@@@COOOOOL@O@@H@"
"OCOOOOOOOL@C@@@COOOOOL@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@C@@@@@@@@@@@O@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@@H@"
"O@@@@@@@@@@@@@@@@@@@@@@O@CH@"
"O@@@@@@@@@@@@@@@@@@@@@@O@CH@"
"O@@@@@@@@@@@@@@@@@@@@@@O@O@@"
"O@@@@@@@@@@@@@@@@@@@@@@O@O@@"
"O@@@@@@@@@@@@@@@@@@@@@@OCL@@"
"O@@@@@@@@@@@@@@@@@@@@@@OCL@@"
"O@@@@@@@@@@@@@@@@@@@@@@OO@@@"
"O@@@@@@@@@@@@@@@@@@@@@@OO@@@"
"OOOOOOOOOOOOOOOOOOOOOOOOL@@@"
"OOOOOOOOOOOOOOOOOOOOOOOOL@@@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@@@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@@@")}  {(READBITMAP)(105 103
"@@COOOOOOOOOOOOOOOOOOOOOOOH@"
"@@OOOOOOOOOOOOOOOOOOOOOOOOH@"
"@@OOOOOOOOOOOOOOOOOOOOOOOOH@"
"@COOOOOOOOOOOOOOOOOOOOOOOOH@"
"@COOOOOOOOOOOOOOOOOOOOOOOOH@"
"@OOOOOOOOOOOOOOOOOOOOOOOOOH@"
"@OOOOOOOOOOOOOOOOOOOOOOOOOH@"
"COOOOOOOOOOOOOOOOOOOOOOOOOH@"
"COOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOOH@"
"OOOOOOOOOOOOOOOOOOOOOOOOOO@@"
"OOOOOOOOOOOOOOOOOOOOOOOOOO@@"
"OOOOOOOOOOOOOOOOOOOOOOOOOL@@"
"OOOOOOOOOOOOOOOOOOOOOOOOOL@@"
"OOOOOOOOOOOOOOOOOOOOOOOOO@@@"
"OOOOOOOOOOOOOOOOOOOOOOOOO@@@"
"OOOOOOOOOOOOOOOOOOOOOOOOL@@@"
"OOOOOOOOOOOOOOOOOOOOOOOOL@@@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@@@"
"OOOOOOOOOOOOOOOOOOOOOOOO@@@@")})
(DECLARE: EVAL@COMPILE 
[PUTDEF (QUOTE SCRATCHSTRING)
	(QUOTE RESOURCES)
	(QUOTE (NEW (ALLOCSTRING 100]
)
(DECLARE: EVAL@COMPILE 
[I.S.OPR (QUOTE SELECTEDIN)
	 NIL
	 (QUOTE (bind ($$MESSAGES ← (fetch (MAILFOLDER MESSAGEDESCRIPTORS)
					   of BODY))
		      ($$MSG# ← (SUB1 (fetch (MAILFOLDER FIRSTSELECTEDMESSAGE)
					     of BODY)))
		      ($$MSGLAST ← (fetch (MAILFOLDER LASTSELECTEDMESSAGE)
					  of BODY))
		      until
		      (IGREATERP (add $$MSG# 1)
				 $$MSGLAST)
		      when
		      (fetch (LAFITEMSG SELECTED?)
			     of
			     (SETQ I.V. (NTHMESSAGE $$MESSAGES $$MSG#]
)
(MAILOMAT.INIT)
(PUTPROPS MAILOMAT COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (4050 102505 (MAILOMAT.ADD.USER 4060 . 6110) (MAILOMAT.APPEND.TIME 6112 . 
6362) (MAILOMAT.APPENDMESSAGES 6364 . 7402) (MAILOMAT.ENCODE.PERIODIC.PARAMS 7404 . 8292) 
(MAILOMAT.ENCODE.START.TIME 8294 . 8887) (MAILOMAT.ENCODE.TIME.UNIT 8889 . 9338) (
MAILOMAT.ENCODE.TOD.PARAMS 9340 . 9793) (MAILOMAT.ENCODE.USER.DATA 9795 . 11875) (
MAILOMAT.EXTRACT.FIELDS 11877 . 13107) (MAILOMAT.HARDCOPY 13109 . 13967) (
MAILOMAT.MENU.FN.PUT 13969 . 15709) (MAILOMAT.INFER.USERNAME 15711 . 16641) (
MAILOMAT.UPDATECONTENTSFILE 16643 . 19936) (MAILOMAT.UPDATEMAILFOLDER 19938 . 20809) (
MAILOMAT.BLANKP 20811 . 20976) (MAILOMAT.BUTTON.GET.MENU 20978 . 21509) (
MAILOMAT.BUTTON.GET.SUBMENU 21511 . 22533) (MAILOMAT.BUTTON.OBJ.CREATE 22535 . 25423) (
MAILOMAT.BUTTONFN.DOMENU 25425 . 26534) (MAILOMAT.BUTTONFN.DOSUBMENU 26536 . 27200) (
MAILOMAT.BUTTONFN.SELFIELD 27202 . 27815) (MAILOMAT.CHECK.FIELDS 27817 . 29180) (
MAILOMAT.CHECK.MENU 29182 . 30150) (MAILOMAT.CHECK.SHORTSTRING 30152 . 30498) (
MAILOMAT.CHECK.SUBMENU 30500 . 31712) (MAILOMAT.CONFIRM 31714 . 31928) (
MAILOMAT.DELETE.FIELD.VAL 31930 . 32842) (MAILOMAT.DISCONNECT.WINDOW 32844 . 33092) (
MAILOMAT.FIND.BUTTON 33094 . 33574) (MAILOMAT.FIND.EDIT.CHANGES 33576 . 36848) (
MAILOMAT.FIND.UNPROTECTED.CH# 36850 . 37549) (MAILOMAT.FORM.CLEAR 37551 . 38189) (
MAILOMAT.FORM.CREATE 38191 . 43271) (MAILOMAT.FORM.FILL.INS 43273 . 43408) (
MAILOMAT.FULLUSERNAME 43410 . 44314) (MAILOMAT.ICONFN 44316 . 45348) (
MAILOMAT.INDEX.FIRING.TIMES 45350 . 45592) (MAILOMAT.INIT 45594 . 46565) (
MAILOMAT.INIT.MAIL.USER 46567 . 48641) (MAILOMAT.LOAD.FIELDS 48643 . 49645) (
MAILOMAT.LOAD.FROM.PROFILE 49647 . 51178) (MAILOMAT.LOADMAILFOLDER 51180 . 52377) (
MAILOMAT.PANEL.CREATE 52379 . 52806) (MAILOMAT.PARSE.TIME 52808 . 54204) (
MAILOMAT.PARSEMAILFOLDER1 54206 . 57505) (MAILOMAT.FORM.GROUP.CREATE 57507 . 60666) (
MAILOMAT.KILL.ATTACHED.TEDIT.CLOSEFN 60668 . 61654) (MAILOMAT.FORM.MENU.ACTIONFN 61656 . 
64051) (MAILOMAT.GET.MAILOMAT 64053 . 64701) (MAILOMAT.GET.PASSWORD 64703 . 65543) (
MAILOMAT.GETMAILFOLDER 65545 . 67932) (MAILOMAT.GETNEWMAIL 67934 . 69113) (
MAILOMAT.GETNEWMAIL1 69115 . 70899) (MAILOMAT.FORM.MENU.BUTTONFN 70901 . 71178) (
MAILOMAT.FORM.SAVE 71180 . 74016) (MAILOMAT.GET.FILENAME 74018 . 74350) (
MAILOMAT.GET.ASSOCIATED.MENU.BUTTON.VAL 74352 . 74804) (MAILOMAT.GET.ASSOCIATED.MENU.VAL 
74806 . 75382) (MAILOMAT.GET.BUTTON.FIELD.AS.TEXT 75384 . 76052) (
MAILOMAT.GET.BUTTON.FIELD.AS.LIST 76054 . 76401) (MAILOMAT.MARK.ACTIVE 76403 . 76609) (
MAILOMAT.MARK.HARDCOPIED 76611 . 77363) (MAILOMAT.MENU.CR.FN 77365 . 77599) (
MAILOMAT.MENU.FN.CLEAR 77601 . 78057) (MAILOMAT.MENU.FN.GET 78059 . 79035) (
MAILOMAT.MENU.FN.APPLY 79037 . 80689) (MAILOMAT.GET.USERNAME 80691 . 81186) (
MAILOMAT.OPEN.MAILFOLDER 81188 . 83036) (MAILOMAT.PRESENT.TIME 83038 . 83401) (
MAILOMAT.PROCESS.FILE 83403 . 85942) (MAILOMAT.PROMPT 85944 . 86287) (
MAILOMAT.PROTECT.WARNING 86289 . 86552) (MAILOMAT.PUT.FAILED 86554 . 86814) (
MAILOMAT.READTOCFILE 86816 . 91899) (MAILOMAT.RECONNECT.WINDOW 91901 . 92366) (
MAILOMAT.REMOVE.USER 92368 . 92768) (MAILOMAT.REPLACE.FIELD.VAL 92770 . 94552) (
MAILOMAT.REPLACE.FILL.INS 94554 . 95092) (MAILOMAT.RESET.SEL 95094 . 95706) (
MAILOMAT.SCRATCH.LOAD 95708 . 96442) (MAILOMAT.SELECTMESSAGE 96444 . 96672) (
MAILOMAT.TEXTSTREAM.LOAD 96674 . 99356) (MAILOMAT.TIME.OF.DAY.WAKEUP 99358 . 100492) (
MAILOMAT.TOBJ.ACTIVEP 100494 . 100717) (MAILOMAT.TRANSMIT.HARDCOPY 100719 . 101705) (
MAILOMAT.PERIODIC.WAKEUP 101707 . 102503)))))
STOP