Update.
[elisp/wanderlust.git] / wl / wl-address.el
index 2ca14ba..dc62579 100644 (file)
@@ -46,6 +46,7 @@
 (defvar wl-address-list nil)
 (defvar wl-address-completion-list nil)
 (defvar wl-address-petname-hash nil)
+(defvar wl-address-enable-strict-loading t)
 
 (defvar wl-address-ldap-search-hash nil)
 
@@ -273,12 +274,18 @@ Matched address lists are append to CL."
       (setq entries (cdr entries)))
     (append result cl)))
 
-(defun wl-complete-field-to ()
-  (interactive)
-  (let ((cl wl-address-completion-list))
-    (if cl
-       (completing-read "To: " cl)
-      (read-string "To: "))))
+(defun wl-complete-address (string predicate flag)
+  "Completion function for completing-read (comma separated addresses)."
+  (if (string-match "^\\(.*,\\)\\(.*\\)$" string)
+      (let* ((str1 (match-string 1 string))
+            (str2 (match-string 2 string))
+            (str2-comp (wl-complete-address str2 predicate flag)))
+       (if (and (not flag) (stringp str2-comp))
+           (concat str1 str2-comp)
+         str2-comp))
+    (if (not flag)
+       (try-completion string wl-address-list)
+      (all-completions string wl-address-list))))
 
 (defalias 'wl-address-quote-specials 'elmo-address-quote-specials)
 
@@ -288,28 +295,33 @@ Matched address lists are append to CL."
       (setq addr-tuple (car address-list))
       (setq cl
            (cons
-            (cons (nth 0 addr-tuple)
-                  (if (or (string= (nth 2 addr-tuple) "")
-                          (string-match ".*:.*;$" (nth 0 addr-tuple)))
-                      (nth 0 addr-tuple)
-                    (concat
-                     (wl-address-quote-specials
-                      (nth 2 addr-tuple)) " <"(nth 0 addr-tuple)">")))
+            (wl-address-make-completion-entry 0 addr-tuple)
             cl))
       ;; nickname completion.
-      (setq cl
-           (cons
-            (cons (nth 1 addr-tuple)
-                  (if (or (string= (nth 2 addr-tuple) "")
-                          (string-match ".*:.*;$" (nth 0 addr-tuple)))
-                      (nth 0 addr-tuple)
-                    (concat
-                     (wl-address-quote-specials
-                      (nth 2 addr-tuple)) " <"(nth 0 addr-tuple)">")))
-            cl))
+      (if wl-address-enable-strict-loading
+         (unless (or (equal (nth 1 addr-tuple) (nth 0 addr-tuple))
+                     ;; already exists
+                     (assoc (nth 1 addr-tuple) cl))
+           (setq cl
+                 (cons
+                  (wl-address-make-completion-entry 1 addr-tuple)
+                  cl)))
+       (setq cl
+             (cons
+              (wl-address-make-completion-entry 1 addr-tuple)
+              cl)))
       (setq address-list (cdr address-list)))
     cl))
 
+(defun wl-address-make-completion-entry (index addr-tuple)
+  (cons (nth index addr-tuple)
+       (if (or (string= (nth 2 addr-tuple) "")
+               (string-match ".*:.*;$" (nth 0 addr-tuple)))
+           (nth 0 addr-tuple)
+         (concat
+          (wl-address-quote-specials
+           (nth 2 addr-tuple)) " <"(nth 0 addr-tuple)">"))))
+
 (defun wl-complete-field-body-or-tab ()
   (interactive)
   (let ((case-fold-search t)
@@ -362,7 +374,7 @@ Matched address lists are append to CL."
     (with-output-to-temp-buffer
        wl-completion-buf-name
       (display-completion-list all))
-    (message "Making completion list... done")))
+    (message "Making completion list...done")))
 
 (defun wl-complete-window-delete ()
   (let (comp-buf comp-win)
@@ -442,7 +454,8 @@ Matched address lists are append to CL."
             (message "Sole completion"))
            ((and epand-char
                  (> len 0)
-                 (char-equal (aref pattern (1- len)) epand-char)
+                 (or (char-equal (aref pattern (1- len)) epand-char)
+                     (char-equal (aref pattern (1- len)) ?\ ))
                  (assoc (substring pattern 0 (1- len)) cl))
             (wl-complete-insert
              start end
@@ -635,7 +648,7 @@ Group list contents is not included."
     (with-temp-buffer
       (message "Deleting Address...")
       (insert-file-contents wl-address-file)
-      (delete-matching-lines (concat "^[ \t]*" the-email))
+      (delete-matching-lines (concat "^[ \t]*" the-email "[ \t]+\".*\"[ \t]+\".*\"$"))
       (write-region (point-min) (point-max)
                    wl-address-file nil 'no-msg)
       ;; Delete entries.
@@ -659,9 +672,16 @@ If already registerd, change it."
                                                the-realname)))
     (when change-address
       (setq new-addr (read-from-minibuffer "E-Mail: " address))
-      (if (and (not (string= address new-addr))
-              (assoc new-addr wl-address-list))
-         (error "'%s' already exists" new-addr)))
+      (cond
+       ((or (not (stringp new-addr))
+           (string-match "^[ \t]*$" new-addr))
+       (error "empty address"))
+       ((and (not (string= address new-addr))
+            (assoc new-addr wl-address-list))
+       (error "'%s' already exists" new-addr))
+       (t
+       ;; do nothing
+       )))
     ;; writing to ~/.address
     (let ((output-coding-system
           (mime-charset-to-coding-system wl-mime-charset)))