Fix last change.
[elisp/wanderlust.git] / utils / bbdb-wl.el
index e1444bc..b40e4c2 100644 (file)
 (defvar bbdb-wl-folder-regexp nil)
 (defvar bbdb-wl-ignore-folder-regexp nil)
 
+(defvar bbdb-wl-canonicalize-full-name-function
+  #'bbdb-wl-canonicalize-spaces-and-dots
+  "Way to canonicalize full name.")
+
+(defun bbdb-wl-canonicalize-spaces-and-dots (string)
+  (while (and string (string-match "  +\\|[\f\t\n\r\v]+\\|\\." string))
+    (setq string (replace-match " " nil t string)))
+  (and string (string-match "^ " string)
+       (setq string (replace-match "" nil t string)))
+  string)
+
 ;;;###autoload
 (defun bbdb-wl-setup ()
   (add-hook 'wl-message-redisplay-hook 'bbdb-wl-get-update-record)
   (add-hook 'wl-summary-exit-hook 'bbdb-wl-hide-bbdb-buffer)
   (add-hook 'wl-message-window-deleted-hook 'bbdb-wl-hide-bbdb-buffer)
   (add-hook 'wl-exit-hook 'bbdb-wl-exit)
+  (add-hook 'wl-save-hook 'bbdb-offer-save)
   (add-hook 'wl-summary-toggle-disp-off-hook 'bbdb-wl-hide-bbdb-buffer)
   (add-hook 'wl-summary-toggle-disp-folder-on-hook 'bbdb-wl-hide-bbdb-buffer)
   (add-hook 'wl-summary-toggle-disp-folder-off-hook 'bbdb-wl-hide-bbdb-buffer)
             (lambda ()
 ;;;           (local-set-key "\M-\t" 'bbdb-complete-name)
               (define-key (current-local-map) "\M-\t" 'bbdb-complete-name))))
-  ;; BBDB 2.00.06 or earlier:
-  ;;  auto-autoloads.el includes (provide 'bbdb-autoloads)
-  ;;  Don't exist bbdb-autoloads.el
-  (when (and (not (featurep 'bbdb-autoloads))
-            (module-installed-p 'bbdb-autoloads))
-    ;; BBDB 2.20: bbdb-autoloads.el NOT includes (provide 'bbdb-autoloads)
-    (load "bbdb-autoloads"))
-  
+  (require 'bbdb)
+  (bbdb-initialize)
+
   (if (not (boundp 'bbdb-get-addresses-from-headers))
       (defvar bbdb-get-addresses-from-headers
        '("From" "Resent-From" "Reply-To")))
@@ -180,6 +187,7 @@ For BBDB 2.33 or earlier."
                              (eword-decode-string
                               (decode-mime-charset-string
                                fn wl-mime-charset))))
+                    fn (funcall bbdb-wl-canonicalize-full-name-function fn)
                    ad (std11-address-string structure))
              ;; ignore uninteresting addresses, this is kinda gross!
              (when (or (not (stringp uninteresting-senders))
@@ -216,7 +224,7 @@ For BBDB 2.34 or later."
                                (std11-unfold-string header-content)))
              (while (and (setq structure (car structures))
                          (eq (car structure) 'mailbox))
-               (setq fn (std11-full-name-string structure)
+                (setq fn (std11-full-name-string structure)
                      fn (and fn
                              (with-temp-buffer ; to keep raw buffer unibyte.
                                (elmo-set-buffer-multibyte
@@ -224,6 +232,7 @@ For BBDB 2.34 or later."
                                (eword-decode-string
                                 (decode-mime-charset-string
                                  fn wl-mime-charset))))
+                     fn (funcall bbdb-wl-canonicalize-full-name-function fn)
                      ad (std11-address-string structure))
                ;; ignore uninteresting addresses, this is kinda gross!
                (when (or (not (stringp uninteresting-senders))