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

;;; Reason: Modified GET-NEW-MAIL to rebind *mail-buffer*.

;;;                           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 149149, M/S 2151             
;;;   AUSTIN, TEXAS 78714-9149                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Patch file for MAIL-READER version 6.9
;;; Written 06/22/90 14:58:38 by BERGER,
;;; while running on ARIES from band LODX
;;; With SYSTEM 6.41, VIRTUAL-MEMORY 6.3, EH 6.8, MAKE-SYSTEM 6.5, MICRONET 6.0, LOCAL-FILE 6.2,
;;;  BASIC-PATHNAME 6.5, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.8, NETWORK-NAMESPACE 6.1,
;;;  DISK-IO 6.4, DISK-LABEL 6.1, BASIC-FILE 6.13, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.2,
;;;  COMPILER 6.18, TV 6.31, DATALINK 6.0, CHAOSNET 6.8, GC 6.4, MEMORY-AUX 6.0, NVRAM 6.4,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.6, UCL 6.1, INPUT-EDITOR 6.1, METER 6.2, ZWEI 6.26,
;;;  DEBUG-TOOLS 6.5, NETWORK-SUPPORT 6.1, NETWORK-SERVICE 6.3, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.8, MAC-PRINTER-TYPES 6.2, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.6, MAIL-READER 6.8, TELNET 6.1, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.7, PROFILE 6.3, VISIDOC 6.7, TI-CLOS 6.53, CLEH 6.5, IP 3.65,
;;;  Experimental BUG 11.19, Experimental CLX 7.0, Experimental CLUE 7.5, X11M 6.32,
;;;   microcode 483, Band Name: Rel 6.1 *b +SLE 6/18

#!C
; From file COMMAND.LISP#> MAIL-READER; Hotel:
#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*   ; DAB 10-04-89
		       (:FIRST-UNSEEN        
			(select-next-message-search
			  :unseen
			  (or *mail-buffer*
			      (multiple-value-setq (*mail-buffer* *msg*)  ; DAB 06-22-90
				(sync-mail-buffers nil)))	; DAB 01-25-90 *mail-buffer* may not be set up yet.
			  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)))))
))
