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 4.0 1996/01/26 08:20:29 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)))
47 (if (string= phrase "")
52 (or tm-bbdb/use-mail-extr
54 (fset 'mail-extract-address-components
55 (symbol-function 'tm-bbdb/extract-address-components))
60 ;;; @ bbdb-extract-field-value
63 (or (fboundp 'tm:bbdb-extract-field-value)
65 ;; (require 'bbdb-hooks) ; not provided.
66 ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload
67 (or (fboundp 'bbdb-header-start)
69 (fset 'tm:bbdb-extract-field-value
70 (symbol-function 'bbdb-extract-field-value))
71 (defun bbdb-extract-field-value (field)
72 (let ((value (rfc822/get-field-body field)))
74 (mime-eword/decode-string value))))
78 ;;; @ full-name canonicalization methods
81 (defun tm-bbdb/canonicalize-spaces (str)
83 (while (string-match "\\s +" str)
84 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
85 (setq str (substring str (match-end 0)))
88 (setq dest (cons str dest)))
89 (setq dest (nreverse dest))
90 (mapconcat 'identity dest " ")
93 (defun tm-bbdb/canonicalize-dots (str)
95 (while (string-match "\\." str)
96 (setq dest (cons (substring str 0 (match-end 0)) dest))
97 (setq str (substring str (match-end 0)))
100 (setq dest (cons str dest)))
101 (setq dest (nreverse dest))
102 (mapconcat 'identity dest " ")
105 (defvar tm-bbdb/canonicalize-full-name-methods
106 '(mime-eword/decode-string
107 tm-bbdb/canonicalize-dots
108 tm-bbdb/canonicalize-spaces))
111 ;;; @ BBDB functions for mime/viewer-mode
114 (defvar tm-bbdb/auto-create-p nil)
116 (defun tm-bbdb/update-record (&optional offer-to-create)
117 "Return the record corresponding to the current MIME previewing message.
118 Creating or modifying it as necessary. A record will be created if
119 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
120 the user confirms the creation."
122 (if (and mime::article/preview-buffer
123 (get-buffer mime::article/preview-buffer))
124 (set-buffer mime::article/preview-buffer))
126 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
127 (let ((from (rfc822/get-field-body "From")))
129 (string-match (bbdb-user-mail-names)
132 ;; (tm-bbdb/extract-address-components from)
133 (mail-extract-address-components from)
135 (setq from (or (rfc822/get-field-body "To")
138 (bbdb-annotate-message-sender
140 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
145 (defun tm-bbdb/annotate-sender (string)
146 "Add a line to the end of the Notes field of the BBDB record
147 corresponding to the sender of this message."
149 (list (if bbdb-readonly-p
150 (error "The Insidious Big Brother Database is read-only.")
151 (read-string "Comments: "))))
152 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
154 (defun tm-bbdb/edit-notes (&optional arg)
155 "Edit the notes field or (with a prefix arg) a user-defined field
156 of the BBDB record corresponding to the sender of this message."
158 (let ((record (or (tm-bbdb/update-record t)
160 (bbdb-display-records (list record))
162 (bbdb-record-edit-property record nil t)
163 (bbdb-record-edit-notes record t))))
165 (defun tm-bbdb/show-sender ()
166 "Display the contents of the BBDB for the sender of this message.
167 This buffer will be in bbdb-mode, with associated keybindings."
169 (let ((record (tm-bbdb/update-record t)))
171 (bbdb-display-records (list record))
172 (error "unperson"))))
174 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
175 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
176 displaying the record corresponding to the sender of the current message."
177 (bbdb-pop-up-bbdb-buffer
178 (function (lambda (w)
179 (let ((b (current-buffer)))
180 (set-buffer (window-buffer w))
181 (prog1 (eq major-mode 'mime/viewer-mode)
183 (let ((bbdb-gag-messages t)
184 (bbdb-use-pop-up nil)
185 (bbdb-electric-p nil))
186 (let ((record (tm-bbdb/update-record offer-to-create))
187 (bbdb-elided-display (bbdb-pop-up-elided-display))
188 (b (current-buffer)))
189 (bbdb-display-records (if record (list record) nil))
199 (run-hooks 'tm-bbdb-load-hook)
201 ;;; end of tm-bbdb.el