Mercurial > hg > xemacs-beta
comparison lisp/tm/tm-bbdb.el @ 4:b82b59fe008d r19-15b3
Import from CVS: tag r19-15b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:56 +0200 |
parents | |
children | 4b173ad71786 |
comparison
equal
deleted
inserted
replaced
3:30df88044ec6 | 4:b82b59fe008d |
---|---|
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> | |
9 ;; Version: $Id: tm-bbdb.el,v 1.1.1.1 1996/12/18 03:55:31 steve Exp $ | |
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 | |
31 (require 'std11) | |
32 (require 'tm-ew-d) | |
33 (require 'tm-view) | |
34 (require 'bbdb-com) ; (require 'bbdb) implicitly | |
35 | |
36 ;;; @ mail-extr | |
37 ;;; | |
38 | |
39 (defvar tm-bbdb/use-mail-extr t) | |
40 | |
41 (defun tm-bbdb/extract-address-components (str) | |
42 (let* ((ret (std11-extract-address-components str)) | |
43 (phrase (car ret)) | |
44 (address (car (cdr ret))) | |
45 (methods tm-bbdb/canonicalize-full-name-methods)) | |
46 (while (and phrase methods) | |
47 (setq phrase (funcall (car methods) phrase) | |
48 methods (cdr methods))) | |
49 (if (string= address "") (setq address nil)) | |
50 (if (string= phrase "") (setq phrase nil)) | |
51 (list phrase address) | |
52 )) | |
53 | |
54 (or tm-bbdb/use-mail-extr | |
55 (progn | |
56 (require 'mail-extr) ; for `what-domain' | |
57 (or (fboundp 'tm:mail-extract-address-components) | |
58 (fset 'tm:mail-extract-address-components | |
59 (symbol-function 'mail-extract-address-components))) | |
60 (fset 'mail-extract-address-components | |
61 (symbol-function 'tm-bbdb/extract-address-components)) | |
62 )) | |
63 | |
64 | |
65 ;;; @ bbdb-extract-field-value | |
66 ;;; | |
67 | |
68 (or (fboundp 'tm:bbdb-extract-field-value) | |
69 (progn | |
70 ;; (require 'bbdb-hooks) ; not provided. | |
71 ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload | |
72 (or (fboundp 'bbdb-header-start) | |
73 (load "bbdb-hooks")) | |
74 (fset 'tm:bbdb-extract-field-value | |
75 (symbol-function 'bbdb-extract-field-value)) | |
76 (defun bbdb-extract-field-value (field) | |
77 (let ((value (tm:bbdb-extract-field-value field))) | |
78 (and value | |
79 (mime-eword/decode-string value)))) | |
80 )) | |
81 | |
82 | |
83 ;;; @ full-name canonicalization methods | |
84 ;;; | |
85 | |
86 (defun tm-bbdb/canonicalize-spaces (str) | |
87 (let (dest) | |
88 (while (string-match "\\s +" str) | |
89 (setq dest (cons (substring str 0 (match-beginning 0)) dest)) | |
90 (setq str (substring str (match-end 0))) | |
91 ) | |
92 (or (string= str "") | |
93 (setq dest (cons str dest))) | |
94 (setq dest (nreverse dest)) | |
95 (mapconcat 'identity dest " ") | |
96 )) | |
97 | |
98 (defun tm-bbdb/canonicalize-dots (str) | |
99 (let (dest) | |
100 (while (string-match "\\." str) | |
101 (setq dest (cons (substring str 0 (match-end 0)) dest)) | |
102 (setq str (substring str (match-end 0))) | |
103 ) | |
104 (or (string= str "") | |
105 (setq dest (cons str dest))) | |
106 (setq dest (nreverse dest)) | |
107 (mapconcat 'identity dest " ") | |
108 )) | |
109 | |
110 (defvar tm-bbdb/canonicalize-full-name-methods | |
111 '(mime-eword/decode-string | |
112 tm-bbdb/canonicalize-dots | |
113 tm-bbdb/canonicalize-spaces)) | |
114 | |
115 | |
116 ;;; @ BBDB functions for mime/viewer-mode | |
117 ;;; | |
118 | |
119 (defvar tm-bbdb/auto-create-p nil) | |
120 | |
121 (defun tm-bbdb/update-record (&optional offer-to-create) | |
122 "Return the record corresponding to the current MIME previewing message. | |
123 Creating or modifying it as necessary. A record will be created if | |
124 tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and | |
125 the user confirms the creation." | |
126 (save-excursion | |
127 (if (and mime::article/preview-buffer | |
128 (get-buffer mime::article/preview-buffer)) | |
129 (set-buffer mime::article/preview-buffer)) | |
130 (if bbdb-use-pop-up | |
131 (tm-bbdb/pop-up-bbdb-buffer offer-to-create) | |
132 (let* ((from (std11-field-body "From")) | |
133 (addr (if from | |
134 (car (cdr (mail-extract-address-components from)))))) | |
135 (if (or (null from) | |
136 (null addr) | |
137 (string-match (bbdb-user-mail-names) addr)) | |
138 (setq from (or (std11-field-body "To") from)) | |
139 ) | |
140 (if from | |
141 (bbdb-annotate-message-sender | |
142 from t | |
143 (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p) | |
144 offer-to-create) | |
145 offer-to-create)) | |
146 )))) | |
147 | |
148 (defun tm-bbdb/annotate-sender (string) | |
149 "Add a line to the end of the Notes field of the BBDB record | |
150 corresponding to the sender of this message." | |
151 (interactive | |
152 (list (if bbdb-readonly-p | |
153 (error "The Insidious Big Brother Database is read-only.") | |
154 (read-string "Comments: ")))) | |
155 (bbdb-annotate-notes (tm-bbdb/update-record t) string)) | |
156 | |
157 (defun tm-bbdb/edit-notes (&optional arg) | |
158 "Edit the notes field or (with a prefix arg) a user-defined field | |
159 of the BBDB record corresponding to the sender of this message." | |
160 (interactive "P") | |
161 (let ((record (or (tm-bbdb/update-record t) | |
162 (error "")))) | |
163 (bbdb-display-records (list record)) | |
164 (if arg | |
165 (bbdb-record-edit-property record nil t) | |
166 (bbdb-record-edit-notes record t)))) | |
167 | |
168 (defun tm-bbdb/show-sender () | |
169 "Display the contents of the BBDB for the sender of this message. | |
170 This buffer will be in bbdb-mode, with associated keybindings." | |
171 (interactive) | |
172 (let ((record (tm-bbdb/update-record t))) | |
173 (if record | |
174 (bbdb-display-records (list record)) | |
175 (error "unperson")))) | |
176 | |
177 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create) | |
178 "Make the *BBDB* buffer be displayed along with the MIME preview window(s), | |
179 displaying the record corresponding to the sender of the current message." | |
180 (let ((framepop (eq temp-buffer-show-function 'framepop-display-buffer))) | |
181 (or framepop | |
182 (bbdb-pop-up-bbdb-buffer | |
183 (function | |
184 (lambda (w) | |
185 (let ((b (current-buffer))) | |
186 (set-buffer (window-buffer w)) | |
187 (prog1 (eq major-mode 'mime/viewer-mode) | |
188 (set-buffer b))))))) | |
189 (let ((bbdb-gag-messages t) | |
190 (bbdb-use-pop-up nil) | |
191 (bbdb-electric-p nil)) | |
192 (let ((record (tm-bbdb/update-record offer-to-create)) | |
193 (bbdb-elided-display (bbdb-pop-up-elided-display)) | |
194 (b (current-buffer))) | |
195 (if framepop | |
196 (if record | |
197 (bbdb-display-records (list record)) | |
198 (framepop-banish)) | |
199 (bbdb-display-records (if record (list record) nil)) | |
200 (if (not record) | |
201 (progn | |
202 (set-buffer "*BBDB*") | |
203 (delete-window)))) | |
204 (set-buffer b) | |
205 record)))) | |
206 | |
207 (defun tm-bbdb/define-keys () | |
208 (let ((mime/viewer-mode-map (current-local-map))) | |
209 (define-key mime/viewer-mode-map ";" 'tm-bbdb/edit-notes) | |
210 (define-key mime/viewer-mode-map ":" 'tm-bbdb/show-sender) | |
211 )) | |
212 | |
213 (add-hook 'mime-viewer/define-keymap-hook 'tm-bbdb/define-keys) | |
214 | |
215 | |
216 ;;; @ for signature.el | |
217 ;;; | |
218 | |
219 (defun signature/get-bbdb-sigtype (addr) | |
220 "Extract sigtype information from BBDB." | |
221 (let ((record (bbdb-search-simple nil addr))) | |
222 (and record | |
223 (bbdb-record-getprop record 'sigtype)) | |
224 )) | |
225 | |
226 (defun signature/set-bbdb-sigtype (sigtype addr) | |
227 "Add sigtype information to BBDB." | |
228 (let* ((bbdb-notice-hook nil) | |
229 (record (bbdb-annotate-message-sender | |
230 addr t | |
231 (bbdb-invoke-hook-for-value | |
232 bbdb/mail-auto-create-p) | |
233 t))) | |
234 (if record | |
235 (progn | |
236 (bbdb-record-putprop record 'sigtype sigtype) | |
237 (bbdb-change-record record nil)) | |
238 ))) | |
239 | |
240 (defun signature/get-sigtype-from-bbdb (&optional verbose) | |
241 (let* ((to (std11-field-body "To")) | |
242 (addr (and to | |
243 (car (cdr (mail-extract-address-components to))))) | |
244 (sigtype (signature/get-bbdb-sigtype addr)) | |
245 return | |
246 ) | |
247 (if addr | |
248 (if verbose | |
249 (progn | |
250 (setq return (signature/get-sigtype-interactively sigtype)) | |
251 (if (and (not (string-equal return sigtype)) | |
252 (y-or-n-p | |
253 (format "Register \"%s\" for <%s>? " return addr)) | |
254 ) | |
255 (signature/set-bbdb-sigtype return addr) | |
256 ) | |
257 return) | |
258 (or sigtype | |
259 (signature/get-signature-file-name)) | |
260 )) | |
261 )) | |
262 | |
263 | |
264 ;;; @ end | |
265 ;;; | |
266 | |
267 (provide 'tm-bbdb) | |
268 | |
269 (run-hooks 'tm-bbdb-load-hook) | |
270 | |
271 ;;; end of tm-bbdb.el |