(FILECREATED "15-Jan-85 13:24:35" {ERIS}<SPEECH>MAILREADER>PROSE-LAFITE-MESSAGES.;2 23187  

      previous date: "14-Jan-85 18:21:38" {ERIS}<SPEECH>MAILREADER>PROSE-LAFITE-MESSAGES.;1)


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

(PRETTYCOMPRINT PROSE-LAFITE-MESSAGESCOMS)

(RPAQQ PROSE-LAFITE-MESSAGESCOMS [(FNS LAB.PROMPTPRINT \LAFITE.GETNEWMAIL1 BADMAILFILE.FLAGBYTE 
				       \LAFITE.GETNEWMAIL BADMAILFILE VERIFYFAILED READTOCFILE 
				       VERIFYMAILFOLDER \LAFITE.VERIFYMSG PARSEMAILFOLDER1 
				       LOADMAILFOLDER)
				  (DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS
					    (ADDVARS (NLAMA)
						     (NLAML)
						     (LAMA LAB.PROMPTPRINT])
(DEFINEQ

(LAB.PROMPTPRINT
  [LAMBDA FOLDER&ARGS                                        (* lfg: "14-Jan-85 17:21")
    (PROG ((MAILFOLDER (\DTEST (ARG FOLDER&ARGS 1)
			       (QUOTE MAILFOLDER)))
	   WINDOW)
          (SETQ WINDOW (ffetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER))
          (CLEARW WINDOW)
          (for I from 2 to FOLDER&ARGS do (PRIN3 (ARG FOLDER&ARGS I)
						 WINDOW))
          (for I from 2 to FOLDER&ARGS do (SAYT (ARG FOLDER&ARGS I)))
          (freplace (MAILFOLDER BROWSERPROMPTDIRTY) of MAILFOLDER with T])

(\LAFITE.GETNEWMAIL1
  [LAMBDA (MAILSERVER MAILFOLDER OUTSTREAM REPORTWINDOW)     (* lfg: "14-Jan-85 17:25")
    (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 (printout REPORTWINDOW " empty")
			  (RETURN))
		   (NIL                                      (* No response))
		   (COND
		     (MAILBOX (PRINTLAFITESTATUS (QUOTE NEW.MAIL))
			      (UNSELECTALLMESSAGES MAILFOLDER)
			      (COND
				((SETQ #OFMESSAGES (fetch (OPENEDMAILBOX #OFMESSAGES) of OPENRESULT))
				  (SAYT (CONCAT #OFMESSAGES (if (EQ #OFMESSAGES 1)
								then " message. "
							      else " messages. ")))
				  (\LAFITE.GETNEWMAIL# REPORTWINDOW #OFMESSAGES)))
			      (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)
					  (printout REPORTWINDOW " done")
					  [COND
					    ((NULL #OFMESSAGES)
					      (\LAFITE.GETNEWMAIL# REPORTWINDOW (LENGTH MESSAGELIST]
					  MESSAGELIST)
					(T                   (* \LAFITE.RETRIEVEMESSAGES already set the file ptr 
							     back, etc *)
					   (printout REPORTWINDOW " retrieval aborted")
					   (APPLY* (fetch (MAILSERVER CLOSEMAILBOX) of MAILSERVER)
						   MAILBOX NIL)
					   NIL]
          (printout REPORTWINDOW " not responding")
          (COND
	    ((CDR (LISTP OPENRESULT))                        (* Say more about why not responding)
	      (printout REPORTWINDOW " (" (fetch (OPENEDMAILBOX PROPERTIES) of OPENRESULT)
			")"])

(BADMAILFILE.FLAGBYTE
  [LAMBDA (MAILFOLDER MSG#)                                  (* lfg: "14-Jan-85 17:28")
    (PROGN (printout (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER)
		     " [at msg " .P2 MSG# ": bad flag byte] ")
	   (SAYT (CONCAT (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER)
			 " at msg " .P2 MSG# ": bad flag byte. "))
	   NIL])

(\LAFITE.GETNEWMAIL
  [LAMBDA (MAILFOLDER WINDOW)                                (* lfg: "14-Jan-85 17:24")
    (PROG ((REPORTWINDOW (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER))
	   (OUTSTREAM (\LAFITE.OPEN.FOLDER MAILFOLDER (QUOTE APPEND)))
	   FIRSTMESSAGE)
          [for MAILSERVER in [fetch (LAFITEUSERDATA MAILSERVERS)
				of (OR (\LAFITE.GET.USER.DATA)
				       (PROGN (printout REPORTWINDOW "No mailboxes known")
					      (P.CHUNK "No mailboxes known")
					      (GO EXIT]
	     bind MESSAGELIST NTHTIME when (PROGN (COND
						    (NTHTIME (printout REPORTWINDOW "; "))
						    (T (SETQ NTHTIME T)))
						  (SAYT (CONCAT "Fetching mail from "
								(fetch (MAILSERVER MAILSERVERNAME)
								   of MAILSERVER)))
						  (printout REPORTWINDOW (fetch (MAILSERVER 
										   MAILSERVERNAME)
									    of MAILSERVER)
							    " ..")
						  (SETQ MESSAGELIST (\LAFITE.GETNEWMAIL1 MAILSERVER 
										       MAILFOLDER 
											OUTSTREAM 
										     REPORTWINDOW)))
	     do (LAB.APPENDMESSAGES MAILFOLDER MESSAGELIST)
		(OR FIRSTMESSAGE (SETQ FIRSTMESSAGE (CAR MESSAGELIST]
                                                             (* select the first new message -- all former messages 
							     have already been unselected)
          (printout REPORTWINDOW (QUOTE %.))
          [COND
	    (FIRSTMESSAGE                                    (* If any mail was retrieved, select the first message 
							     and make sure it is visible)
			  (SELECTMESSAGE FIRSTMESSAGE MAILFOLDER)
			  (LAB.EXPOSEMESSAGE MAILFOLDER FIRSTMESSAGE)
			  (COND
			    ((AND LAFITEGETMAILTUNE (EQ (MACHINETYPE)
							(QUOTE DANDELION)))
			      (PLAYTUNE LAFITEGETMAILTUNE]
      EXIT(replace (MAILFOLDER BROWSERPROMPTDIRTY) of MAILFOLDER with T])

(BADMAILFILE
  [LAMBDA (MAILFOLDER HERE MSG# ERRSTR LASTMSG NOERROR)      (* lfg: "14-Jan-85 17:13")
    [COND
      ((OR (NOT NOERROR)
	   LAFITEDEBUGFLG)
	(PROG ((BROWSERWINDOW (fetch (MAILFOLDER BROWSERWINDOW) of MAILFOLDER)))
	      (CLEARW BROWSERWINDOW)
	      (printout BROWSERWINDOW "Cannot parse file " (fetch (MAILFOLDER FULLFOLDERNAME)
							      of MAILFOLDER)
			" near message " .P2 MSG# ", byte " .P2 HERE " because: " ERRSTR)
	      (P.CHUNK "Cannot parse file.  Please have someone scavenge your mail file. ")
	      [COND
		(LASTMSG (printout BROWSERWINDOW T "Last message was:" T "Date: "
				   (fetch (LAFITEMSG DATE) of LASTMSG)
				   T "From: " (fetch (LAFITEMSG FROM) of LASTMSG)
				   T "Subject: " (fetch (LAFITEMSG SUBJECT) of LASTMSG]
	      (COND
		(LAFITEDEBUGFLG (HELP "Mail file parsing error" ERRSTR]
    NIL])

(VERIFYFAILED
  [LAMBDA (ERRMSG)                                           (* lfg: "14-Jan-85 17:30")
    (DECLARE (USEDFREE MSG#))
    (P.CHUNK (CONCAT "Error in message " MSG# ": "))
    (RETFROM (QUOTE P.CONTROLLER))
    (HELP (CONCAT "Error in message " MSG# ": ")
	  ERRMSG])

(READTOCFILE
  [LAMBDA (MAILFOLDER TOCFILE)                               (* lfg: "14-Jan-85 17:31")

          (* * 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 (printout (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER)
			"Reading table of contents...")
	      (SAYT "Reading table of contents. ")
	      (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)
			    (printout (fetch BROWSERPROMPTWINDOW of MAILFOLDER)
				      "(older format)")
			    (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 (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])

(VERIFYMAILFOLDER
  [LAMBDA (MAILFOLDER)                                       (* lfg: "14-Jan-85 17:30")
    (DECLARE (SPECVARS MSG# MSG HERE CHCOUNT))
    [COND
      ((NOT (type? MAILFOLDER MAILFOLDER))
	(SETQ MAILFOLDER (\DTEST (COND
				   ((WINDOWP MAILFOLDER)
				     (WINDOWPROP MAILFOLDER (QUOTE MAILFOLDER)))
				   ((LITATOM MAILFOLDER)
				     (\LAFITE.GETMAILFOLDER MAILFOLDER)))
				 (QUOTE MAILFOLDER]
    (WITH.MONITOR (fetch (MAILFOLDER FOLDERLOCK) of MAILFOLDER)
		  (PROG (STREAM END)
		        (SETQ STREAM (\LAFITE.OPEN.FOLDER MAILFOLDER (QUOTE INPUT)
							  (QUOTE OLD)))
		        (OR (IEQP (SETQ END (GETEOFPTR STREAM))
				  (fetch (MAILFOLDER FOLDEREOFPTR) of MAILFOLDER))
			    (P.CHUNK "Length of file does not match Folder's idea of length")
			    (RETFROM P.CONTROLLER)
			    (HELP "Length of file does not match Folder's idea of length"
				  (LIST END)))
		        [bind CHCOUNT STAMPCOUNT MARK MSG (HERE ← 0)
			      (MESSAGES ←(fetch (MAILFOLDER MESSAGEDESCRIPTORS) of MAILFOLDER))
			      (LASTMSG# ←(fetch (MAILFOLDER #OFMESSAGES) of MAILFOLDER))
			   for MSG# from 1 while (ILESSP HERE END)
			   do (SETFILEPTR STREAM HERE)
			      [COND
				((IGREATERP MSG# LASTMSG#)
				  (RETURN (VERIFYFAILED "More messages in file than in core"]
			      (SETQ MSG (NTHMESSAGE MESSAGES MSG#)) 

          (* * 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
				((NOT (IEQP (fetch (LAFITEMSG BEGIN) of MSG)
					    HERE))
				  (VERIFYFAILED "Message beginning pointer wrong"))
				((NOT (LA.READSTAMP STREAM))
				  (VERIFYFAILED "Bad Stamp"))
				([OR (NOT (SETQ CHCOUNT (LA.READCOUNT STREAM)))
				     (NOT (IEQP CHCOUNT (fetch (LAFITEMSG MESSAGELENGTH)
							   of MSG]
				  (VERIFYFAILED "Bad Message Length"))
				([OR (NOT (SETQ STAMPCOUNT (LA.READCOUNT STREAM)))
				     (NOT (IEQP STAMPCOUNT (fetch (LAFITEMSG STAMPLENGTH)
							      of MSG]
				  (VERIFYFAILED "Bad Message Length"))
				((fetch (LAFITEMSG MARKSCHANGED?) of MSG))
				((NOT (EQ (SELECTC (BIN STREAM)
						   (UNDELETEDFLAG NIL)
						   (DELETEDFLAG T)
						   (QUOTE ?))
					  (fetch (LAFITEMSG DELETED?) of MSG)))
				  (VERIFYFAILED "Disagreement in delete mark"))
				((NOT (EQ (SELECTC (BIN STREAM)
						   (UNSEENFLAG NIL)
						   (SEENFLAG T)
						   (QUOTE ?))
					  (fetch (LAFITEMSG SEEN?) of MSG)))
                                                             (* Figure out how to handle seen from me)
				  (VERIFYFAILED "Disagreement in seen mark"))
				([NOT (OR (EQ (SETQ MARK (BIN STREAM))
					      (fetch (LAFITEMSG MARKCHAR) of MSG))
					  (NOT (fetch (LAFITEMSG SEEN?) of MSG]
				  (VERIFYFAILED "Disagreement in mark byte")))
			      (add HERE CHCOUNT)
			   finally (COND
				     ((NOT (IEQP HERE END))
				       (VERIFYFAILED "Last message too short"]
		        (RETURN T])

(\LAFITE.VERIFYMSG
  [LAMBDA (MSG MAILFOLDER)                                   (* lfg: "14-Jan-85 17:33")
    (PROG ((STREAM (fetch (MAILFOLDER FOLDERSTREAM) of MAILFOLDER)))
          (SETFILEPTR STREAM (fetch (LAFITEMSG BEGIN) of MSG))
          (OR (LA.READSTAMP STREAM)
	      (P.CHUNK (CONCAT "Inconsistency in table of contents at message number "
			       (fetch (LAFITEMSG #) of MSG)
			       (CONCAT "Inconsistency in table of contents at message number "
				       (fetch (LAFITEMSG #) of MSG)
				       
".
Lafite's parse of the file is incorrect at this point.  Recommendation: close browser with option Don't Update, delete "
				       (TOCFILENAME (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER))
				       ", then browse this folder again to reparse.")
			       (TOCFILENAME (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER))
			       ", then browse this folder again to reparse."))
	      (RETFROM (QUOTE P.CONTROLLER))
	      (HELP (CONCAT "Inconsistency in table of contents at message number "
			    (fetch (LAFITEMSG #) of MSG)
			    
".
Lafite's parse of the file is incorrect at this point.  Recommendation: close browser with option Don't Update, delete "
			    (TOCFILENAME (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER))
			    ", then browse this folder again to reparse.")
		    MSG])

(PARSEMAILFOLDER1
  [LAMBDA (MAILFOLDER STREAM EOFPTR START FIRSTMSG# NOERROR)
                                                             (* lfg: "14-Jan-85 18:12")

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


    (printout (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER)
	      "Parsing "
	      (COND
		((ZEROP START)
		  "folder")
		(T "additional msgs"))
	      (QUOTE ...))
    [SAYT (CONCAT "Parsing " (COND
		    ((ZEROP START)
		      "folder")
		    (T "additional msgs. "]
    (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])

(LOADMAILFOLDER
  [LAMBDA (MAILFOLDER)                                       (* lfg: "14-Jan-85 18:13")

          (* LAFITEVERSION# is used to keep track of changed in internal datastructures that get written out to Lafite TOC 
	  files. If the datastructures change, then just change the version number to LAFITEVERSION#+1 and the rest of Lafite 
	  should adjust appropriately. *)


    (PROG ((MAILFILE (fetch (MAILFOLDER FULLFOLDERNAME) of MAILFOLDER))
	   CONTENTSFILE)
          (RETURN (COND
		    ((OR (AND (INFILEP (SETQ CONTENTSFILE (TOCFILENAME MAILFILE)))
			      (READTOCFILE MAILFOLDER CONTENTSFILE))
			 (PARSEMAILFOLDER MAILFOLDER))
		      (SAYT " done.")
		      (printout (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER)
				" done.")
		      [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 (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER)
				 "Failed.")
		       NIL])
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA LAB.PROMPTPRINT)
)
(PUTPROPS PROSE-LAFITE-MESSAGES COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (712 22948 (LAB.PROMPTPRINT 722 . 1356) (\LAFITE.GETNEWMAIL1 1358 . 3792) (
BADMAILFILE.FLAGBYTE 3794 . 4197) (\LAFITE.GETNEWMAIL 4199 . 6200) (BADMAILFILE 6202 . 7141) (
VERIFYFAILED 7143 . 7463) (READTOCFILE 7465 . 12892) (VERIFYMAILFOLDER 12894 . 16455) (
\LAFITE.VERIFYMSG 16457 . 17913) (PARSEMAILFOLDER1 17915 . 21615) (LOADMAILFOLDER 21617 . 22946)))))
STOP