grunwald@m.cs.uiuc.edu (10/04/88)
Here's a version of popmail.el that works with 18.52. Rmail changed slightly
in that version. Also, this works even if you don't call your rmail buffer
``RMAIL''.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; File: popmail.el ;;
;; Author: Wolfgang Rupprecht ;;
;; Created: Thu Sep 17 14:55:45 EDT 1987 ;;
;; Contents: pop up a mail buffer whenever new mail arrives ;;
;; ;;
;; Copyright (c) 1987 Wolfgang Rupprecht. ;;
;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. ;;
;; ;;
;; $Log$ ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GNU Emacs and this file popmail.el, are distributed in the hope
;; that they will be useful, but WITHOUT ANY WARRANTY. No author or
;; distributor accepts responsibility to anyone for the consequences of
;; using them or for whether they serve any particular purpose or work at
;; all, unless he says so in writing. Refer to the GNU Emacs General
;; Public License for full details.
;; Everyone is granted permission to copy, modify and redistribute GNU
;; Emacs and popmail.el, but only under the conditions described in the
;; GNU Emacs General Public License. A copy of this license is supposed
;; to have been given to you along with GNU Emacs so you can know your
;; rights and responsibilities. It should be in a file named COPYING.
;; Among other things, the copyright notice and this notice must be
;; preserved on all copies.
;; Instructions:
;; Insert the following (minus the leading ';; ') into your .emacs file:
;;
;; (let ((process-connection-type nil)) ; try not to hog a pty for this.
;; (display-time))
;;
;; ;; don't let two pop-mails be active at once.
;; (if (file-locked-p (expand-file-name "~/RMAIL"))
;; nil
;; (load-library "popmail") ; patches time filter
;; (setq pop-mail t))
(provide 'pop-mail)
(defvar pop-mail nil "*If t display new mail in a pop up mail buffer.
files listed in rmail-primary-inbox-list are watched")
(defvar pop-mail-ding t "*If non-nil ding bell, when new mail pops up.")
(defun display-time-filter (proc string)
"A filter that replaces the 'display-time-filter' filter.
This filter pops up a mail window 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 pop-mail
(let ((mail-inbox-list
(list
rmail-primary-inbox-list
"~/mbox"
(concat rmail-spool-directory
(if (getenv "LOGNAME")
"$LOGNAME" "$USER"))))
file)
(while mail-inbox-list
(if
(and (stringp (car mail-inbox-list))
(file-exists-p
(setq file (expand-file-name
(substitute-in-file-name (car mail-inbox-list)))))
(/= 0 (nth 7 (file-attributes file)))) ;size != 0
(progn
(save-excursion (rmail))
(find-file rmail-file-name)
(setq mail-inbox-list nil) ; once only
(if pop-mail-ding
(ding)))
(setq mail-inbox-list (cdr mail-inbox-list)))))))