* wl-util.el (wl-read-shell-commande): New function or alias.
[elisp/wanderlust.git] / wl / wl-address.el
index 6026ad6..2d9f845 100644 (file)
@@ -37,7 +37,7 @@
 (require 'wl-vars)
 (require 'std11)
 
-(defvar wl-address-complete-header-list 
+(defvar wl-address-complete-header-list
   '("To:" "From:" "Cc:" "Bcc:" "Mail-Followup-To:" "Reply-To:"
     "Return-Receipt-To:"))
 (defvar wl-address-complete-header-regexp nil) ; auto-generated.
@@ -87,7 +87,7 @@ If level 3 is required for uniqness with other candidates,
 (defconst wl-ldap-alias-sep "/")
 
 (defconst wl-ldap-search-attribute-type-list
-  '("sn" "cn" "mail" "email" "displayName" "gecos"))
+  '("sn" "cn" "mail" "email"))
 
 (defun wl-ldap-get-value (type entry)
   ""
@@ -207,7 +207,7 @@ Matched address lists are append to CL."
        (ldap-default-base (or wl-ldap-base ldap-default-base))
        (dnhash (elmo-make-hash))
        cache len sym tmpl regexp entries ent values dn dnstr alias
-       result fullname mails)
+       result cn mails)
     ;; check cache
     (mapatoms (lambda (atom)
                (if (and (string-match
@@ -244,9 +244,7 @@ Matched address lists are append to CL."
                    ent)
            mails (or (wl-ldap-get-value-list "mail" ent)
                      (wl-ldap-get-value-list "email" ent))
-           fullname (or (wl-ldap-get-value "displayName" ent)
-                        (wl-ldap-get-value "gecos" ent)
-                        (wl-ldap-get-value "cn" ent))
+           cn (wl-ldap-get-value "cn" ent)
            dn (car (car entries))
            dnstr (elmo-get-hash-val (upcase dn) dnhash))
       ;; make alias list generated from LDAP data.
@@ -261,7 +259,7 @@ Matched address lists are append to CL."
        (when (not (boundp sym))
          (set sym alias)
          (setq result (cons (cons alias
-                                  (concat fullname " <" (car mails) ">"))
+                                  (concat cn " <" (car mails) ">"))
                             result)))
        (setq values (cdr values)))
       ;; make mail addrses list
@@ -270,7 +268,7 @@ Matched address lists are append to CL."
            ;; (string-match regexp (car mails))
            ;; add mail address itself to completion list
            (setq result (cons (cons (car mails)
-                                    (concat fullname " <" (car mails) ">"))
+                                    (concat cn " <" (car mails) ">"))
                               result)))
        (setq mails (cdr mails)))
       (setq entries (cdr entries)))
@@ -526,7 +524,7 @@ Refresh `wl-address-list', `wl-address-completion-list', and
           (wl-address-expand-aliases alist (1+ nest-count))))))
 
 (defun wl-address-make-alist-from-alias-file (file)
-  (elmo-set-work-buf
+  (with-temp-buffer
     (let ((case-fold-search t)
          alias expn alist)
       (insert-file-contents file)
@@ -544,23 +542,23 @@ Refresh `wl-address-list', `wl-address-completion-list', and
       )))
 
 (defun wl-address-make-address-list (path)
-  (if (and path (file-readable-p path))
-      (elmo-set-work-buf
-       (let (ret
-            (coding-system-for-read wl-cs-autoconv))
-        (insert-file-contents path)
-        (goto-char (point-min))
-        (while (not (eobp))
-          (if (looking-at
-               "^\\([^#\n][^ \t\n]+\\)[ \t]+\\(\".*\"\\)[ \t]+\\(\".*\"\\)[ \t]*.*$")
-              (setq ret
-                    (cons
-                     (list (wl-match-buffer 1)
-                           (read (wl-match-buffer 2))
-                           (read (wl-match-buffer 3)))
-                     ret)))
-          (forward-line))
-        (nreverse ret)))))
+  (when (and path (file-readable-p path))
+    (with-temp-buffer
+      (let (ret
+           (coding-system-for-read wl-cs-autoconv))
+       (insert-file-contents path)
+       (goto-char (point-min))
+       (while (not (eobp))
+         (if (looking-at "\
+^\\([^#\n][^ \t\n]+\\)[ \t]+\\(\".*\"\\)[ \t]+\\(\".*\"\\)[ \t]*.*$")
+             (setq ret
+                   (cons
+                    (list (wl-match-buffer 1)
+                          (read (wl-match-buffer 2))
+                          (read (wl-match-buffer 3)))
+                    ret)))
+         (forward-line))
+       (nreverse ret)))))
 
 
 (defsubst wl-address-header-extract-address (str)
@@ -735,6 +733,31 @@ If already registerd, change it."
        (wl-address-init)
        (list (or new-addr address) the-petname the-realname)))))
 
+;; Read addresses from minibuffer with completion.
+(defvar wl-address-minibuffer-history nil)
+(defvar wl-address-minibuffer-local-map nil
+  "Keymap to use when reading address from the minibuffer.")
+
+(unless wl-address-minibuffer-local-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map minibuffer-local-map)
+    (define-key map "\C-i"
+      (lambda ()
+       (interactive)
+       (wl-complete-field-body wl-address-completion-list
+                               ?@ nil wl-use-ldap)))
+    (setq wl-address-minibuffer-local-map map)))
+
+(defun wl-address-read-from-minibuffer (prompt &optional
+                                              initial-contents
+                                              default-value)
+  (read-from-minibuffer prompt
+                       initial-contents
+                       wl-address-minibuffer-local-map
+                       nil
+                       'wl-address-minibuffer-history
+                       default-value))
+
 (require 'product)
 (product-provide (provide 'wl-address) (require 'wl-version))