2 ;;; tm-bbdb.el --- tm shared module for BBDB
4 ;;; Copyright (C) 1995 KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>
6 ;;; Author: KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>
7 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Version: $Id: tm-bbdb.el,v 3.0 1996/01/24 02:20:25 morioka Exp $
9 ;;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB
11 ;;; This file is part of tm (Tools for MIME).
13 ;;; This program is free software; you can redistribute it and/or
14 ;;; modify it under the terms of the GNU General Public License as
15 ;;; published by the Free Software Foundation; either version 2, or
16 ;;; (at your option) any later version.
18 ;;; This program is distributed in the hope that it will be useful,
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;;; General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with This program. If not, write to the Free Software
25 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
37 (defvar tm-bbdb/use-mail-extr t)
39 (defun tm-bbdb/extract-address-components (str)
40 (let* ((ret (rfc822/extract-address-components str))
43 (methods tm-bbdb/canonicalize-full-name-methods))
44 (while (and phrase methods)
45 (setq phrase (funcall (car methods) phrase)
46 methods (cdr methods)))
50 (or tm-bbdb/use-mail-extr
52 (fset 'mail-extract-address-components
53 (symbol-function 'tm-bbdb/extract-address-components))
58 ;;; @ bbdb-extract-field-value
61 (or (fboundp 'tm:bbdb-extract-field-value)
63 ;; (require 'bbdb-hooks) ; not provided.
64 (or (fboundp 'bbdb-extract-field-value)
66 (fset 'tm:bbdb-extract-field-value
67 (symbol-function 'bbdb-extract-field-value))
68 (defun bbdb-extract-field-value (field)
69 (let ((value (rfc822/get-field-body field)))
71 (mime-eword/decode-string value))))
75 ;;; @ full-name canonicalization methods
78 (defun tm-bbdb/canonicalize-spaces (str)
80 (while (string-match "\\s +" str)
81 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
82 (setq str (substring str (match-end 0)))
85 (setq dest (cons str dest)))
86 (setq dest (nreverse dest))
87 (mapconcat 'identity dest " ")
90 (defun tm-bbdb/canonicalize-dots (str)
92 (while (string-match "\\." str)
93 (setq dest (cons (substring str 0 (match-end 0)) dest))
94 (setq str (substring str (match-end 0)))
97 (setq dest (cons str dest)))
98 (setq dest (nreverse dest))
99 (mapconcat 'identity dest " ")
102 (defvar tm-bbdb/canonicalize-full-name-methods nil)
104 (setq tm-bbdb/canonicalize-full-name-methods
105 '(mime-eword/decode-string
106 tm-bbdb/canonicalize-dots
107 tm-bbdb/canonicalize-spaces))
110 ;;; @ BBDB functions for mime/viewer-mode
113 (defvar tm-bbdb/auto-create-p nil)
115 (defun tm-bbdb/update-record (&optional offer-to-create)
116 "Return the record corresponding to the current MIME previewing message.
117 Creating or modifying it as necessary. A record will be created if
118 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
119 the user confirms the creation."
121 (and mime::article/preview-buffer
122 (get-buffer mime::article/preview-buffer)
123 (set-buffer mime::article/preview-buffer))
125 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
126 (let ((from (rfc822/get-field-body "From")))
128 (string-match (bbdb-user-mail-names)
131 ;; (tm-bbdb/extract-address-components from)
132 (mail-extract-address-components from)
134 (setq from (or (rfc822/get-field-body "To")
137 (bbdb-annotate-message-sender
139 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
144 (defun tm-bbdb/annotate-sender (string)
145 "Add a line to the end of the Notes field of the BBDB record
146 corresponding to the sender of this message."
148 (list (if bbdb-readonly-p
149 (error "The Insidious Big Brother Database is read-only.")
150 (read-string "Comments: "))))
151 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
153 (defun tm-bbdb/edit-notes (&optional arg)
154 "Edit the notes field or (with a prefix arg) a user-defined field
155 of the BBDB record corresponding to the sender of this message."
157 (let ((record (or (tm-bbdb/update-record t)
159 (bbdb-display-records (list record))
161 (bbdb-record-edit-property record nil t)
162 (bbdb-record-edit-notes record t))))
164 (defun tm-bbdb/show-sender ()
165 "Display the contents of the BBDB for the sender of this message.
166 This buffer will be in bbdb-mode, with associated keybindings."
168 (let ((record (tm-bbdb/update-record t)))
170 (bbdb-display-records (list record))
171 (error "unperson"))))
173 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
174 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
175 displaying the record corresponding to the sender of the current message."
176 (bbdb-pop-up-bbdb-buffer
177 (function (lambda (w)
178 (let ((b (current-buffer)))
179 (set-buffer (window-buffer w))
180 (prog1 (eq major-mode 'mime/viewer-mode)
182 (let ((bbdb-gag-messages t)
183 (bbdb-use-pop-up nil)
184 (bbdb-electric-p nil))
185 (let ((record (tm-bbdb/update-record offer-to-create))
186 (bbdb-elided-display (bbdb-pop-up-elided-display))
187 (b (current-buffer)))
188 (bbdb-display-records (if record (list record) nil))
198 (run-hooks 'tm-bbdb-load-hook)
200 ;;; end of tm-bbdb.el