X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tm-bbdb.el;h=cf0ac19ca40ea5462438d67342509ad8f45aed3c;hb=53ab6c426401d04d0d0ce99d6df144187be6ba01;hp=d41760641bec8a388c583f641876dc4032356e59;hpb=227a9b3b792a6e82efbeb3a4fdb2490ff7049429;p=elisp%2Ftm.git diff --git a/tm-bbdb.el b/tm-bbdb.el index d417606..cf0ac19 100644 --- a/tm-bbdb.el +++ b/tm-bbdb.el @@ -1,11 +1,14 @@ ;;; -;;; tm-bbdb.el --- tm shred module for BBDB +;;; tm-bbdb.el --- tm shared module for BBDB ;;; -;;; Copyright (C) 1995 KOBAYASHI Shuhei +;;; Copyright (C) 1995,1996 KOBAYASHI Shuhei +;;; Copyright (C) 1996 Artur Pioro ;;; -;;; Author: KOBAYASHI Shuhei -;;; Maintainer: MORIOKA Tomohiko -;;; Version: $Id: tm-bbdb.el,v 2.0 1996/01/23 04:34:12 morioka Exp $ +;;; Author: KOBAYASHI Shuhei +;;; Artur Pioro +;;; modified by Pekka Marjola +;;; Maintainer: KOBAYASHI Shuhei +;;; Version: $Id: tm-bbdb.el,v 7.9 1996/05/23 16:42:14 shuhei-k Exp $ ;;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB ;;; ;;; This file is part of tm (Tools for MIME). @@ -27,33 +30,51 @@ ;;; Code: (require 'bbdb) +(require 'bbdb-com) (require 'tl-822) (require 'tm-ew-d) +(require 'tm-view) + + +;;; @ mail-extr +;;; + +(defvar tm-bbdb/use-mail-extr t) (defun tm-bbdb/extract-address-components (str) (let* ((ret (rfc822/extract-address-components str)) (phrase (car ret)) - (address (cdr ret)) + (address (car (cdr ret))) (methods tm-bbdb/canonicalize-full-name-methods)) (while (and phrase methods) (setq phrase (funcall (car methods) phrase) methods (cdr methods))) - (cons phrase address) + (if (string= address "") (setq address nil)) + (if (string= phrase "") (setq phrase nil)) + (list phrase address) )) -(fset 'mail-extract-address-components - (symbol-function 'tm-bbdb/extract-address-components)) -(provide 'mail-extr) +(or tm-bbdb/use-mail-extr + (progn + (require 'mail-extr) ; for `what-domain' + (fset 'mail-extract-address-components + (symbol-function 'tm-bbdb/extract-address-components)) + )) + + +;;; @ bbdb-extract-field-value +;;; (or (fboundp 'tm:bbdb-extract-field-value) (progn ;; (require 'bbdb-hooks) ; not provided. - (or (fboundp 'bbdb-extract-field-value) + ;; (or (fboundp 'bbdb-extract-field-value) ; defined as autoload + (or (fboundp 'bbdb-header-start) (load "bbdb-hooks")) (fset 'tm:bbdb-extract-field-value (symbol-function 'bbdb-extract-field-value)) (defun bbdb-extract-field-value (field) - (let ((value (rfc822/get-field-body field))) + (let ((value (tm:bbdb-extract-field-value field))) (and value (mime-eword/decode-string value)))) )) @@ -86,12 +107,10 @@ (mapconcat 'identity dest " ") )) -(defvar tm-bbdb/canonicalize-full-name-methods nil) - -(setq tm-bbdb/canonicalize-full-name-methods - '(mime-eword/decode-string - tm-bbdb/canonicalize-dots - tm-bbdb/canonicalize-spaces)) +(defvar tm-bbdb/canonicalize-full-name-methods + '(mime-eword/decode-string + tm-bbdb/canonicalize-dots + tm-bbdb/canonicalize-spaces)) ;;; @ BBDB functions for mime/viewer-mode @@ -105,28 +124,26 @@ Creating or modifying it as necessary. A record will be created if tm-bbdb/auto-create-p is non-nil, or if OFFER-TO-CREATE is non-nil and the user confirms the creation." (save-excursion - (and mime::article/preview-buffer - (get-buffer mime::article/preview-buffer) - (set-buffer mime::article/preview-buffer)) + (if (and mime::article/preview-buffer + (get-buffer mime::article/preview-buffer)) + (set-buffer mime::article/preview-buffer)) (if bbdb-use-pop-up (tm-bbdb/pop-up-bbdb-buffer offer-to-create) - (let ((from (rfc822/get-field-body "From"))) - (if (or (null from) - (string-match (bbdb-user-mail-names) - (car - (cdr - ;; (tm-bbdb/extract-address-components from) - (mail-extract-address-components from) - )))) - (setq from (or (rfc822/get-field-body "To") - from))) - (if from - (bbdb-annotate-message-sender - from t - (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p) - offer-to-create) - offer-to-create)) - )))) + (let* ((from (rfc822/get-field-body "From")) + (addr (if from + (car (cdr (mail-extract-address-components from)))))) + (if (or (null from) + (null addr) + (string-match (bbdb-user-mail-names) addr)) + (setq from (or (rfc822/get-field-body "To") + from))) + (if from + (bbdb-annotate-message-sender + from t + (or (bbdb-invoke-hook-for-value tm-bbdb/auto-create-p) + offer-to-create) + offer-to-create)) + )))) (defun tm-bbdb/annotate-sender (string) "Add a line to the end of the Notes field of the BBDB record @@ -176,6 +193,57 @@ displaying the record corresponding to the sender of the current message." (set-buffer b) record))) +(define-key mime/viewer-mode-map ";" 'tm-bbdb/edit-notes) +(define-key mime/viewer-mode-map ":" 'tm-bbdb/show-sender) + + +;;; @ for signature.el +;;; + +(defun signature/get-bbdb-sigtype (addr) + "Extract sigtype information from BBDB." + (let ((record (bbdb-search-simple nil addr))) + (and record + (bbdb-record-getprop record 'sigtype)) + )) + +(defun signature/set-bbdb-sigtype (sigtype addr) + "Add sigtype information to BBDB." + (let* ((bbdb-notice-hook nil) + (record (bbdb-annotate-message-sender + addr t + (bbdb-invoke-hook-for-value + bbdb/mail-auto-create-p) + t))) + (if record + (progn + (bbdb-record-putprop record 'sigtype sigtype) + (bbdb-change-record record nil)) + ))) + +(defun signature/get-sigtype-from-bbdb (&optional verbose) + (let* ((to (rfc822/get-field-body "To")) + (addr (and to + (car (cdr (mail-extract-address-components to))))) + (sigtype (signature/get-bbdb-sigtype addr)) + return + ) + (if addr + (if verbose + (progn + (setq return (signature/get-sigtype-interactively sigtype)) + (if (and (not (string-equal return sigtype)) + (y-or-n-p + (format "Register \"%s\" for <%s>? " return addr)) + ) + (signature/set-bbdb-sigtype return addr) + ) + return) + (or sigtype + (signature/get-signature-file-name)) + )) + )) + ;;; @ end ;;;