2 ;;; tm-bbdb.el --- tm shred 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 2.0 1996/01/23 04:34:12 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.
33 (defun tm-bbdb/extract-address-components (str)
34 (let* ((ret (rfc822/extract-address-components str))
37 (methods tm-bbdb/canonicalize-full-name-methods))
38 (while (and phrase methods)
39 (setq phrase (funcall (car methods) phrase)
40 methods (cdr methods)))
44 (fset 'mail-extract-address-components
45 (symbol-function 'tm-bbdb/extract-address-components))
48 (or (fboundp 'tm:bbdb-extract-field-value)
50 ;; (require 'bbdb-hooks) ; not provided.
51 (or (fboundp 'bbdb-extract-field-value)
53 (fset 'tm:bbdb-extract-field-value
54 (symbol-function 'bbdb-extract-field-value))
55 (defun bbdb-extract-field-value (field)
56 (let ((value (rfc822/get-field-body field)))
58 (mime-eword/decode-string value))))
62 ;;; @ full-name canonicalization methods
65 (defun tm-bbdb/canonicalize-spaces (str)
67 (while (string-match "\\s +" str)
68 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
69 (setq str (substring str (match-end 0)))
72 (setq dest (cons str dest)))
73 (setq dest (nreverse dest))
74 (mapconcat 'identity dest " ")
77 (defun tm-bbdb/canonicalize-dots (str)
79 (while (string-match "\\." str)
80 (setq dest (cons (substring str 0 (match-end 0)) dest))
81 (setq str (substring str (match-end 0)))
84 (setq dest (cons str dest)))
85 (setq dest (nreverse dest))
86 (mapconcat 'identity dest " ")
89 (defvar tm-bbdb/canonicalize-full-name-methods nil)
91 (setq tm-bbdb/canonicalize-full-name-methods
92 '(mime-eword/decode-string
93 tm-bbdb/canonicalize-dots
94 tm-bbdb/canonicalize-spaces))
97 ;;; @ BBDB functions for mime/viewer-mode
100 (defvar tm-bbdb/auto-create-p nil)
102 (defun tm-bbdb/update-record (&optional offer-to-create)
103 "Return the record corresponding to the current MIME previewing message.
104 Creating or modifying it as necessary. A record will be created if
105 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
106 the user confirms the creation."
108 (and mime::article/preview-buffer
109 (get-buffer mime::article/preview-buffer)
110 (set-buffer mime::article/preview-buffer))
112 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
113 (let ((from (rfc822/get-field-body "From")))
115 (string-match (bbdb-user-mail-names)
118 ;; (tm-bbdb/extract-address-components from)
119 (mail-extract-address-components from)
121 (setq from (or (rfc822/get-field-body "To")
124 (bbdb-annotate-message-sender
126 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
131 (defun tm-bbdb/annotate-sender (string)
132 "Add a line to the end of the Notes field of the BBDB record
133 corresponding to the sender of this message."
135 (list (if bbdb-readonly-p
136 (error "The Insidious Big Brother Database is read-only.")
137 (read-string "Comments: "))))
138 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
140 (defun tm-bbdb/edit-notes (&optional arg)
141 "Edit the notes field or (with a prefix arg) a user-defined field
142 of the BBDB record corresponding to the sender of this message."
144 (let ((record (or (tm-bbdb/update-record t)
146 (bbdb-display-records (list record))
148 (bbdb-record-edit-property record nil t)
149 (bbdb-record-edit-notes record t))))
151 (defun tm-bbdb/show-sender ()
152 "Display the contents of the BBDB for the sender of this message.
153 This buffer will be in bbdb-mode, with associated keybindings."
155 (let ((record (tm-bbdb/update-record t)))
157 (bbdb-display-records (list record))
158 (error "unperson"))))
160 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
161 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
162 displaying the record corresponding to the sender of the current message."
163 (bbdb-pop-up-bbdb-buffer
164 (function (lambda (w)
165 (let ((b (current-buffer)))
166 (set-buffer (window-buffer w))
167 (prog1 (eq major-mode 'mime/viewer-mode)
169 (let ((bbdb-gag-messages t)
170 (bbdb-use-pop-up nil)
171 (bbdb-electric-p nil))
172 (let ((record (tm-bbdb/update-record offer-to-create))
173 (bbdb-elided-display (bbdb-pop-up-elided-display))
174 (b (current-buffer)))
175 (bbdb-display-records (if record (list record) nil))
185 (run-hooks 'tm-bbdb-load-hook)
187 ;;; end of tm-bbdb.el