procmail
[Top] [All Lists]

Re: How could i get some indication of a new message ?

1997-05-19 16:42:00
Excerpts from mail: (19-May-97) Re: How could i get some indication of a new 
message ? by era eriksson
Thanks, but what I had in mind was something that could tell me how many
messages there are in each folder, i.e. something like

   Mail:1  Procmail:1  Spam-Law:322

... perhaps only when I ask for it (so as not to clutter up the mode
line).

Here's an elisp package that does something like what you're asking for. It
was posted to the gnu.emacs.vm.info newsgroup back in 1995. I saved it
because it sounded pretty interesting, though I never got around to trying it
out (so don't e-mail me any questions about it). You might want to e-mail the
author to see if he ever came out with a newer version.

To be honest though, I suggest a good X Windows client like xbuffy instead of
using Emacs for this. Grab
<ftp://tigger.itc.virginia.edu/pub/src/xbuffy3.3.tar.gz> if you are
interested. It does the same thing, but it's more customizable and overall
niftier, IMHO. By utilizing xbuffy + gnudoit, you can achieve the same
functionality as this package.

Enjoy,
Ed

------- Start of forwarded message -------
From: cengiz(_at_)cat(_dot_)isi(_dot_)edu (Cengiz Alaetinoglu)
Newsgroups: gnu.emacs.vm.info
Subject: Re: automatically visiting folders in sequence
Date: 27 Jun 1995 17:55:59 GMT

This add-on package creates a frame with the following content for me:
   18: Inbox       31: bbdb        233: ietf            23: tuba      
   11: trknws                      154: bgp              0: sip       
    0: siir-l      54: nanog         0: idrp             0: nimrod-wg 
   29: sdag       294: rps           1: ipng             0: flows     
 1417: ra-isi       1: com-priv      0: big-internet     9: idpr-wg   

These are my most recently visited mail folders. The ones which have new
mail spooled for them are in bold face (kind of like biff behaviour). You
can click mouse-2 on any one of them to visit that folder.

This is unfinished work. It needs a lot more customization and
documentation, but it works for me and I do not have the time to do the work.

- -- 
Cengiz Alaettinoglu       Information Sciences Institute
(310) 822-1511            University of Southern California
http://www.isi.edu/div7/people/cengiz.home


;; vm--folders.el: 
;; version: 0.9  Dec 19 '94
;;
;; Copyright (C) 1994 1994 Cengiz Alaettinoglu <ca(_at_)cs(_dot_)umd(_dot_)edu>
;;
;; LCD Archive Entry:
;; vm--folders.el|Cengiz Alaettinoglu|cengiz(_at_)isi(_dot_)edu|
;; folders.|
;; 19-Dec-1994|1.3|~/misc/vm--folders.el|
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You didn't receive a copy of the GNU General Public License along
;; with this program; so, write to the Free Software Foundation, Inc.,
;; 675 Mass Ave, Cambridge, MA 02139, USA.
;;
;;----------------------------------------------------------------------------
;;
;; DESCRIPTION:
;;   Displays a buffer with vm folder names
;;     using highlight face if that buffer contains new messages
;;     with number of messages in it
;;   One can middle-click or press v on a folder name to visit it.
;;
;; INSTALLATION:
;;
;;   Add this to your .emacs:
;;
;;     (and window-system (require 'vm--folders))
;;
;;   In your vm-folder-directory, create and edit a file called Folders
;;   with the folder names in it. Obey the following regular expression:
;;        \( +[0-9]+: +<folder-name> +\)
;;   Eg.
;;         0: Inbox     0: Workbox     0: Foo
;;         0: Bar       0: Zoo
;;
;;   Do not worry about the initial message counts. 
;;   They will be updated as you visit and save folders.
;;
;; CUSTOMIZATION:
;;
;;
;; CREDITS:
;; 
;;----------------------------------------------------------------------------

(require 'vm)
(provide 'vm--folders)


(defvar vm--folders-file (concat vm-folder-directory "Folders")
  "File to store (message counts, folder) pairs in.")

(defvar vm--folders-frame-alist
  '((name . "VM Folders")     
    (height . 6) (width . 80) 
    (top . 600) (left . 1160)
    (minibuffer . nil)
    (menu-bar-lines . 0))
  "*Alist of frame parameters used for creating the VM Folders frame.")

(defvar vm--folders-mode-hook nil 
  "Executed after vm--folders-mode is entered.")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar vm--folders-frame-id nil
  "*VM Folders frame id.")

(defvar vm--folders-buffer nil
  "Buffer to display folder names.")

(defvar vm--folder-dependency-alist nil
  "Which folders depend on which files.")

(defvar vm--folders-timer nil
  "timer.")

(defun vm--folders-update-buffer ()
  (if vm--folders-buffer
      (save-excursion
        (set-buffer vm--folders-buffer)   
;       (setq buffer-read-only nil)
        (let ((folder-dependency-alist vm--folder-dependency-alist)
              (count 0)
              (first nil)
              (file1 nil)
              (lpoint nil)
              (new-mail nil))
          (while folder-dependency-alist
            (setq first (car folder-dependency-alist))
            (setq folder-dependency-alist (cdr folder-dependency-alist))
            (setq file1 (car first))
            (setq first (cdr first))
            (setq new-mail nil)
            (while (and (not new-mail) first)
              (setq new-mail 
                    (let ((fname (expand-file-name (car first) 
                                                    vm-folder-directory)))
                      (and (file-exists-p fname)
                           (not (= (nth 7 (file-attributes fname)) 0)))))
              (setq first (cdr first)))

            (vm--folders-update-folder-face file1 
                                               (if new-mail 'bold 'default))

            ))
;       (setq buffer-read-only t)
        (goto-char (point-min))
        )
    (cancel-timer vm--folders-timer) ; only if not vm--folders-buffer
    )
  )

(defun vm--folders-update-folder-face (folder face)
  (goto-char (point-min))
  (if (search-forward folder nil t)
      (progn
        (put-text-property (match-beginning 0) (match-end 0) 'face face)
        (put-text-property (match-beginning 0) (match-end 0) 
                           'mouse-face 'highlight)
        )
    )
)

(defun vm--folders-start ()
  (interactive)
  (or vm--folders-buffer
      (progn 
        (find-file vm--folders-file)
        (setq vm--folders-buffer (current-buffer))))


  (setq vm--folder-dependency-alist
      (mapcar '(lambda (x)
                 (list (car x) (car (cdr x))))
              vm-spool-files))

  (let ((new-pair nil)
        (last-pair (car vm--folder-dependency-alist))
        (folder-dependency-alist nil)
        (rest (cdr vm--folder-dependency-alist)))
    (while rest
      (setq new-pair (car rest))
      (setq rest (cdr rest))

      (if (string= (car last-pair) (car new-pair))
          (setq last-pair (append last-pair (cdr new-pair)))
        (progn
          (setq folder-dependency-alist 
                (append folder-dependency-alist (list last-pair)))
          (setq last-pair new-pair))))

    (setq folder-dependency-alist (append folder-dependency-alist (list 
last-pair)))
    (setq vm--folder-dependency-alist folder-dependency-alist)
    )
  
  (let ((old-frame (selected-frame)))
        (select-frame 
         (if (and vm--folders-frame-id (frame-live-p vm--folders-frame-id))
             vm--folders-frame-id
           (setq vm--folders-frame-id (new-frame vm--folders-frame-alist))))

        (switch-to-buffer vm--folders-buffer)
        (vm--folders-mode)
        (setq vm--folders-timer 
              (run-at-time 60 60 'vm--folders-update-buffer))
        (vm--folders-update-buffer)
        (select-frame old-frame))
  )
   
(defun vm--folders-mode ()
   "VM Folders mode."
   (interactive)
   (setq major-mode 'vm--folders-mode)
   (setq mode-name "VM Folders Mode")
   (use-local-map vm--folders-mode-map)
;   (setq buffer-read-only t)
   (set-syntax-table text-mode-syntax-table)
   (setq default-directory vm-folder-directory)
   (run-hooks 'vm--folders-mode-hook)
   )

(defvar vm--folders-mode-map nil
  "keymap.")

(if vm--folders-mode-map
    nil
  (setq vm--folders-mode-map (make-sparse-keymap))
  (define-key vm--folders-mode-map "v" 'vm--folders-visit-folder)
  (define-key vm--folders-mode-map "g" 'vm--folders-start)
  (define-key vm--folders-mode-map [mouse-2] 'vm--folders-visit-folder-at-mouse)
)

(defun vm--folders-visit-folder ()
  (interactive)
  (let ((folder-name
    (save-excursion
      (if (and (re-search-backward (concat " *[0-9]+:") nil t)
               (re-search-forward  (concat " *[0-9]+: *\\([^ \t\n]*\\)") nil t))
          (progn 
            (buffer-substring (match-beginning 1) (match-end 1)))))))
    (and folder-name (vm-visit-folder folder-name))))

(defun vm--folders-visit-folder-at-mouse (event)
  (interactive "@e")
  (goto-char (posn-point (event-start event)))
  (vm--folders-visit-folder))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Update message count ;;;;;;;;;;;;;;;;;;;;

(defadvice vm-save-folder (after vm--cache-message-count-hook act)
  (vm--cache-message-count (buffer-file-name) (length vm-message-list))
  )

(defadvice vm-save-message (after vm--cache-message-count-hook act)
  (vm--cache-message-count-inc (ad-get-arg 0) (or (ad-get-arg 1) 1))
  )

(defun vm--cache-message-count (folder count)
  (save-excursion
    (set-buffer vm--folders-buffer)
    (setq folder (file-name-nondirectory folder))
    (goto-char (point-min))
    (if (re-search-forward (concat "\\( *[0-9]+\\): *" folder) nil t)
        (vm--folders-update-count count (match-beginning 1) (match-end 1))
      )
    )
  )

(defun vm--cache-message-count-inc (folder inc)
  (save-excursion
    (set-buffer vm--folders-buffer)
    (setq folder (file-name-nondirectory folder))
    (goto-char (point-min))
    (if (re-search-forward (concat "\\( *[0-9]+\\): *" folder) nil t)
        (let ((count (string-to-int 
                      (buffer-substring (match-beginning 1) 
                                        (match-end 1)))))
          (setq count (+ count (abs inc)))
          (vm--folders-update-count count (match-beginning 1) (match-end 1))
          )
      )
    )
  )

(defun vm--folders-update-count (count start end)
  (goto-char start)
  (delete-region start end)
  (insert (format (concat "%" 
                          (int-to-string (- end start))
                          "d")
                  count))
  )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Startup ;;;;;;;;;;;;;;;;;;;;

(defadvice save-some-buffers
  (before save-some-buffers-save-vm--folders act compile)
  "Save folders buffer..."
  (save-excursion
    (set-buffer vm--folders-buffer)
    (save-buffer))
)

(vm--folders-start)
------- End of forwarded message -------