[comp.emacs] A Sun Gnu rmail sentinel.

dzzr@beta.UUCP (Douglas J Roberts) (02/03/88)

A while back I snarfed something called pop-mail.el from this group. It
turned out to be fairly useful: from within an EMACS shell, a
background process would check once a minute to see if new mail had
arrived. If so, rmail would be invoked and a new rmail buffer would
pop up. I use pop-mail.el when I remote login to my office Sun from
home.

At the office, however, I felt it would be more useful to have a mail
tool that behaved more like Sun's mailtool: ie. when new mail arrived,
have the console beep and pop up an icon indicating new mail. 

That's what sun-mail.el does: if new mail arrives for the logged-on
user (Suns only) , a new iconic cshell process is started. I use Sun's
"mail has arrived" icon, the one with a mail box with a letter
sticking out.  After you get your mail with rmail, the iconic shell
process is killed off.

This code runs on Sun3/50s, 3/75s 3/110s, and 3/260s. I make no claim
for any other hardware.

Enjoy!
--Doug




----------------------------------------------------------------------------
;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
;; Read the GNU COPYING file for the full details.
;; 9/17/87 wolfgang@mgm.mit.edu (was pop-mail.el)
;; 12/8/87 dzzr@lanl.gov (now sun-mail.el)

(defvar sun-mail t "*If t pop up a mail icon when new mail arrives.
	Files listed in rmail-primary-inbox-list are watched")

(defvar number-beeps 2)
(defvar beep-counter 0)
(defvar mail-process nil)
(defvar checked 'no)
;;
;; NOTE: YOU MUST CHANGE THIS PATH TO POINT TO YOUR OWN ICON!!
;;
(defvar icon-path "/u/a5/roberts/icons/mail.icon")

(defun display-time-filter (proc string)
  "A filter that replaces the 'display-time-filter' filter.
       This filter pops up a mail icon whenever new mail arrives."
  ;; Desired data can't need more than the last 30 chars,
  ;; so save time by flushing the rest.
  ;; This way, if we have many different times all collected at once,
  ;; we can discard all but the last few very fast.
  (if (> (length string) 30)
      (setq string (substring string -30)))
  ;; Now discard all but the very last one.
  (while (and (> (length string) 4)
	      (string-match "[0-9]+:[0-9][0-9].." string 4))
    (setq string (substring string (match-beginning 0))))
  (if (string-match "[^0-9][0-9]+:" string)
      (setq string (substring string 0 (1+ (match-beginning 0)))))
  ;; Append the date if desired.
  (if display-time-day-and-date
      (setq string (concat (substring (current-time-string) 0 11) string)))
  ;; Install the new time for display.
  (setq display-time-string string)
  ;; Force redisplay of all buffers' mode lines to be considered.
  (save-excursion (set-buffer (other-buffer)))
  (set-buffer-modified-p (buffer-modified-p))
  ;; Do redisplay right now, if no input pending.
  (sit-for 0)
  
  (if sun-mail
      (let (
	    (list rmail-primary-inbox-list)
	    file
	    )
	(while list
	  (progn ;; #1 The case where there is mail
	    (while (and 
		     (not (eq checked 'yes))
			  (check-file list))
	      (setq checked 'yes)
	      (if (or (not mail-process)
		      (not (eq (process-status mail-process) 'run)))
		  (progn ;; Fire up an icon if the background process is not already running
		    (message "New mail has arrived...")
		    (setq mail-process
			  (start-process "new" 
					 nil
					 "shelltool"
					 "-WL" ""
					 "-Wl" "If you see this you have new mail..."
					 "-Wp" "500"  "67" 
					 "-Ws" "650" "824" 
					 "-WP" "788" "0" 
					 "-Wi" "-WI" 
					 icon-path
					 ))
		    )
		);; end mail process if
	      (while (< beep-counter number-beeps)
		(ding)
		(sit-for 2)
		(setq beep-counter (+ beep-counter 1))
		)
	      (setq beep-counter 0)
	      );; end of while check-file
	    ) ;; end of progn #1
	  (setq list (cdr list))
	  );; end of while list
	
	(progn ;; #2 The case where there was no mail
;;;
;;; KILL OFF THE MAIL ICON PROCESS IF NO MORE MAIL
;;;
	  (cond (
		 (and
		   (not (check-file rmail-primary-inbox-list))
		   (not (check-file (cdr rmail-primary-inbox-list)))
		   mail-process
		   (eq (process-status mail-process) 'run))
		 (setq checked 'no)
		 (kill-process mail-process)
		 ))
	  );; end progn #2
	);; end of let
    ))

;;;
;;; CHECKS TO SEE IF A FILE IS EMPTY
;;;
(defun check-file (file-list)
  "This method checks to see if the file has contents.
       Returns t if the file is not empty."
  (if (and (not (null file-list))
	   (file-exists-p
	     (setq file (expand-file-name
			  (substitute-in-file-name (car file-list)))))
	   (/= 0 (nth 7 (file-attributes file)))) ;size != 0
      t
    nil))


===============================================================
Douglas Roberts
Los Alamos National Laboratory
(505)667-4569
dzzr@lanl.gov
===============================================================

-- 
---------------------------------------------------------------
			Doug Roberts
			dzzr@lanl.gov
---------------------------------------------------------------