2 ;;; tm-bbdb.el --- tm shared module for BBDB
4 ;;; Copyright (C) 1995,1996 KOBAYASHI Shuhei
5 ;;; Copyright (C) 1996 Artur Pioro
7 ;;; Author: KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
8 ;;; Artur Pioro <artur@flugor.if.uj.edu.pl>
9 ;;; modified by Pekka Marjola <marjola@bilbo.ntc.nokia.com>
10 ;;; Maintainer: KOBAYASHI Shuhei <shuhei-k@jaist.ac.jp>
11 ;;; Version: $Id: tm-bbdb.el,v 7.7 1996/04/23 06:34:57 shuhei-k Exp $
12 ;;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB
14 ;;; This file is part of tm (Tools for MIME).
16 ;;; This program is free software; you can redistribute it and/or
17 ;;; modify it under the terms of the GNU General Public License as
18 ;;; published by the Free Software Foundation; either version 2, or
19 ;;; (at your option) any later version.
21 ;;; This program is distributed in the hope that it will be useful,
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;;; General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with This program. If not, write to the Free Software
28 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
42 (defvar tm-bbdb/use-mail-extr t)
44 (defun tm-bbdb/extract-address-components (str)
45 (let* ((ret (rfc822/extract-address-components str))
47 (address (car (cdr ret)))
48 (methods tm-bbdb/canonicalize-full-name-methods))
49 (while (and phrase methods)
50 (setq phrase (funcall (car methods) phrase)
51 methods (cdr methods)))
52 (if (string= address "") (setq address nil))
53 (if (string= phrase "") (setq phrase nil))
57 (or tm-bbdb/use-mail-extr
59 (require 'mail-extr) ; for `what-domain'
60 (fset 'mail-extract-address-components
61 (symbol-function 'tm-bbdb/extract-address-components))
65 ;;; @ bbdb-extract-field-value
68 (or (fboundp 'tm:bbdb-extract-field-value)
70 ;; (require 'bbdb-hooks) ; not provided.
71 ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload
72 (or (fboundp 'bbdb-header-start)
74 (fset 'tm:bbdb-extract-field-value
75 (symbol-function 'bbdb-extract-field-value))
76 (defun bbdb-extract-field-value (field)
77 (let ((value (tm:bbdb-extract-field-value field)))
79 (mime-eword/decode-string value))))
83 ;;; @ full-name canonicalization methods
86 (defun tm-bbdb/canonicalize-spaces (str)
88 (while (string-match "\\s +" str)
89 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
90 (setq str (substring str (match-end 0)))
93 (setq dest (cons str dest)))
94 (setq dest (nreverse dest))
95 (mapconcat 'identity dest " ")
98 (defun tm-bbdb/canonicalize-dots (str)
100 (while (string-match "\\." str)
101 (setq dest (cons (substring str 0 (match-end 0)) dest))
102 (setq str (substring str (match-end 0)))
105 (setq dest (cons str dest)))
106 (setq dest (nreverse dest))
107 (mapconcat 'identity dest " ")
110 (defvar tm-bbdb/canonicalize-full-name-methods
111 '(mime-eword/decode-string
112 tm-bbdb/canonicalize-dots
113 tm-bbdb/canonicalize-spaces))
116 ;;; @ BBDB functions for mime/viewer-mode
119 (defvar tm-bbdb/auto-create-p nil)
121 (defun tm-bbdb/update-record (&optional offer-to-create)
122 "Return the record corresponding to the current MIME previewing message.
123 Creating or modifying it as necessary. A record will be created if
124 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
125 the user confirms the creation."
127 (if (and mime::article/preview-buffer
128 (get-buffer mime::article/preview-buffer))
129 (set-buffer mime::article/preview-buffer))
131 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
132 (let* ((from (rfc822/get-field-body "From"))
134 (car (cdr (mail-extract-address-components from))))))
137 (string-match (bbdb-user-mail-names) addr))
138 (setq from (or (rfc822/get-field-body "To")
141 (bbdb-annotate-message-sender
143 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
148 (defun tm-bbdb/annotate-sender (string)
149 "Add a line to the end of the Notes field of the BBDB record
150 corresponding to the sender of this message."
152 (list (if bbdb-readonly-p
153 (error "The Insidious Big Brother Database is read-only.")
154 (read-string "Comments: "))))
155 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
157 (defun tm-bbdb/edit-notes (&optional arg)
158 "Edit the notes field or (with a prefix arg) a user-defined field
159 of the BBDB record corresponding to the sender of this message."
161 (let ((record (or (tm-bbdb/update-record t)
163 (bbdb-display-records (list record))
165 (bbdb-record-edit-property record nil t)
166 (bbdb-record-edit-notes record t))))
168 (defun tm-bbdb/show-sender ()
169 "Display the contents of the BBDB for the sender of this message.
170 This buffer will be in bbdb-mode, with associated keybindings."
172 (let ((record (tm-bbdb/update-record t)))
174 (bbdb-display-records (list record))
175 (error "unperson"))))
177 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
178 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
179 displaying the record corresponding to the sender of the current message."
180 (bbdb-pop-up-bbdb-buffer
181 (function (lambda (w)
182 (let ((b (current-buffer)))
183 (set-buffer (window-buffer w))
184 (prog1 (eq major-mode 'mime/viewer-mode)
186 (let ((bbdb-gag-messages t)
187 (bbdb-use-pop-up nil)
188 (bbdb-electric-p nil))
189 (let ((record (tm-bbdb/update-record offer-to-create))
190 (bbdb-elided-display (bbdb-pop-up-elided-display))
191 (b (current-buffer)))
192 (bbdb-display-records (if record (list record) nil))
197 ;;; @ for signature.el
200 (defun signature/get-bbdb-sigtype (addr)
201 "Extract sigtype information from BBDB."
202 (let ((record (bbdb-search-simple nil addr)))
204 (bbdb-record-getprop record 'sigtype))
207 (defun signature/set-bbdb-sigtype (sigtype addr)
208 "Add sigtype information to BBDB."
209 (let* ((bbdb-notice-hook nil)
210 (record (bbdb-annotate-message-sender
212 (bbdb-invoke-hook-for-value
213 bbdb/mail-auto-create-p)
217 (bbdb-record-putprop record 'sigtype sigtype)
218 (bbdb-change-record record nil))
221 (defun signature/get-sigtype-from-bbdb (&optional verbose)
222 (let* ((to (rfc822/get-field-body "To"))
224 (car (cdr (mail-extract-address-components to)))))
225 (sigtype (signature/get-bbdb-sigtype addr))
231 (setq return (signature/get-sigtype-interactively sigtype))
232 (if (and (not (string-equal return sigtype))
234 (format "Register \"%s\" for <%s>? " return addr))
236 (signature/set-bbdb-sigtype return addr)
240 (signature/get-signature-file-name))
250 (run-hooks 'tm-bbdb-load-hook)
252 ;;; end of tm-bbdb.el