1 ;;; mu-bbdb.el --- `attribution' function for mu-cite with BBDB.
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Maintainer: Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, citation, bbdb
9 ;; This file is part of MU (Message Utilities).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 ;; 1. bytecompile this file and copy it to the apropriate directory.
30 ;; 2. put the following lines to your ~/.emacs:
31 ;; (add-hook 'mu-cite-load-hook
40 (eval-when-compile (require 'cl))
42 ;; Pickup `module-installed-p'.
46 (when (module-installed-p 'bbdb)
50 ;;; @ obsolete functions
53 ;; This part will be abolished in the future.
56 (defconst mu-bbdb-obsolete-function-alist
57 '((mu-cite/get-bbdb-attr mu-bbdb-get-attr)
58 (mu-cite/get-bbdb-prefix-method mu-bbdb-get-prefix-method)
59 (mu-cite/get-bbdb-prefix-register-method
60 mu-bbdb-get-prefix-register-method)
61 (mu-cite/get-bbdb-prefix-register-verbose-method
62 mu-bbdb-get-prefix-register-verbose-method)
63 (mu-cite/set-bbdb-attr mu-bbdb-set-attr)))
66 (function (lambda (elem)
67 (apply (function define-obsolete-function-alias) elem)))
68 mu-bbdb-obsolete-function-alist)
76 "`attribution' function for mu-cite with BBDB."
81 (defcustom mu-bbdb-load-hook nil
82 "List of functions called after mu-bbdb is loaded."
87 ;;; @@ prefix and registration using BBDB
90 (defun mu-bbdb-get-prefix-method ()
91 (or (mu-bbdb-get-attr (mu-cite-get-value 'address))
94 (defun mu-bbdb-get-attr (addr)
95 "Extract attribute information from BBDB."
96 (let ((record (bbdb-search-simple nil addr)))
98 (bbdb-record-getprop record 'attribution))))
100 (defun mu-bbdb-set-attr (attr addr)
101 "Add attribute information to BBDB."
102 (let* ((bbdb-notice-hook nil)
103 (record (bbdb-annotate-message-sender
105 (bbdb-invoke-hook-for-value
106 bbdb/mail-auto-create-p)
109 (bbdb-record-putprop record 'attribution attr)
110 (bbdb-change-record record nil))))
112 (defun mu-bbdb-get-prefix-register-method ()
113 (let ((addr (mu-cite-get-value 'address)))
114 (or (mu-bbdb-get-attr addr)
116 (read-string "Citation name? "
117 (or (mu-cite-get-value 'x-attribution)
118 (mu-cite-get-value 'full-name))
119 'mu-cite-minibuffer-history)))
120 (if (and (not (string-equal return ""))
121 (y-or-n-p (format "Register \"%s\"? " return)))
122 (mu-bbdb-set-attr return addr))
125 (defun mu-bbdb-get-prefix-register-verbose-method ()
126 (let* ((addr (mu-cite-get-value 'address))
127 (attr (mu-bbdb-get-attr addr))
128 (return (read-string "Citation name? "
130 (mu-cite-get-value 'x-attribution)
131 (mu-cite-get-value 'full-name))
132 'mu-cite-minibuffer-history)))
133 (if (and (not (string-equal return ""))
134 (not (string-equal return attr))
135 (y-or-n-p (format "Register \"%s\"? " return)))
136 (mu-bbdb-set-attr return addr))
139 (unless (assoc 'bbdb-prefix mu-cite-default-methods-alist)
140 (setq mu-cite-default-methods-alist
141 (append mu-cite-default-methods-alist
144 (function mu-bbdb-get-prefix-method))
145 (cons 'bbdb-prefix-register
146 (function mu-bbdb-get-prefix-register-method))
147 (cons 'bbdb-prefix-register-verbose
149 mu-bbdb-get-prefix-register-verbose-method))))))
157 (run-hooks 'mu-bbdb-load-hook)
159 ;;; mu-bbdb.el ends here