(FILECREATED " 4-Aug-84 17:28:11" {ERIS}<LAFITE>LAFITEFIND.;3 10129  

      changes to:  (VARS LAFITEFINDCOMS)
		   (FNS \LAFITE.DO.FIND)

      previous date: "23-Apr-84 00:33:51" {ERIS}<LAFITE>LAFITEFIND.;2)


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

(PRETTYCOMPRINT LAFITEFINDCOMS)

(RPAQQ LAFITEFINDCOMS [(FNS \LAFITE.FIND \LAFITE.FIND.RELATED \LAFITE.FIND.RELATED.BACKWARD 
			    \LAFITE.FIND.AGAIN \LAFITE.FIND.PROMPT \LAFITE.DO.FIND 
			    LAFITEEXTRABROWSERCOMMANDFN)
		       (DECLARE: EVAL@COMPILE DONTCOPY (RECORDS SEARCHSTATE)
				 (GLOBALVARS LAFITEFINDAREAMENUITEMS LAFITEEXTRAMENUITEMS 
					     LAFITEFINDTYPEMENUITEMS LAFITEFINDTYPEMENU 
					     LAFITEFINDAREAMENU LAFITEEXTRAMENU LAFITEEXTRAMENUFLG 
					     \LAFITE.LAST.SEARCH))
		       (INITVARS LAFITEFINDTYPEMENU LAFITEFINDAREAMENU LAFITEEXTRAMENU)
		       (VARS LAFITEFINDAREAMENUITEMS LAFITEFINDTYPEMENUITEMS LAFITEEXTRAMENUITEMS)
		       (VARS (LAFITEEXTRAMENUFLG T)
			     (\LAFITE.LAST.SEARCH))
		       (DECLARE: DONTEVAL@LOAD DOCOPY (P (MOVD? (QUOTE OPENMAILFOLDER)
								(QUOTE \LAFITE.OPEN.FOLDER])
(DEFINEQ

(\LAFITE.FIND
  [LAMBDA (MAILFOLDER)                                       (* bvm: "23-Apr-84 00:31")
                                                             (* Invoked by Find command)
    (PROG (SEARCHDIRECTION SEARCHAREA SEARCHSTRING)
          (OR [SETQ SEARCHDIRECTION
		(MENU (OR LAFITEFINDTYPEMENU
			  (SETQ LAFITEFINDTYPEMENU
			    (create MENU
				    ITEMS ← LAFITEFINDTYPEMENUITEMS
				    MENUFONT ← LAFITEMENUFONT
				    CENTERFLG ← T]
	      (RETURN))
          (OR [SETQ SEARCHAREA
		(MENU (OR LAFITEFINDAREAMENU
			  (SETQ LAFITEFINDAREAMENU
			    (create MENU
				    ITEMS ← LAFITEFINDAREAMENUITEMS
				    MENUFONT ← LAFITEMENUFONT
				    CENTERFLG ← T]
	      (RETURN))
          (COND
	    ((EQ SEARCHAREA (QUOTE Related))
	      [SETQ SEARCHSTRING (fetch (LAFITEMSG SUBJECT) of (NTHMESSAGE (fetch MESSAGEDESCRIPTORS
									      of MAILFOLDER)
									   (fetch LASTSELECTEDMESSAGE
									      of MAILFOLDER]
	      [COND
		((UCASE.STREQUAL (SUBSTRING SEARCHSTRING 1 4)
				 "Re: ")
		  (SETQ SEARCHSTRING (SUBSTRING SEARCHSTRING 5]
	      (SETQ SEARCHAREA (QUOTE Subject)))
	    ((SETQ SEARCHSTRING (\LAFITE.FIND.PROMPT MAILFOLDER SEARCHAREA)))
	    (T (RETURN)))
          (\LAFITE.DO.FIND MAILFOLDER (CAR SEARCHDIRECTION)
			   SEARCHAREA SEARCHSTRING NIL (EQ (CADR SEARCHDIRECTION)
							   (QUOTE ALL])

(\LAFITE.FIND.RELATED
  [LAMBDA (MAILFOLDER DIRECTION)                             (* bvm: " 5-Mar-84 17:31")
    (PROG [(SEARCHSTRING (fetch (LAFITEMSG SUBJECT) of (NTHMESSAGE (fetch MESSAGEDESCRIPTORS
								      of MAILFOLDER)
								   (fetch LASTSELECTEDMESSAGE
								      of MAILFOLDER]
          [COND
	    ((UCASE.STREQUAL (SUBSTRING SEARCHSTRING 1 4)
			     "Re: ")
	      (SETQ SEARCHSTRING (SUBSTRING SEARCHSTRING 5]
          (\LAFITE.DO.FIND MAILFOLDER (COND
			     ((EQ DIRECTION (QUOTE BACKWARD))
			       DIRECTION)
			     (T (QUOTE FORWARD)))
			   (QUOTE Subject)
			   SEARCHSTRING NIL T])

(\LAFITE.FIND.RELATED.BACKWARD
  [LAMBDA (MAILFOLDER)                                       (* bvm: " 5-Mar-84 17:28")
    (\LAFITE.FIND.RELATED MAILFOLDER (QUOTE BACKWARD])

(\LAFITE.FIND.AGAIN
  [LAMBDA (MAILFOLDER)                                       (* bvm: "24-Mar-84 16:33")
    (PROG ((LASTSEARCH \LAFITE.LAST.SEARCH))
          (COND
	    (LASTSEARCH (\LAFITE.DO.FIND MAILFOLDER (fetch SEARCHDIRECTION of LASTSEARCH)
					 (fetch SEARCHAREA of LASTSEARCH)
					 (fetch SEARCHSTRING of LASTSEARCH)
					 NIL NIL (fetch SEARCHREPLYTO of LASTSEARCH)))
	    (T (\LAFITE.FIND MAILFOLDER])

(\LAFITE.FIND.PROMPT
  [LAMBDA (MAILFOLDER SEARCHAREA)                            (* bvm: "24-Mar-84 16:34")
    (PROG ((WINDOW (fetch (MAILFOLDER BROWSERPROMPTWINDOW) of MAILFOLDER))
	   (LASTSEARCH \LAFITE.LAST.SEARCH))
          (CLEARW WINDOW)
          (RETURN (PROMPTFORWORD (CONCAT "Find " SEARCHAREA " string: ")
				 (AND LASTSEARCH (fetch SEARCHREPLYTO of LASTSEARCH)
				      (fetch SEARCHSTRING of LASTSEARCH))
				 NIL WINDOW NIL NIL (CHARCODE (CR ESC])

(\LAFITE.DO.FIND
  [LAMBDA (MAILFOLDER DIRECTION AREA SEARCHSTRING FROM# ALLFLG REPLYTO?)
                                                             (* bvm: " 4-Aug-84 17:09")
    (PROG ((MESSAGES (fetch (MAILFOLDER MESSAGEDESCRIPTORS) of MAILFOLDER))
	   MSG LASTMSG# MSG# ADDFLG #FOUND INSTREAM CURRENT)
          (SELECTQ DIRECTION
		   [FORWARD (SETQ LASTMSG# (fetch (MAILFOLDER #OFMESSAGES) of MAILFOLDER))
			    (OR FROM# (SETQ FROM# (COND
				    (ALLFLG                  (* Make sure to include any selected messages)
					    (SUB1 (fetch (MAILFOLDER FIRSTSELECTEDMESSAGE)
						     of MAILFOLDER)))
				    (T (fetch (MAILFOLDER LASTSELECTEDMESSAGE) of MAILFOLDER]
		   [BACKWARD (OR FROM# (SETQ FROM# (COND
				     (ALLFLG                 (* Make sure to include any selected messages)
					     (ADD1 (fetch (MAILFOLDER LASTSELECTEDMESSAGE)
						      of MAILFOLDER)))
				     (T (fetch (MAILFOLDER FIRSTSELECTEDMESSAGE) of MAILFOLDER]
		   (SHOULDNT))
          (SELECTQ AREA
		   [Body (SETQ INSTREAM (\LAFITE.OPEN.FOLDER MAILFOLDER (QUOTE INPUT]
		   NIL)
          (SETQ MSG# FROM#)
      LP  [until (SELECTQ DIRECTION
			  (FORWARD (IGREATERP (add MSG# 1)
					      LASTMSG#))
			  (ILEQ (add MSG# -1)
				0))
	     do (SETQ MSG (NTHMESSAGE MESSAGES MSG#))
		(COND
		  ((SELECTQ AREA
			    (From (STRPOS SEARCHSTRING (COND
					    ((fetch (LAFITEMSG MSGFROMMEP) of MSG)
					      (fetch (LAFITEMSG TO) of MSG))
					    (T (fetch (LAFITEMSG FROM) of MSG)))
					  1 NIL NIL NIL UPPERCASEARRAY))
			    (Subject (STRPOS SEARCHSTRING (fetch (LAFITEMSG SUBJECT) of MSG)
					     1 NIL NIL NIL UPPERCASEARRAY))
			    (Body (FILEPOS SEARCHSTRING INSTREAM (fetch (LAFITEMSG START)
								    of MSG)
					   (fetch (LAFITEMSG END) of MSG)
					   NIL NIL UPPERCASEARRAY))
			    (SHOULDNT))
		    (COND
		      ((NOT ADDFLG)
			(UNSELECTALLMESSAGES MAILFOLDER)
			(SETQ ADDFLG T)))
		    (LA.SELECTRANGE MAILFOLDER MSG# MSG# T)
		    (LA.SHOW.SELECTION MAILFOLDER MSG (QUOTE REPLACE))
		    (COND
		      [(NOT #FOUND)
			(SETQ #FOUND 1)
			(COND
			  ((NOT ALLFLG)
			    (LAB.PROMPTPRINT MAILFOLDER "Found in message " MSG#)
			    (LAB.EXPOSEMESSAGE MAILFOLDER MSG)
			    (RETURN]
		      (T (add #FOUND 1]
          [COND
	    ((NULL #FOUND)
	      (LAB.PROMPTPRINT MAILFOLDER "%"" SEARCHSTRING "%" not found"))
	    (ALLFLG (SETQ CURRENT (AND (SETQ CURRENT (fetch (MAILFOLDER CURRENTDISPLAYEDMESSAGE)
							of MAILFOLDER))
				       (NOT (fetch (LAFITEMSG SELECTED?) of CURRENT))
				       (fetch (LAFITEMSG #) of CURRENT)))
		    (COND
		      ([SETQ CURRENT (SELECTQ DIRECTION
					      (FORWARD (LAB.FIND.SELECTED.MSG
							 MAILFOLDER
							 (ADD1 (OR CURRENT (ADD1 FROM#)))
							 (fetch (MAILFOLDER LASTSELECTEDMESSAGE)
							    of MAILFOLDER)))
					      (LAB.REV.FIND.SELECTED.MSG MAILFOLDER
									 (fetch (MAILFOLDER 
									     FIRSTSELECTEDMESSAGE)
									    of MAILFOLDER)
									 (SUB1 (OR CURRENT
										   (SUB1 FROM#]
			(LAB.PROMPTPRINT MAILFOLDER "Found in " #FOUND " messages")
			(LAB.EXPOSEMESSAGE MAILFOLDER (NTHMESSAGE MESSAGES CURRENT)))
		      (T (LAB.PROMPTPRINT MAILFOLDER "No related message found"]
          (SETQ \LAFITE.LAST.SEARCH
	    (create SEARCHSTATE
		    SEARCHSTRING ← SEARCHSTRING
		    SEARCHDIRECTION ← DIRECTION
		    SEARCHAREA ← AREA
		    SEARCHREPLYTO ← REPLYTO?])

(LAFITEEXTRABROWSERCOMMANDFN
  [LAMBDA (WINDOW MAILFOLDER)                                (* bvm: " 5-Mar-84 15:39")
    (PROG [(FN (MENU (.LAFITEMENU. LAFITEEXTRAMENU LAFITEEXTRAMENUITEMS]
          (COND
	    (FN (APPLY* FN MAILFOLDER])
)
(DECLARE: EVAL@COMPILE DONTCOPY 
[DECLARE: EVAL@COMPILE 

(RECORD SEARCHSTATE (SEARCHSTRING SEARCHDIRECTION SEARCHAREA SEARCHREPLYTO))
]

(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS LAFITEFINDAREAMENUITEMS LAFITEEXTRAMENUITEMS LAFITEFINDTYPEMENUITEMS 
	  LAFITEFINDTYPEMENU LAFITEFINDAREAMENU LAFITEEXTRAMENU LAFITEEXTRAMENUFLG 
	  \LAFITE.LAST.SEARCH)
)
)

(RPAQ? LAFITEFINDTYPEMENU NIL)

(RPAQ? LAFITEFINDAREAMENU NIL)

(RPAQ? LAFITEEXTRAMENU NIL)

(RPAQQ LAFITEFINDAREAMENUITEMS ((From (QUOTE From)
				      "Search From: field for string (or To: if from self)")
				(Subject (QUOTE Subject)
					 "Search Subject: field for string")
				(Body (QUOTE Body)
				      "Search message bodies for string")
				(Related (QUOTE Related)
					 "Search for a message with same Subject, modulo Re:")))

(RPAQQ LAFITEFINDTYPEMENUITEMS (("Find Next One" (QUOTE (FORWARD ONE))
						 "Search forward from selected message")
				("Find Next All" (QUOTE (FORWARD ALL))
						 "Search forward from selected message")
				("Find Previous One" (QUOTE (BACKWARD ONE))
						     "Search backward from selected message")
				("Find Previous All" (QUOTE (BACKWARD ALL))
						     "Search backward from selected message")))

(RPAQQ LAFITEEXTRAMENUITEMS ((Find (QUOTE \LAFITE.FIND)
				   "Search mail for something")
			     ["Find Related" (QUOTE \LAFITE.FIND.RELATED)
					     
					"Find all messages from here on in reply to this message"
					     (SUBITEMS ("Find Related Forward" (QUOTE 
									     \LAFITE.FIND.RELATED))
						       ("Find Related Backward" (QUOTE 
								    \LAFITE.FIND.RELATED.BACKWARD]
			     ("Find Again" (QUOTE \LAFITE.FIND.AGAIN)
					   "Repeat previous search")))

(RPAQQ LAFITEEXTRAMENUFLG T)

(RPAQQ \LAFITE.LAST.SEARCH NIL)
(DECLARE: DONTEVAL@LOAD DOCOPY 
(MOVD? (QUOTE OPENMAILFOLDER)
       (QUOTE \LAFITE.OPEN.FOLDER))
)
(PUTPROPS LAFITEFIND COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1128 8145 (\LAFITE.FIND 1138 . 2536) (\LAFITE.FIND.RELATED 2538 . 3192) (
\LAFITE.FIND.RELATED.BACKWARD 3194 . 3379) (\LAFITE.FIND.AGAIN 3381 . 3847) (\LAFITE.FIND.PROMPT 3849
 . 4348) (\LAFITE.DO.FIND 4350 . 7895) (LAFITEEXTRABROWSERCOMMANDFN 7897 . 8143)))))
STOP