Hi Waider,

since we are talking feature proposals. This was an old proposal of mine
years ago, but never made it into the distribution and I'm now sure
there are better ways to to it.... But nevertheless, if someone could do
it right and add it to BBDB, that'll be great.

I had to do some nasty things to achieve the following behaviour:

- I don't want BBDB entries for mail from mailing lists. I use
  bbdb-ignore-some-messages-alist for that.

- If I do get an email not caught by that list I want to be _asked_
  whether to create an entry or not. Additionally, I want to be asked
  whether to add a mail alias.

The last bit was easy: add a function to bbdb-create-hook. Although the
one presented below might not be the best one.

But for the previously described functionality I had to re-define
bbdb/vm-update-record such that it calls bbdb/update-record or
bbdb/vm-update-record with two arguments such that prompt-to-create (the
second arg) is set to t. And then change those functions to use two
instead of one argument in the call to bbdb-annotate-message-sender. 
I'll append the code at the end. What's nasty about this is that I have
to remove/add this functions to the right hooks (it took me a while to
figure out the right ones). 

What I would really like is to make this behaviour customizable via a
variable? 

What do other people think? Is this a feature anybody else would use?

-- frank

in .vm:

;; BBDB & VM stuff
(bbdb-insinuate-vm)
;; change vm's behaviour such that my own hooks get called
;; defs see fm-packages.el
(fm-vm-hook)

in fm-packages.el:

;; code is open to discussion:
;; I prefixed my own functions with my initials to avoid confusion
;; what's mine and what's somebody else's code.

(defun fm-bbdb/vm-update-record (&optional offer-to-create prompt-to-create)
  "Returns the record corresponding to the current VM message, 
creating or modifying it as necessary.  A record will be created if 
bbdb/mail-auto-create-p is non-nil, or if OFFER-TO-CREATE is true and
if PROMPT-TO-CREATE is true the user has to confirm the creation. 
Original def, see bbdb-vm.el."
  (save-excursion
    (vm-select-folder-buffer)
    (vm-check-for-killed-summary)
    (vm-error-if-folder-empty)
    (if bbdb-use-pop-up
        (bbdb/vm-pop-up-bbdb-buffer offer-to-create)
      (let ((msg (car vm-message-pointer))
            (inhibit-local-variables nil) ; vm binds this to t...
            (enable-local-variables t)    ; ...or vm bind this to nil.
            (inhibit-quit nil))  ; vm damn well better not bind this to t!
        ;; this doesn't optimize the case of moving thru a folder where
        ;; few messages have associated records.
        (or (bbdb-message-cache-lookup msg nil) ; nil = current-buffer
            (and msg
                 (let ((from (bbdb/vm-get-from msg)))
                   (if from
                       (bbdb-encache-message
                        msg
                        (bbdb-annotate-message-sender
                         from t
                         (or (bbdb-invoke-hook-for-value
                              bbdb/mail-auto-create-p)
                             offer-to-create)
                         prompt-to-create))))))))))

;; if we noticed a new entry, ask for a mail-alias
(add-hook 'bbdb-create-hook 'fm-bbdb-insert-mail-alias)
(defvar fm-alias nil)
;; ask for mail-alias addition
(defun fm-bbdb-insert-mail-alias (record)
  "Query whether to insert a mail alias."
  (interactive)
  (if (bbdb-y-or-n-p "Add mail-alias? ")
      (fm-bbdb/insert-mail-alias record)))
;; ask for mail-alias value
(defun fm-bbdb/insert-mail-alias (record)
  "Query for a mail alias and add it to record."
  (interactive)
  (setq fm-alias (bbdb-read-string "Mail-alias: "))
  (bbdb-record-putprop record 'mail-alias fm-alias))

;; this is supposed to change the behaviour of BBDB such that it adds a
;; new entry only if it is not on my exclusion list and if I confirm it.
;; we have to remove the original function and add ours; the def is in
;; fm-packages.el
(defun fm-update-record (&optional offer-to-create)
  "Call  fm-bbdb/vm-update-record with prompt-to-create set to t"
  (fm-bbdb/vm-update-record offer-to-create t))
(defun fm-vm-hook ()
   "Remove the standard bbdb/vm-update-record from vm/select-message-hook and;;  add 
my own such that PROMPT-TO-CREATE is true."
   (remove-hook 'vm-select-message-hook 'bbdb/vm-update-record)
   (add-hook 'vm-select-message-hook 'fm-update-record))

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

Reply via email to