4
|
1 ;;; tm-bbdb.el --- tm shared module for BBDB
|
|
2
|
|
3 ;; Copyright (C) 1995,1996 Shuhei KOBAYASHI
|
|
4 ;; Copyright (C) 1996 Artur Pioro
|
|
5
|
|
6 ;; Author: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
|
|
7 ;; Artur Pioro <artur@flugor.if.uj.edu.pl>
|
|
8 ;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
|
70
|
9 ;; Version: $Id: tm-bbdb.el,v 1.1.1.1 1996/12/18 22:43:38 steve Exp $
|
4
|
10 ;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB
|
|
11
|
|
12 ;; This file is part of tm (Tools for MIME).
|
|
13
|
|
14 ;; This program is free software; you can redistribute it and/or
|
|
15 ;; modify it under the terms of the GNU General Public License as
|
|
16 ;; published by the Free Software Foundation; either version 2, or (at
|
|
17 ;; your option) any later version.
|
|
18
|
|
19 ;; This program is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
|
28
|
|
29 ;;; Code:
|
|
30
|
70
|
31 (eval-when (compile)
|
|
32 (ignore-errors
|
|
33 (require 'bbdb)
|
|
34 (require 'bbdb-com)))
|
|
35 (eval-when (load eval)
|
|
36 (require 'bbdb)
|
|
37 (require 'bbdb-com))
|
4
|
38 (require 'std11)
|
|
39 (require 'tm-ew-d)
|
|
40 (require 'tm-view)
|
8
|
41
|
|
42
|
4
|
43 ;;; @ mail-extr
|
|
44 ;;;
|
|
45
|
70
|
46 (defvar tm-bbdb/use-mail-extr t)
|
|
47
|
4
|
48 (defun tm-bbdb/extract-address-components (str)
|
|
49 (let* ((ret (std11-extract-address-components str))
|
|
50 (phrase (car ret))
|
|
51 (address (car (cdr ret)))
|
|
52 (methods tm-bbdb/canonicalize-full-name-methods))
|
|
53 (while (and phrase methods)
|
|
54 (setq phrase (funcall (car methods) phrase)
|
|
55 methods (cdr methods)))
|
|
56 (if (string= address "") (setq address nil))
|
|
57 (if (string= phrase "") (setq phrase nil))
|
|
58 (list phrase address)
|
|
59 ))
|
|
60
|
|
61 (or tm-bbdb/use-mail-extr
|
|
62 (progn
|
|
63 (require 'mail-extr) ; for `what-domain'
|
|
64 (or (fboundp 'tm:mail-extract-address-components)
|
|
65 (fset 'tm:mail-extract-address-components
|
|
66 (symbol-function 'mail-extract-address-components)))
|
|
67 (fset 'mail-extract-address-components
|
|
68 (symbol-function 'tm-bbdb/extract-address-components))
|
|
69 ))
|
|
70
|
|
71
|
|
72 ;;; @ bbdb-extract-field-value
|
|
73 ;;;
|
|
74
|
|
75 (or (fboundp 'tm:bbdb-extract-field-value)
|
|
76 (progn
|
|
77 ;; (require 'bbdb-hooks) ; not provided.
|
|
78 ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload
|
|
79 (or (fboundp 'bbdb-header-start)
|
|
80 (load "bbdb-hooks"))
|
|
81 (fset 'tm:bbdb-extract-field-value
|
|
82 (symbol-function 'bbdb-extract-field-value))
|
|
83 (defun bbdb-extract-field-value (field)
|
|
84 (let ((value (tm:bbdb-extract-field-value field)))
|
|
85 (and value
|
|
86 (mime-eword/decode-string value))))
|
|
87 ))
|
|
88
|
|
89
|
|
90 ;;; @ full-name canonicalization methods
|
|
91 ;;;
|
|
92
|
|
93 (defun tm-bbdb/canonicalize-spaces (str)
|
|
94 (let (dest)
|
|
95 (while (string-match "\\s +" str)
|
|
96 (setq dest (cons (substring str 0 (match-beginning 0)) dest))
|
|
97 (setq str (substring str (match-end 0)))
|
|
98 )
|
|
99 (or (string= str "")
|
|
100 (setq dest (cons str dest)))
|
|
101 (setq dest (nreverse dest))
|
|
102 (mapconcat 'identity dest " ")
|
|
103 ))
|
|
104
|
|
105 (defun tm-bbdb/canonicalize-dots (str)
|
|
106 (let (dest)
|
|
107 (while (string-match "\\." str)
|
|
108 (setq dest (cons (substring str 0 (match-end 0)) dest))
|
|
109 (setq str (substring str (match-end 0)))
|
|
110 )
|
|
111 (or (string= str "")
|
|
112 (setq dest (cons str dest)))
|
|
113 (setq dest (nreverse dest))
|
|
114 (mapconcat 'identity dest " ")
|
|
115 ))
|
|
116
|
|
117 (defvar tm-bbdb/canonicalize-full-name-methods
|
|
118 '(mime-eword/decode-string
|
|
119 tm-bbdb/canonicalize-dots
|
|
120 tm-bbdb/canonicalize-spaces))
|
|
121
|
|
122
|
|
123 ;;; @ BBDB functions for mime/viewer-mode
|
|
124 ;;;
|
|
125
|
70
|
126 (defvar tm-bbdb/auto-create-p nil)
|
|
127
|
4
|
128 (defun tm-bbdb/update-record (&optional offer-to-create)
|
|
129 "Return the record corresponding to the current MIME previewing message.
|
|
130 Creating or modifying it as necessary. A record will be created if
|
|
131 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and
|
|
132 the user confirms the creation."
|
|
133 (save-excursion
|
|
134 (if (and mime::article/preview-buffer
|
|
135 (get-buffer mime::article/preview-buffer))
|
|
136 (set-buffer mime::article/preview-buffer))
|
|
137 (if bbdb-use-pop-up
|
|
138 (tm-bbdb/pop-up-bbdb-buffer offer-to-create)
|
|
139 (let* ((from (std11-field-body "From"))
|
|
140 (addr (if from
|
|
141 (car (cdr (mail-extract-address-components from))))))
|
|
142 (if (or (null from)
|
|
143 (null addr)
|
|
144 (string-match (bbdb-user-mail-names) addr))
|
|
145 (setq from (or (std11-field-body "To") from))
|
|
146 )
|
|
147 (if from
|
|
148 (bbdb-annotate-message-sender
|
|
149 from t
|
|
150 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p)
|
|
151 offer-to-create)
|
|
152 offer-to-create))
|
|
153 ))))
|
|
154
|
|
155 (defun tm-bbdb/annotate-sender (string)
|
70
|
156 "Add a line to the end of the Notes field of the BBDB record
|
4
|
157 corresponding to the sender of this message."
|
|
158 (interactive
|
|
159 (list (if bbdb-readonly-p
|
|
160 (error "The Insidious Big Brother Database is read-only.")
|
|
161 (read-string "Comments: "))))
|
|
162 (bbdb-annotate-notes (tm-bbdb/update-record t) string))
|
|
163
|
|
164 (defun tm-bbdb/edit-notes (&optional arg)
|
|
165 "Edit the notes field or (with a prefix arg) a user-defined field
|
|
166 of the BBDB record corresponding to the sender of this message."
|
|
167 (interactive "P")
|
|
168 (let ((record (or (tm-bbdb/update-record t)
|
|
169 (error ""))))
|
|
170 (bbdb-display-records (list record))
|
|
171 (if arg
|
|
172 (bbdb-record-edit-property record nil t)
|
|
173 (bbdb-record-edit-notes record t))))
|
|
174
|
|
175 (defun tm-bbdb/show-sender ()
|
|
176 "Display the contents of the BBDB for the sender of this message.
|
|
177 This buffer will be in bbdb-mode, with associated keybindings."
|
|
178 (interactive)
|
|
179 (let ((record (tm-bbdb/update-record t)))
|
|
180 (if record
|
|
181 (bbdb-display-records (list record))
|
|
182 (error "unperson"))))
|
|
183
|
|
184 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
|
|
185 "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
|
|
186 displaying the record corresponding to the sender of the current message."
|
70
|
187 (bbdb-pop-up-bbdb-buffer
|
|
188 (function
|
|
189 (lambda (w)
|
|
190 (let ((b (current-buffer)))
|
|
191 (set-buffer (window-buffer w))
|
|
192 (prog1 (eq major-mode 'mime/viewer-mode)
|
|
193 (set-buffer b))))))
|
|
194 (let ((bbdb-gag-messages t)
|
|
195 (bbdb-use-pop-up nil)
|
|
196 (bbdb-electric-p nil))
|
|
197 (let ((record (tm-bbdb/update-record offer-to-create))
|
|
198 (bbdb-elided-display (bbdb-pop-up-elided-display))
|
|
199 (b (current-buffer)))
|
|
200 (bbdb-display-records (if record (list record) nil))
|
|
201 (or record
|
|
202 (delete-windows-on (get-buffer "*BBDB*")))
|
|
203 (set-buffer b)
|
|
204 record)))
|
4
|
205
|
|
206 (defun tm-bbdb/define-keys ()
|
|
207 (let ((mime/viewer-mode-map (current-local-map)))
|
|
208 (define-key mime/viewer-mode-map ";" 'tm-bbdb/edit-notes)
|
|
209 (define-key mime/viewer-mode-map ":" 'tm-bbdb/show-sender)
|
|
210 ))
|
|
211
|
|
212 (add-hook 'mime-viewer/define-keymap-hook 'tm-bbdb/define-keys)
|
|
213
|
|
214
|
|
215 ;;; @ for signature.el
|
|
216 ;;;
|
|
217
|
|
218 (defun signature/get-bbdb-sigtype (addr)
|
|
219 "Extract sigtype information from BBDB."
|
|
220 (let ((record (bbdb-search-simple nil addr)))
|
|
221 (and record
|
|
222 (bbdb-record-getprop record 'sigtype))
|
|
223 ))
|
|
224
|
|
225 (defun signature/set-bbdb-sigtype (sigtype addr)
|
|
226 "Add sigtype information to BBDB."
|
|
227 (let* ((bbdb-notice-hook nil)
|
70
|
228 (record (bbdb-annotate-message-sender
|
4
|
229 addr t
|
70
|
230 (bbdb-invoke-hook-for-value
|
4
|
231 bbdb/mail-auto-create-p)
|
|
232 t)))
|
|
233 (if record
|
|
234 (progn
|
|
235 (bbdb-record-putprop record 'sigtype sigtype)
|
|
236 (bbdb-change-record record nil))
|
|
237 )))
|
|
238
|
|
239 (defun signature/get-sigtype-from-bbdb (&optional verbose)
|
|
240 (let* ((to (std11-field-body "To"))
|
|
241 (addr (and to
|
|
242 (car (cdr (mail-extract-address-components to)))))
|
|
243 (sigtype (signature/get-bbdb-sigtype addr))
|
70
|
244 return
|
4
|
245 )
|
|
246 (if addr
|
|
247 (if verbose
|
|
248 (progn
|
|
249 (setq return (signature/get-sigtype-interactively sigtype))
|
|
250 (if (and (not (string-equal return sigtype))
|
|
251 (y-or-n-p
|
|
252 (format "Register \"%s\" for <%s>? " return addr))
|
|
253 )
|
|
254 (signature/set-bbdb-sigtype return addr)
|
|
255 )
|
|
256 return)
|
|
257 (or sigtype
|
|
258 (signature/get-signature-file-name))
|
|
259 ))
|
|
260 ))
|
|
261
|
|
262
|
|
263 ;;; @ end
|
|
264 ;;;
|
|
265
|
|
266 (provide 'tm-bbdb)
|
|
267
|
|
268 (run-hooks 'tm-bbdb-load-hook)
|
|
269
|
|
270 ;;; end of tm-bbdb.el
|