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 6.0 1996/03/04 11:58:55 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.
38 (defvar tm-bbdb/use-mail-extr t)
40 (defun tm-bbdb/extract-address-components (str)
41 (let* ((ret (rfc822/extract-address-components str))
44 (methods tm-bbdb/canonicalize-full-name-methods))
45 (while (and phrase methods)
46 (setq phrase (funcall (car methods) phrase)
47 methods (cdr methods)))
48 (if (string= phrase "")
53 (or tm-bbdb/use-mail-extr
55 (fset 'mail-extract-address-components
56 (symbol-function 'tm-bbdb/extract-address-components))
61 ;;; @ bbdb-extract-field-value
64 (or (fboundp 'tm:bbdb-extract-field-value)
66 ;; (require 'bbdb-hooks) ; not provided.
67 ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload
68 (or (fboundp 'bbdb-header-start)
70 (fset 'tm:bbdb-extract-field-value
71 (symbol-function 'bbdb-extract-field-value))
72 (defun bbdb-extract-field-value (field)
73 (let ((value (tm:bbdb-extract-field-value field)))
75 (mime-eword/decode-string value))))
79 ;;; @ full-name canonicalization methods
82 (defun tm-bbdb/canonicalize-spaces (str)
84 (while (string-match "\\s +" str)
85 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
86 (setq str (substring str (match-end 0)))
89 (setq dest (cons str dest)))
90 (setq dest (nreverse dest))
91 (mapconcat 'identity dest " ")
94 (defun tm-bbdb/canonicalize-dots (str)
96 (while (string-match "\\." str)
97 (setq dest (cons (substring str 0 (match-end 0)) dest))
98 (setq str (substring str (match-end 0)))
101 (setq dest (cons str dest)))
102 (setq dest (nreverse dest))
103 (mapconcat 'identity dest " ")
106 (defvar tm-bbdb/canonicalize-full-name-methods
107 '(mime-eword/decode-string
108 tm-bbdb/canonicalize-dots
109 tm-bbdb/canonicalize-spaces))
112 ;;; @ BBDB functions for mime/viewer-mode
115 (defvar tm-bbdb/auto-create-p nil)
117 (defun tm-bbdb/update-record (&optional offer-to-create)
118 "Return the record corresponding to the current MIME previewing message.
119 Creating or modifying it as necessary. A record will be created if
120 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
121 the user confirms the creation."
123 (if (and mime::article/preview-buffer
124 (get-buffer mime::article/preview-buffer))
125 (set-buffer mime::article/preview-buffer))
127 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
128 (let ((from (rfc822/get-field-body "From")))
130 (string-match (bbdb-user-mail-names)
133 ;; (tm-bbdb/extract-address-components from)
134 (mail-extract-address-components from)
136 (setq from (or (rfc822/get-field-body "To")
139 (bbdb-annotate-message-sender
141 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
146 (defun tm-bbdb/annotate-sender (string)
147 "Add a line to the end of the Notes field of the BBDB record
148 corresponding to the sender of this message."
150 (list (if bbdb-readonly-p
151 (error "The Insidious Big Brother Database is read-only.")
152 (read-string "Comments: "))))
153 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
155 (defun tm-bbdb/edit-notes (&optional arg)
156 "Edit the notes field or (with a prefix arg) a user-defined field
157 of the BBDB record corresponding to the sender of this message."
159 (let ((record (or (tm-bbdb/update-record t)
161 (bbdb-display-records (list record))
163 (bbdb-record-edit-property record nil t)
164 (bbdb-record-edit-notes record t))))
166 (defun tm-bbdb/show-sender ()
167 "Display the contents of the BBDB for the sender of this message.
168 This buffer will be in bbdb-mode, with associated keybindings."
170 (let ((record (tm-bbdb/update-record t)))
172 (bbdb-display-records (list record))
173 (error "unperson"))))
175 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
176 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
177 displaying the record corresponding to the sender of the current message."
178 (bbdb-pop-up-bbdb-buffer
179 (function (lambda (w)
180 (let ((b (current-buffer)))
181 (set-buffer (window-buffer w))
182 (prog1 (eq major-mode 'mime/viewer-mode)
184 (let ((bbdb-gag-messages t)
185 (bbdb-use-pop-up nil)
186 (bbdb-electric-p nil))
187 (let ((record (tm-bbdb/update-record offer-to-create))
188 (bbdb-elided-display (bbdb-pop-up-elided-display))
189 (b (current-buffer)))
190 (bbdb-display-records (if record (list record) nil))
200 (run-hooks 'tm-bbdb-load-hook)
202 ;;; end of tm-bbdb.el