I don't have access to the cvs tree, but here's an addition
for BBDB VM integration.  It lets VM automatically add
labels to messages based on the values of BBDB fields.  

I use it this way.  I have a mailing list for my fraternity
(stg) in the mail-alias field of my bbdb entries.  Typically
all mail I get from these people is about the fraternity.
There's nothing common in the mail that they to send me (no
headers, no tag in the subject line, etc).  The only common
thing is that all of their bbdb entries have a mail-alias
field with "stg" in it.  This code will automatically have
VM label the message with a label called "stg".  

It's completely customizable, you can use different fields,
you can set the values, you can make the values different
strings from the labels.  I think you should just be able to
drop it in to the bbdb vm support.

I've run with this code for a while on BBDB 2.00.06, VM 6.75
on Emacs 20.6 running on NT4 SP6.

Howard

;;; bbdb/vm-auto-add-label

(defgroup bbdb-mua-specific-vm nil
  "VM-specific BBDB customizations"
  :group 'bbdb-mua-specific)
(put 'bbdb-mua-specific-vm 'custom-loads '("bbdb-vm"))

(defcustom bbdb/vm-auto-add-label-list '("stg" "family" "aix" "team")
  "*List used by `bbdb/vm-auto-add-label' to automatically label messages.
Each element in the list is either a string or a list of two strings.
If a single string then it is used as both the field value to check for
and the label to apply to the message.  If a list of two strings, the first
is the field value to search for and the second is the label to apply."
  :group 'bbdb-mua-specific-vm
  :type 'list)

(defcustom bbdb/vm-auto-add-label-field bbdb-define-all-aliases-field
  "*Fields used by `bbdb/vm-auto-add-label' to automatically label messages.
Value is either a single symbol or a list of symbols of bbdb fields that
`bbdb/vm-auto-add-label' uses to check for labels to apply to messages.
Defaults to `bbdb-define-all-aliases-field' which is typically `mail-alias'."
  :group 'bbdb-mua-specific-vm
  :type '(choice symbol list))

(defun bbdb/vm-auto-add-label (record)
  "Automatically add labels to messages based on the mail-alias field.
Add this to `bbdb-notice-hook' and if using VM each message that bbdb
notices will be checked.  If the sender has a value in the
bbdb/vm-auto-add-label-field  in their BBDB record that
matches a value in `bbdb/vm-auto-add-label-list' then a VM
label will be added to the message. 

This works great when `bbdb-user-mail-names' is set.  As a result
mail that you send to people (and copy yourself on) is labeled as well."
  (let (field aliases sep)
    (and (eq major-mode 'vm-mode)
         (mapcar #'(lambda(x)
                     (and
                      (setq field (bbdb-record-getprop record x))
                      (setq sep (or (get x 'field-separator) ","))
                      (setq aliases (append aliases (bbdb-split field sep)))))
                 (cond ((listp bbdb/vm-auto-add-label-field)
                        bbdb/vm-auto-add-label-field)
                       ((symbolp bbdb/vm-auto-add-label-field)
                        (list bbdb/vm-auto-add-label-field))
                       (t (error "Bad value for bbdb/vm-auto-add-label-field"))))
         (vm-add-message-labels
          (mapconcat #'(lambda (l)
                         (cond ((stringp l)
                                (if (member l aliases)
                                    l))
                               ((and (consp l)
                                     (stringp (car l))
                                     (stringp (cdr l)))
                                (if (member (car l) aliases)
                                    (cdr l)))
                               (t
                                (error "Malformed bbdb/vm-auto-add-label-list"))))
                     bbdb/vm-auto-add-label-list
                     " ")
          1))))

(add-hook 'bbdb-notice-hook 'bbdb/vm-auto-add-label)



_______________________________________________
bbdb-info mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/mailman/listinfo/bbdb-info

Reply via email to