* wl-draft.el (wl-message-mail-p): Test resent-to: field.
[elisp/wanderlust.git] / wl / wl-address.el
index 4d75b79..259ae2b 100644 (file)
@@ -1,8 +1,12 @@
 ;;; wl-address.el -- Tiny address management for Wanderlust.
 
-;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Shun-ichi GOTO <gotoh@taiyo.co.jp>
+;; Copyright (C) 1998,1999,2000 Takeshi Chiba <chiba@d3.bs1.fc.nec.co.jp>
 
 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
+;;     Shun-ichi GOTO <gotoh@taiyo.co.jp>
+;;     Takeshi Chiba <chiba@d3.bs1.fc.nec.co.jp>
 ;; Keywords: mail, net news
 
 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
@@ -49,8 +53,8 @@
 Valid value is nit, t, 1 or larget integer.
 
 If this value nil, minimum alias postfix is made depends on uniqness
-with other candidates. In this implementation, it's same to 1.  If t,
-always append all dn data. If number, always append spcified level of
+with other candidates.  In this implementation, it's same to 1.  If t,
+always append all dn data.  If number, always append spcified level of
 data but maybe appended more uniqness.  If invalid value, treat as
 nil.
 
@@ -74,8 +78,7 @@ If level 3 is required for uniqness with other candidates,
     2 => Goto/Shun-ichi_GOTO/Mew/Emacs    ... appended more
     3 => Goto/Shun-ichi_GOTO/Mew/Emacs
     4 => Goto/Shun-ichi_GOTO/Mew/Emacs/Lisper
-    (so on...)
-")
+    (so on...)")
 
 (defconst wl-ldap-alias-sep "/")
 
@@ -116,6 +119,7 @@ Returns matched uniq string list."
       (setq type (car (car entry))
            values (mapcar (function wl-ldap-alias-safe-string)
                           (cdr (car entry)))
+           values (elmo-flatten values)
            entry (cdr entry))
       (if (string-match "::?$" type)
          (setq type (substring type 0 (match-beginning 0))))
@@ -131,14 +135,13 @@ Returns matched uniq string list."
 (defun wl-ldap-alias-safe-string (str)
   "Modify STR for alias.
 Replace space/tab in STR into '_' char.
-And remove domain part of mail addr."
+Replace '@' in STR into list of mailbox and sub-domains."
   (while (string-match "[^_a-zA-Z0-9+@%.!\\-/]+" str)
     (setq str (concat (substring str 0 (match-beginning 0))
                      "_"
                      (substring str (match-end 0)))))
-  (if (string-match "@[^/@]+" str)
-      (setq str (concat (substring str 0 (match-beginning 0))
-                       (substring str (match-end 0)))))
+  (if (string-match "\\(@\\)[^/@]+" str)
+      (setq str (split-string str  "[@\\.]")))
   str)
 
 (defun wl-ldap-register-dn-string (hash dn &optional str dn-list)
@@ -154,7 +157,8 @@ And remove domain part of mail addr."
                                    (if (string-match "[a-z]+=\\(.*\\)" str)
                                        (wl-ldap-alias-safe-string
                                         (wl-match-string 1 str))))
-                                 (split-string dn ",")))))
+                                 (split-string dn "[ \t]*,[ \t]*")))))
+      (setq dn-list (elmo-flatten dn-list))
       ;; prepare candidate for uniq str
       (if str
          (setq str (concat str wl-ldap-alias-sep (car dn-list))
@@ -276,9 +280,11 @@ Matched address lists are append to CL."
        (completing-read "To: " cl)
       (read-string "To: "))))
 
+(defconst wl-address-specials-regexp "[]\"(),.:;<>@[\\]")
+
 (defun wl-address-quote-specials (word)
   "Make quoted string of WORD if needed."
-  (if (assq 'specials (std11-lexical-analyze word))
+  (if (string-match wl-address-specials-regexp word)
       (prin1-to-string word)
     word))
 
@@ -387,7 +393,7 @@ Matched address lists are append to CL."
                   (progn
                     (delete-region start end)
                     (insert (cdr alias))
-               ;     (wl-highlight-message (point-min)(point-max) t)
+;;;                 (wl-highlight-message (point-min)(point-max) t)
                     )))
             (wl-complete-window-delete))
            ((null completion)
@@ -457,9 +463,13 @@ Matched address lists are append to CL."
 (defvar wl-address-init-func 'wl-local-address-init)
 
 (defun wl-address-init ()
+  "Call `wl-address-init-func'."
   (funcall wl-address-init-func))
 
 (defun wl-local-address-init ()
+  "Reload `wl-address-file'.
+Refresh `wl-address-list', `wl-address-completion-list', and
+`wl-address-petname-hash'."
   (message "Updating addresses...")
   (setq wl-address-list
        (wl-address-make-address-list wl-address-file))
@@ -539,7 +549,7 @@ Matched address lists are append to CL."
            (forward-line))
          ret))))
 
-(defsubst wl-address-get-petname-1 (string)
+(defun wl-address-get-petname-1 (string)
   (let ((address (downcase (wl-address-header-extract-address string))))
     (elmo-get-hash-val address wl-address-petname-hash)))
 
@@ -556,7 +566,7 @@ Matched address lists are append to CL."
                      wl-from))))))
 
 (defsubst wl-address-header-extract-address (str)
-  "Extracts a real e-mail address from STR and returns it.
+  "Extracts a real e-mail address from STR and return it.
 e.g. \"Mine Sakurai <m-sakura@ccs.mt.nec.co.jp>\"
   ->  \"m-sakura@ccs.mt.nec.co.jp\".
 e.g. \"m-sakura@ccs.mt.nec.co.jp (Mine Sakurai)\"
@@ -568,7 +578,7 @@ e.g. \"m-sakura@ccs.mt.nec.co.jp (Mine Sakurai)\"
         (t str)))
 
 (defsubst wl-address-header-extract-realname (str)
-  "Extracts a real name from STR and returns it.
+  "Extracts a real name from STR and return it.
 e.g. \"Mr. bar <hoge@foo.com>\"
   ->  \"Mr. bar\"."
   (cond ((string-match "\\(.*[^ \t]\\)[ \t]*<[^>]*>" str)
@@ -587,7 +597,7 @@ e.g. \"Mr. bar <hoge@foo.com>\"
 (defun wl-address-string-without-group-list-contents (sequence)
   "Return address string from lexical analyzed list SEQUENCE.
 Group list contents is not included."
-  (let (address-string route-addr-end token seq)
+  (let (address-string route-addr-end token seq group-end)
   (while sequence
     (setq token (car sequence))
     (cond
@@ -597,10 +607,12 @@ Group list contents is not included."
       (setq address-string (concat address-string (cdr token))) ; ':'
       (setq seq (cdr sequence))
       (setq token (car seq))
-      (while (not (and (eq 'specials (car token))
-                      (string= (cdr token) ";")))
+      (setq group-end nil)
+      (while (not group-end)
        (setq token (car seq))
-       (setq seq (cdr seq)))
+       (setq seq (cdr seq))
+       (setq group-end (and (eq 'specials (car token))
+                            (string= (cdr token) ";"))))
       (setq address-string (concat address-string (cdr token))) ; ';'
       (setq sequence seq))
      ;;   route-addr  =  "<" [route] addr-spec ">"
@@ -619,7 +631,7 @@ Group list contents is not included."
   address-string))
 
 (defun wl-address-petname-delete (the-email)
-  "Delete petname in wl-address-file."
+  "Delete petname in `wl-address-file'."
   (let* ( (tmp-buf (get-buffer-create " *wl-petname-tmp*"))
          (output-coding-system
           (mime-charset-to-coding-system wl-mime-charset)))
@@ -638,7 +650,7 @@ Group list contents is not included."
                                         default-petname
                                         default-realname
                                         &optional change-petname)
-  "Add petname to wl-address-file, if not registerd.
+  "Add petname to `wl-address-file', if not registerd.
 If already registerd, change it."
   (let (the-realname the-petname)
 
@@ -652,8 +664,8 @@ If already registerd, change it."
     ;; setup output "realname"
     (setq the-realname
        (read-from-minibuffer (format "Real Name: ") default-realname))
-;;     (if (string= the-realname "")
-;;         (setq the-realname default-petname))
+;;;    (if (string= the-realname "")
+;;;        (setq the-realname default-petname))
 
     ;; writing to ~/.address
     (let ( (tmp-buf (get-buffer-create " *wl-petname-tmp*"))