1 ;;; tm-bbdb.el --- tm shared module for BBDB
3 ;; Copyright (C) 1995,1996 KOBAYASHI Shuhei
4 ;; Copyright (C) 1996 Artur Pioro
6 ;; Author: KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
7 ;; Artur Pioro <artur@flugor.if.uj.edu.pl>
8 ;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Version: $Id: tm-bbdb.el,v 7.16 1996/10/02 04:19:02 shuhei-k Exp $
10 ;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB
12 ;; This file is part of tm (Tools for MIME).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; see the file COPYING. If not, write to
26 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
41 (defvar tm-bbdb/use-mail-extr t)
43 (defun tm-bbdb/extract-address-components (str)
44 (let* ((ret (std11-extract-address-components str))
46 (address (car (cdr ret)))
47 (methods tm-bbdb/canonicalize-full-name-methods))
48 (while (and phrase methods)
49 (setq phrase (funcall (car methods) phrase)
50 methods (cdr methods)))
51 (if (string= address "") (setq address nil))
52 (if (string= phrase "") (setq phrase nil))
56 (or tm-bbdb/use-mail-extr
58 (require 'mail-extr) ; for `what-domain'
59 (or (fboundp 'tm:mail-extract-address-components)
60 (fset 'tm:mail-extract-address-components
61 (symbol-function 'mail-extract-address-components)))
62 (fset 'mail-extract-address-components
63 (symbol-function 'tm-bbdb/extract-address-components))
67 ;;; @ bbdb-extract-field-value
70 (or (fboundp 'tm:bbdb-extract-field-value)
72 ;; (require 'bbdb-hooks) ; not provided.
73 ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload
74 (or (fboundp 'bbdb-header-start)
76 (fset 'tm:bbdb-extract-field-value
77 (symbol-function 'bbdb-extract-field-value))
78 (defun bbdb-extract-field-value (field)
79 (let ((value (tm:bbdb-extract-field-value field)))
81 (mime-eword/decode-string value))))
85 ;;; @ full-name canonicalization methods
88 (defun tm-bbdb/canonicalize-spaces (str)
90 (while (string-match "\\s +" str)
91 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
92 (setq str (substring str (match-end 0)))
95 (setq dest (cons str dest)))
96 (setq dest (nreverse dest))
97 (mapconcat 'identity dest " ")
100 (defun tm-bbdb/canonicalize-dots (str)
102 (while (string-match "\\." str)
103 (setq dest (cons (substring str 0 (match-end 0)) dest))
104 (setq str (substring str (match-end 0)))
107 (setq dest (cons str dest)))
108 (setq dest (nreverse dest))
109 (mapconcat 'identity dest " ")
112 (defvar tm-bbdb/canonicalize-full-name-methods
113 '(mime-eword/decode-string
114 tm-bbdb/canonicalize-dots
115 tm-bbdb/canonicalize-spaces))
118 ;;; @ BBDB functions for mime/viewer-mode
121 (defvar tm-bbdb/auto-create-p nil)
123 (defun tm-bbdb/update-record (&optional offer-to-create)
124 "Return the record corresponding to the current MIME previewing message.
125 Creating or modifying it as necessary. A record will be created if
126 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
127 the user confirms the creation."
129 (if (and mime::article/preview-buffer
130 (get-buffer mime::article/preview-buffer))
131 (set-buffer mime::article/preview-buffer))
133 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
134 (let* ((from (std11-field-body "From"))
136 (car (cdr (mail-extract-address-components from))))))
139 (string-match (bbdb-user-mail-names) addr))
140 (setq from (or (std11-field-body "To") from))
143 (bbdb-annotate-message-sender
145 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
150 (defun tm-bbdb/annotate-sender (string)
151 "Add a line to the end of the Notes field of the BBDB record
152 corresponding to the sender of this message."
154 (list (if bbdb-readonly-p
155 (error "The Insidious Big Brother Database is read-only.")
156 (read-string "Comments: "))))
157 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
159 (defun tm-bbdb/edit-notes (&optional arg)
160 "Edit the notes field or (with a prefix arg) a user-defined field
161 of the BBDB record corresponding to the sender of this message."
163 (let ((record (or (tm-bbdb/update-record t)
165 (bbdb-display-records (list record))
167 (bbdb-record-edit-property record nil t)
168 (bbdb-record-edit-notes record t))))
170 (defun tm-bbdb/show-sender ()
171 "Display the contents of the BBDB for the sender of this message.
172 This buffer will be in bbdb-mode, with associated keybindings."
174 (let ((record (tm-bbdb/update-record t)))
176 (bbdb-display-records (list record))
177 (error "unperson"))))
179 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
180 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
181 displaying the record corresponding to the sender of the current message."
182 (bbdb-pop-up-bbdb-buffer
183 (function (lambda (w)
184 (let ((b (current-buffer)))
185 (set-buffer (window-buffer w))
186 (prog1 (eq major-mode 'mime/viewer-mode)
188 (let ((bbdb-gag-messages t)
189 (bbdb-use-pop-up nil)
190 (bbdb-electric-p nil))
191 (let ((record (tm-bbdb/update-record offer-to-create))
192 (bbdb-elided-display (bbdb-pop-up-elided-display))
193 (b (current-buffer)))
194 (bbdb-display-records (if record (list record) nil))
197 (set-buffer "*BBDB*")
202 (defun tm-bbdb/define-keys ()
203 (let ((mime/viewer-mode-map (current-local-map)))
204 (define-key mime/viewer-mode-map ";" 'tm-bbdb/edit-notes)
205 (define-key mime/viewer-mode-map ":" 'tm-bbdb/show-sender)
208 (add-hook 'mime-viewer/define-keymap-hook 'tm-bbdb/define-keys)
211 ;;; @ for signature.el
214 (defun signature/get-bbdb-sigtype (addr)
215 "Extract sigtype information from BBDB."
216 (let ((record (bbdb-search-simple nil addr)))
218 (bbdb-record-getprop record 'sigtype))
221 (defun signature/set-bbdb-sigtype (sigtype addr)
222 "Add sigtype information to BBDB."
223 (let* ((bbdb-notice-hook nil)
224 (record (bbdb-annotate-message-sender
226 (bbdb-invoke-hook-for-value
227 bbdb/mail-auto-create-p)
231 (bbdb-record-putprop record 'sigtype sigtype)
232 (bbdb-change-record record nil))
235 (defun signature/get-sigtype-from-bbdb (&optional verbose)
236 (let* ((to (std11-field-body "To"))
238 (car (cdr (mail-extract-address-components to)))))
239 (sigtype (signature/get-bbdb-sigtype addr))
245 (setq return (signature/get-sigtype-interactively sigtype))
246 (if (and (not (string-equal return sigtype))
248 (format "Register \"%s\" for <%s>? " return addr))
250 (signature/set-bbdb-sigtype return addr)
254 (signature/get-signature-file-name))
264 (run-hooks 'tm-bbdb-load-hook)
266 ;;; end of tm-bbdb.el