;;; -*- Mode: Common-Lisp; Package: Zwei; Base: 10.; Patch-File: T -*-

;;; Reason: Added a defvar *cursor-action-after-get-new-mail* that will determine the cursor position after getting new mail. Valid options are listed in the documentation string. [9893,9874]

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Patch file for MAIL-READER version 6.3
;;; Written 10/04/89 07:17:52 by BERGER,
;;; while running on ARIES from band LODX
;;; With SYSTEM 6.17, VIRTUAL-MEMORY 6.2, EH 6.5, MAKE-SYSTEM 6.1, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.1, NETWORK-SUPPORT-COLD 6.0, BASIC-NAMESPACE 6.2, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.3, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.12, TV 6.15, DATALINK 6.0, CHAOSNET 6.1, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.1,
;;;  SYSLOG 6.1, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.5,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.1,
;;;  IMAGEN 6.0, SUGGESTIONS 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.2, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.0, PROFILE 6.1, VISIDOC 6.4, TI-CLOS 6.24, CLEH 6.5, IP 3.50,
;;;  Experimental CLX 6.3, CLUE 6.17, X11M 6.14, Experimental BUG 11.15, VISIDOC-SERVER 6.1,
;;;   microcode 429, Band Name: Rel 6.0 + SLE 8/30

#!C
; From file OPTIONS.LISP#> MAIL-READER; SYS:
#10R ZWEI#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "ZWEI"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: MAIL-READER; OPTIONS.#"


(defvar *Cursor-action-after-get-new-mail* :FIRST-UNSEEN  ; DAB 10-04-89
  "Determines where the cursor will be positioned after getting new mail.
   A value of :first-unseen will position the cursor to the first unseen message.
   A value of :first-new-unseen will position the cursor to the first new unseen message.
   A value of :Current-position will not reposition the cursor.")
))

#!C
; From file COMMAND.LISP#> MAIL-READER; SYS:
#10R ZWEI#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "ZWEI"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: MAIL-READER; COMMAND.#"


(defun GET-NEW-MAIL (buffer &optional quietly inbox-path force-read-old-inboxes)
  (declare (special  *Cursor-action-after-get-new-mail*))
  (when (stringp inbox-path)
    (setq inbox-path (fs:merge-pathname-defaults inbox-path)))
  
  (let ((append-p (append-new-mail-p buffer))
	(old-last (last-message buffer))
	new-msgs
	(current-message (Current-MESSAGE buffer))) ; DAB 07-19-89

    (setq new-msgs
	  (if inbox-path
	      (read-inbox inbox-path buffer)
	    (read-inboxes buffer force-read-old-inboxes)))
    
    (cond ((> new-msgs 0)
	   (unless quietly
	     (format *query-io* "~&~D new message~:P read." new-msgs))
	   ;; Select first new message
	   (cond ((or (not append-p) (null old-last))
		  ;; Prepended (or buffer was empty); go to first message
		  (select-message 0 buffer))
		 ((not (null old-last))
		  ;; Appended; go to the message following the "old" last message
		  (select-message old-last buffer)
		  (select-next-message buffer)))

	   (let ((summary-buffer (mail-summary-of buffer)))
	     (when summary-buffer
	       (update-summary summary-buffer)         ;update the summary

               ;; ADDED  following two forms  -dkm
	       ;; make the UNSEEN filter the current sequence if in filtered mode.  -dkm
	       (when (filter-summary-p summary-buffer)
		 (let ((unseen-filter (dolist (filter (send summary-buffer :filter-list))
					(if (string-equal (send filter :name) "UNSEEN")
					    (return filter)))))
		   (when unseen-filter
		     ;; Move point to the UNSEEN filter line and sync the buffers -dkm
		     (select *Cursor-action-after-get-new-mail*    ; DAB 10-04-89
		       ((:FIRST-UNSEEN :FIRST-NEW-UNSEEN)
			(move-bp (point) (get unseen-filter :filter-summary-line) 0))
		       (:Current-position ())
		       (otherwise ()))
		     (multiple-value-setq (*mail-buffer* *msg*) (sync-mail-buffers nil)))))

	       ;; move to the first unseen message of the current mail-buffer sequence  -dkm
	       (select *Cursor-action-after-get-new-mail*  
		       (:FIRST-UNSEEN        
			(select-next-message-search :unseen *mail-buffer* 1 #'message-attribute-p 0))
		       (:FIRST-NEW-UNSEEN ())
		       (:Current-position (MAKE-MESSAGE-CURRENT current-message Buffer) )
		       (otherwise ()))
	       )))
	  (t 
	   (unless quietly
	     (format *query-io* "~&No new mail."))
	   (values dis-none dis-none)))))
))

#!C
; From file VARIABLES.LISP#> PROFILE; SYS:
#10R PROFILE#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "PROFILE"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: PROFILE; VARIABLES.#"

(WHEN (si:find-package "MAIL") ;; may 01/25/89
  (DEFINE-PROFILE-VARIABLE ZWEI::*Cursor-action-after-get-new-mail* (:MAIL)
    :CVV-TYPE (:CHOOSE '(:FIRST-UNSEEN :FIRST-NEW-UNSEEN :CURRENT-POSITION))
    :GET-VALUE (ZWEI::DEFAULT-MAIL-WINDOW-CONFIGURATION)))
))
