Hi,

A while back Roland posted advices to enable a mail-folder
property. This property was used as the default folder name while
saving messages in vm.

I have improved that in two ways:
1. It is now a list of folder names, the first one on this list
   becomes the default folder name and the other names are pushed to
   the file-name history so that one can scroll through them using the
   history mechanisms. This is useful if you are saving mail from a
   person to more than one folder.
2. This property is created and updated automatically when a message
   is saved to a folder so that the list is in MRU (most recently
   used) order. This is useful, because I am lazy to  set the
   mail-folder property by hand.

I renamed the property to mail-folders so that it does not break with
the existing mail-folder property.

Enjoy. Bug fixes are welcome.

Cengiz

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

(defvar bbdb/vm-mail-folders-file-name-history nil "")

(defadvice vm-save-message (around bbdb/vm-mail-folders activate compile)
  "cache"
  (let* ((folder-name "")
         (record (bbdb/vm-update-record nil))
         (mail-folders (and record (bbdb-record-getprop record 'mail-folders)))
         (folder-list (and mail-folders (car (read-from-string mail-folders)))))
    ad-do-it
    (setq folder-name (ad-get-arg 0))
    (setq folder-name (expand-file-name folder-name vm-folder-directory))
    (setq file-name-history 
          (append (list folder-name) bbdb/vm-mail-folders-file-name-history))
    (and record
         (progn
           (setq folder-list (delete folder-name folder-list))
           (setq folder-list (append (list folder-name) folder-list))
           (bbdb-record-putprop record 'mail-folders 
                                (prin1-to-string folder-list))
           )
         )
    )
  )

(defadvice vm-auto-select-folder (around bbdb/vm-mail-folders activate compile)
  "If the message sender's BBDB entry has a `mail-folder' property, use that."
  (let* ((record (bbdb/vm-update-record nil))
         (mail-folders (and record (bbdb-record-getprop record 'mail-folders)))
         (folder-list (and mail-folders (car (read-from-string mail-folders))))
         (folder-name (and folder-list (car folder-list))))
    (setq bbdb/vm-mail-folders-file-name-history file-name-history)
    (and (cdr folder-list)
         (setq file-name-history 
               (append (cdr folder-list) file-name-history)))
    (if folder-name 
        (setq ad-return-value (file-name-nondirectory folder-name))
      ad-do-it)
    )
  )


Reply via email to