home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / pop-mail.el < prev    next >
Encoding:
Text File  |  1991-06-14  |  2.8 KB  |  82 lines

  1. ; Path: dg-rtp!rock.concert.net!mcnc!stanford.edu!bu.edu!dimacs.rutgers.edu!mips!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!unido!infbs!neitzel@infbs.uucp
  2. ; From: neitzel@infbs.uucp (Martin Neitzel)
  3. ; Newsgroups: gnu.emacs.sources
  4. ; Subject: pop-mail.el for 18.57
  5. ; Date: 6 Jun 91 16:57:22 GMT
  6. ; I just converted my version of good ol' pop-mail to work with 18.57.
  7. ; (For those who wanna know: pop-mail sits on top of display-time and will
  8. ; automatically pop up an RMAIL buffer and "g"et newly arriving mail.)
  9. ; It is basically a drop in replacement for one function in time.el.  You
  10. ; could replace the function in standard time.el or overload it from a new
  11. ; file.  For the latter, put something like this into your .emacs:
  12. ; (display-time)
  13. ; (load "pop-mail") ;; to get the extented functionality.
  14. ; Thanks go to wolfgang@mgm.mit.edu, who came up with the code originally.
  15. ;                                 Martin
  16.  
  17. ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  18. ;; Read the GNU COPYING file for the full details.
  19. ;; 9/17/87 wolfgang@mgm.mit.edu
  20.  
  21. (defvar pop-mail t "*If t display new mail in a pop up mail buffer.
  22.     files listed in rmail-primary-inbox-list are watched")
  23.  
  24. (defun display-time-filter (proc string)
  25.   (let ((time (current-time-string))
  26.     (load (condition-case ()
  27.           (if (zerop (car (load-average))) ""
  28.             (format "%03d" (car (load-average))))
  29.         (error "")))
  30.     (mail-spool-file (or display-time-mail-file
  31.                  (getenv "MAIL")
  32.                  (concat rmail-spool-directory
  33.                      (or (getenv "LOGNAME")
  34.                      (getenv "USER")
  35.                      (user-login-name)))))
  36.     hour pm)
  37.     (setq hour (read (substring time 11 13)))
  38.     (setq pm (>= hour 12))
  39.     (if (> hour 12)
  40.     (setq hour (- hour 12))
  41.       (if (= hour 0)
  42.       (setq hour 12)))
  43.     (setq display-time-string
  44.       (concat (format "%d" hour) (substring time 13 16)
  45.           (if pm "pm " "am ")
  46.           (if (string= load "")
  47.               ""
  48.             (concat (substring load 0 -2) "." (substring load -2)))
  49.           (if (and (file-exists-p mail-spool-file)
  50.                ;; file not empty?
  51.                (> (nth 7 (file-attributes mail-spool-file)) 0))
  52.               " Mail"
  53.             "")))
  54.     ;; Append the date if desired.
  55.     (if display-time-day-and-date
  56.     (setq display-time-string
  57.           (concat (substring time 0 11) display-time-string))))
  58.   ;; Force redisplay of all buffers' mode lines to be considered.
  59.   (save-excursion (set-buffer (other-buffer)))
  60.   (set-buffer-modified-p (buffer-modified-p))
  61.   ;; Do redisplay right now, if no input pending.
  62.   (sit-for 0)
  63.   (if pop-mail
  64.       (let ((list (or rmail-primary-inbox-list
  65.               '("/usr/spool/mail/$USER")))
  66.         file)
  67.     (while list
  68.       (if (and (file-exists-p
  69.             (setq file (expand-file-name
  70.                 (substitute-in-file-name (car list)))))
  71.            (/= 0 (nth 7 (file-attributes file)))) ;size != 0
  72.           (progn
  73.         (save-excursion (rmail))
  74.         (display-buffer (get-buffer "RMAIL"))
  75.         (setq list nil))    ; once only
  76.         (setq list (cdr list)))))))
  77.