This commit was generated by cvs2svn to compensate for changes in r485,
[elisp/tm.git] / tm-bbdb.el
index 277371d..e07e816 100644 (file)
@@ -1,36 +1,37 @@
-;;;
 ;;; tm-bbdb.el --- tm shared module for BBDB
-;;;
-;;; Copyright (C) 1995 KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>
-;;;
-;;; Author: KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>
-;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;;; Version: $Id: tm-bbdb.el,v 7.0 1996/03/13 16:23:26 morioka Exp $
-;;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB
-;;;
-;;; This file is part of tm (Tools for MIME).
-;;;
-;;; This program is free software; you can redistribute it and/or
-;;; modify it under the terms of the GNU General Public License as
-;;; published by the Free Software Foundation; either version 2, or
-;;; (at your option) any later version.
-;;;
-;;; This program is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;;; General Public License for more details.
-;;;
-;;; You should have received a copy of the GNU General Public License
-;;; along with This program.  If not, write to the Free Software
-;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-;;;
+
+;; Copyright (C) 1995,1996 Shuhei KOBAYASHI
+;; Copyright (C) 1996 Artur Pioro
+
+;; Author: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
+;;         Artur Pioro <artur@flugor.if.uj.edu.pl>
+;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
+;; Version: $Id: tm-bbdb.el,v 7.22 1996/11/30 18:40:09 shuhei-k Exp $
+;; Keywords: mail, news, MIME, multimedia, multilingual, BBDB
+
+;; This file is part of tm (Tools for MIME).
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
 ;;; Code:
 
-(require 'bbdb)
-(require 'tl-822)
+(require 'std11)
 (require 'tm-ew-d)
 (require 'tm-view)
-
+(require 'bbdb-com) ; (require 'bbdb) implicitly
 
 ;;; @ mail-extr
 ;;;
 (defvar tm-bbdb/use-mail-extr t)
 
 (defun tm-bbdb/extract-address-components (str)
-  (let* ((ret     (rfc822/extract-address-components str))
+  (let* ((ret     (std11-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)))
-    (if (string= phrase "")
-        (setq phrase nil))
-    (cons phrase address)
+    (if (string= address "") (setq address nil))
+    (if (string= phrase "") (setq phrase nil))
+    (list phrase address)
     ))
 
 (or tm-bbdb/use-mail-extr
     (progn
       (require 'mail-extr) ; for `what-domain'
+      (or (fboundp 'tm:mail-extract-address-components)
+          (fset 'tm:mail-extract-address-components
+                (symbol-function 'mail-extract-address-components)))
       (fset 'mail-extract-address-components
            (symbol-function 'tm-bbdb/extract-address-components))
       ))
@@ -125,13 +129,14 @@ the user confirms the creation."
         (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"))
-             (addr (car (cdr (mail-extract-address-components from)))))
+      (let* ((from (std11-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)))
+            (setq from (or (std11-field-body "To") from))
+         )
         (if from
             (bbdb-annotate-message-sender
              from t
@@ -141,7 +146,7 @@ the user confirms the creation."
         ))))
 
 (defun tm-bbdb/annotate-sender (string)
-  "Add a line to the end of the Notes field of the BBDB record 
+  "Add a line to the end of the Notes field of the BBDB record
 corresponding to the sender of this message."
   (interactive
    (list (if bbdb-readonly-p
@@ -172,21 +177,84 @@ This buffer will be in bbdb-mode, with associated keybindings."
 (defun tm-bbdb/pop-up-bbdb-buffer (&optional offer-to-create)
   "Make the *BBDB* buffer be displayed along with the MIME preview window(s),
 displaying the record corresponding to the sender of the current message."
-  (bbdb-pop-up-bbdb-buffer
-    (function (lambda (w)
-      (let ((b (current-buffer)))
-       (set-buffer (window-buffer w))
-       (prog1 (eq major-mode 'mime/viewer-mode)
-         (set-buffer b))))))
-  (let ((bbdb-gag-messages t)
-       (bbdb-use-pop-up nil)
-       (bbdb-electric-p nil))
-    (let ((record (tm-bbdb/update-record offer-to-create))
-         (bbdb-elided-display (bbdb-pop-up-elided-display))
-         (b (current-buffer)))
-      (bbdb-display-records (if record (list record) nil))
-      (set-buffer b)
-      record)))
+  (let ((framepop (eq temp-buffer-show-function 'framepop-display-buffer)))
+    (or framepop
+        (bbdb-pop-up-bbdb-buffer
+         (function
+          (lambda (w)
+            (let ((b (current-buffer)))
+              (set-buffer (window-buffer w))
+              (prog1 (eq major-mode 'mime/viewer-mode)
+                (set-buffer b)))))))
+    (let ((bbdb-gag-messages t)
+          (bbdb-use-pop-up nil)
+          (bbdb-electric-p nil))
+      (let ((record (tm-bbdb/update-record offer-to-create))
+            (bbdb-elided-display (bbdb-pop-up-elided-display))
+            (b (current-buffer)))
+        (if framepop
+            (if record
+                (bbdb-display-records (list record))
+              (framepop-banish))
+          (bbdb-display-records (if record (list record) nil)))
+        (set-buffer b)
+        record))))
+
+(defun tm-bbdb/define-keys ()
+  (let ((mime/viewer-mode-map (current-local-map)))
+    (define-key mime/viewer-mode-map ";" 'tm-bbdb/edit-notes)
+    (define-key mime/viewer-mode-map ":" 'tm-bbdb/show-sender)
+    ))
+
+(add-hook 'mime-viewer/define-keymap-hook 'tm-bbdb/define-keys)
+
+
+;;; @ 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 (std11-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