1 ;;; wl-address.el --- Tiny address management for Wanderlust.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 1998,1999,2000 Shun-ichi GOTO <gotoh@taiyo.co.jp>
5 ;; Copyright (C) 1998,1999,2000 Takeshi Chiba <chiba@d3.bs1.fc.nec.co.jp>
7 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
8 ;; Shun-ichi GOTO <gotoh@taiyo.co.jp>
9 ;; Takeshi Chiba <chiba@d3.bs1.fc.nec.co.jp>
10 ;; Keywords: mail, net news
12 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
39 (eval-when-compile (require 'cl
))
41 (defvar wl-address-complete-header-list
42 '("To:" "From:" "Cc:" "Bcc:" "Mail-Followup-To:" "Reply-To:"
43 "Return-Receipt-To:"))
44 (defvar wl-address-complete-header-regexp nil
) ; auto-generated.
45 (defvar wl-newsgroups-complete-header-regexp
"^\\(Newsgroups\\|Followup-To\\):")
46 (defvar wl-folder-complete-header-regexp
"^\\(Fcc\\):")
47 (defvar wl-address-list nil
)
48 (defvar wl-address-completion-list nil
)
49 (defvar wl-address-petname-hash nil
)
50 (defvar wl-address-enable-strict-loading t
)
52 (defvar wl-address-ldap-search-hash nil
)
54 (eval-when-compile (require 'pldap
))
56 (defvar wl-ldap-alias-dn-level nil
57 "Level of dn data to make alias postfix.
58 Valid value is nit, t, 1 or larget integer.
60 If this value nil, minimum alias postfix is made depends on uniqness
61 with other candidates. In this implementation, it's same to 1. If t,
62 always append all dn data. If number, always append spcified level of
63 data but maybe appended more uniqness. If invalid value, treat as
66 For example, following dn data is exsist, alias of each level is shown
70 dn: CN=Shun-ichi GOTO,OU=Mew,OU=Emacs,OU=Lisper,O=Programmers Inc.
71 nil => Goto/Shun-ichi_GOTO
72 1 => Goto/Shun-ichi_GOTO
73 2 => Goto/Shun-ichi_GOTO/Mew
74 3 => Goto/Shun-ichi_GOTO/Mew/Emacs
75 4 => Goto/Shun-ichi_GOTO/Mew/Emacs/Lisper
76 5 => Goto/Shun-ichi_GOTO/Mew/Emacs/Lisper/Programmers_Inc_
77 6 => Goto/Shun-ichi_GOTO/Mew/Emacs/Lisper/Programmers_Inc_
78 t => Goto/Shun-ichi_GOTO/Mew/Emacs/Lisper/Programmers_Inc_
80 If level 3 is required for uniqness with other candidates,
81 nil => Goto/Shun-ichi_GOTO/Mew/Emacs ... appended more
82 1 => Goto/Shun-ichi_GOTO/Mew/Emacs ... appended more
83 2 => Goto/Shun-ichi_GOTO/Mew/Emacs ... appended more
84 3 => Goto/Shun-ichi_GOTO/Mew/Emacs
85 4 => Goto/Shun-ichi_GOTO/Mew/Emacs/Lisper
88 (defconst wl-ldap-alias-sep
"/")
90 (defconst wl-ldap-search-attribute-type-list
91 '("sn" "cn" "mail" "email"))
93 (defun wl-ldap-get-value (type entry
)
95 (let* ((values (cdr (assoc type entry
)))
97 (if (and ret
(not ldap-ignore-attribute-codings
))
99 (if (not (string-match "^[\000-\177]*$" (car values
)))
100 (setq ret
(car values
)
102 (setq values
(cdr values
)))))
105 (defun wl-ldap-get-value-list (type entry
)
107 (cdr (assoc type entry
)))
109 (defun wl-ldap-make-filter (pat type-list
)
110 "Make RFC1558 quiery filter for PAT from ATTR-LIST.
111 Each are \"OR\" combination, and PAT is beginning-match."
113 (mapconcat (lambda (x) (format "(%s=%s*)" x pat
)) ; fixed format
118 (defun wl-ldap-make-matched-value-list (regexp type-list entry
)
119 "Correct matching WORD with value of TYPE-LIST in ENTRY.
120 Returns matched uniq string list."
121 (let (type val values result
)
122 ;; collect matching value
124 (setq type
(car (car entry
))
125 values
(mapcar (function wl-ldap-alias-safe-string
)
127 values
(elmo-flatten values
)
129 (if (member type type-list
)
131 (setq val
(car values
)
133 (if (and (string-match regexp val
)
134 (not (member val result
)))
135 (setq result
(cons val result
))))))
138 (defun wl-ldap-alias-safe-string (str)
139 "Modify STR for alias.
140 Replace space/tab in STR into '_' char.
141 Replace '@' in STR into list of mailbox and sub-domains."
142 (while (string-match "[ \t]+" str
)
143 (setq str
(concat (substring str
0 (match-beginning 0))
145 (substring str
(match-end 0)))))
146 (if (string-match "\\(@\\)[^/@]+" str
)
147 (setq str
(split-string str
"[@\\.]")))
150 (defun wl-ldap-register-dn-string (hash dn
&optional str dn-list
)
152 (let (sym dnsym value level
)
153 (setq dnsym
(intern (upcase dn
) hash
))
154 (if (and (null str
) (boundp dnsym
))
155 () ; already processed
156 ;; make dn-list in fisrt time
158 (let ((case-fold-search t
))
159 (setq dn-list
(mapcar (lambda (str)
160 (if (string-match "[a-z]+=\\(.*\\)" str
)
161 (wl-ldap-alias-safe-string
162 (wl-match-string 1 str
))))
163 (split-string dn
"[ \t]*,[ \t]*")))))
164 (setq dn-list
(elmo-flatten dn-list
))
165 ;; prepare candidate for uniq str
167 (setq str
(concat str wl-ldap-alias-sep
(car dn-list
))
168 dn-list
(cdr dn-list
))
169 ;; first entry, pre-build with given level
171 ((null wl-ldap-alias-dn-level
) (setq level
1))
172 ((eq t wl-ldap-alias-dn-level
) (setq level
1000)) ; xxx, big enough
173 ((numberp wl-ldap-alias-dn-level
)
174 (if (< 0 wl-ldap-alias-dn-level
)
175 (setq level wl-ldap-alias-dn-level
)
179 (while (and (< 0 level
) dn-list
)
181 (setq str
(car dn-list
))
182 (setq str
(concat str wl-ldap-alias-sep
(car dn-list
))))
183 (setq level
(1- level
)
184 dn-list
(cdr dn-list
))))
185 (setq sym
(intern (upcase str
) hash
))
186 (if (not (boundp sym
))
188 (progn (set sym
(list dn str dn-list
))
191 (if (not (eq (setq value
(symbol-value sym
)) t
))
194 (apply (function wl-ldap-register-dn-string
) hash value
)))
195 (wl-ldap-register-dn-string hash dn str dn-list
)))))
197 (defun wl-address-ldap-search (pattern cl
)
198 "Make address completion-list matched for PATTERN by LDAP search.
199 Matched address lists are append to CL."
201 (unless wl-address-ldap-search-hash
202 (setq wl-address-ldap-search-hash
(elmo-make-hash 7)))
203 (let ((pat (if (string-match wl-ldap-alias-sep pattern
)
204 (substring pattern
0 (match-beginning 0))
206 (ldap-default-host (or wl-ldap-server ldap-default-host
"localhost"))
207 (ldap-default-port (or wl-ldap-port ldap-default-port
389))
208 (ldap-default-base (or wl-ldap-base ldap-default-base
))
209 (dnhash (elmo-make-hash))
210 cache len sym tmpl regexp entries ent values dn dnstr alias
213 (mapatoms (lambda (atom)
214 (if (and (string-match
215 (concat "^" (symbol-name atom
) ".*") pat
)
218 (setq len
(length (symbol-name atom
))))))
220 (or len
(length (symbol-name atom
)))
221 (symbol-value atom
)))))
222 wl-address-ldap-search-hash
)
223 ;; get matched entries
225 (setq entries
(cdr cache
))
227 (message "Searching in LDAP...")
228 (setq entries
(ldap-search-entries
230 pat wl-ldap-search-attribute-type-list
)
231 nil wl-ldap-search-attribute-type-list nil t
))
232 (message "Searching in LDAP...done")
233 (elmo-set-hash-val pattern entries wl-address-ldap-search-hash
)))
237 (wl-ldap-register-dn-string dnhash
(car (car tmpl
))) ; car is 'dn'.
238 (setq tmpl
(cdr tmpl
)))
240 (setq regexp
(concat "^" pat
))
242 (setq ent
(cdar entries
)
243 values
(wl-ldap-make-matched-value-list
244 regexp wl-ldap-search-attribute-type-list
246 mails
(or (wl-ldap-get-value-list "mail" ent
)
247 (wl-ldap-get-value-list "email" ent
))
248 cn
(wl-ldap-get-value "cn" ent
)
249 dn
(car (car entries
))
250 dnstr
(elmo-get-hash-val (upcase dn
) dnhash
))
251 ;; make alias list generated from LDAP data.
252 (while (and mails values
)
253 ;; make alias like MATCHED/DN-STRING
254 (if (not (string-match (concat "^" (regexp-quote (car values
))) dnstr
))
255 (setq alias
(concat (car values
) wl-ldap-alias-sep dnstr
))
256 ;; use DN-STRING if DN-STRING begin with MATCHED
258 ;; check uniqness then add to list
259 (setq sym
(intern (downcase alias
) dnhash
))
260 (when (not (boundp sym
))
262 (setq result
(cons (cons alias
263 (concat cn
" <" (car mails
) ">"))
265 (setq values
(cdr values
)))
266 ;; make mail addrses list
268 (if (null (assoc (car mails
) cl
)); Not already in cl.
269 ;; (string-match regexp (car mails))
270 ;; add mail address itself to completion list
271 (setq result
(cons (cons (car mails
)
272 (concat cn
" <" (car mails
) ">"))
274 (setq mails
(cdr mails
)))
275 (setq entries
(cdr entries
)))
278 (defun wl-complete-address (string predicate flag
)
279 "Completion function for completing-read (comma separated addresses)."
280 (if (string-match "^\\(.*,\\)\\(.*\\)$" string
)
281 (let* ((str1 (match-string 1 string
))
282 (str2 (match-string 2 string
))
283 (str2-comp (wl-complete-address str2 predicate flag
)))
284 (if (and (not flag
) (stringp str2-comp
))
285 (concat str1 str2-comp
)
288 (try-completion string wl-address-list
)
289 (all-completions string wl-address-list
))))
291 (defalias 'wl-address-quote-specials
'elmo-address-quote-specials
)
293 (defun wl-address-make-completion-list (address-list)
296 (setq addr-tuple
(car address-list
))
299 (wl-address-make-completion-entry 0 addr-tuple
)
301 ;; nickname completion.
302 (if wl-address-enable-strict-loading
303 (unless (or (equal (nth 1 addr-tuple
) (nth 0 addr-tuple
))
305 (assoc (nth 1 addr-tuple
) cl
))
308 (wl-address-make-completion-entry 1 addr-tuple
)
312 (wl-address-make-completion-entry 1 addr-tuple
)
314 (setq address-list
(cdr address-list
)))
317 (defun wl-address-make-completion-entry (index addr-tuple
)
318 (cons (nth index addr-tuple
)
319 (if (or (string= (nth 2 addr-tuple
) "")
320 (string-match ".*:.*;$" (nth 0 addr-tuple
)))
323 (wl-address-quote-specials
324 (nth 2 addr-tuple
)) " <"(nth 0 addr-tuple
)">"))))
326 (defun wl-complete-field-body-or-tab ()
328 (let ((case-fold-search t
)
329 epand-char skip-chars
332 (if (wl-draft-on-field-p)
337 (goto-char (point-min))
338 (search-forward (concat "\n" mail-header-separator
"\n") nil
0)
343 (while (and (looking-at "^[ \t]")
344 (not (= (point) (point-min))))
346 (cond ((looking-at wl-address-complete-header-regexp
)
347 (setq completion-list wl-address-completion-list
)
350 (setq epand-char ?
@))
351 ((looking-at wl-folder-complete-header-regexp
)
352 (setq completion-list wl-folder-entity-hashtb
)
353 (setq skip-chars
"^, "))
354 ((looking-at wl-newsgroups-complete-header-regexp
)
355 (setq completion-list wl-folder-newsgroups-hashtb
)))))
356 (wl-complete-field-body completion-list
357 epand-char skip-chars use-ldap
)
358 (indent-for-tab-command)))))
360 (defvar wl-completion-buf-name
"*Completions*")
362 (defvar wl-complete-candidates nil
)
364 (defun wl-complete-window-show (all)
365 (if (and (get-buffer-window wl-completion-buf-name
)
366 (equal wl-complete-candidates all
))
367 (let ((win (get-buffer-window wl-completion-buf-name
)))
369 (set-buffer wl-completion-buf-name
)
370 (if (pos-visible-in-window-p (point-max) win
)
371 (set-window-start win
1)
372 (scroll-other-window))))
373 (message "Making completion list...")
374 (setq wl-complete-candidates all
)
375 (with-output-to-temp-buffer
376 wl-completion-buf-name
377 (display-completion-list all
))
378 (message "Making completion list...done")))
380 (defun wl-complete-window-delete ()
381 (let (comp-buf comp-win
)
382 (if (setq comp-buf
(get-buffer wl-completion-buf-name
))
383 (if (setq comp-win
(get-buffer-window comp-buf
))
384 (delete-window comp-win
)))))
386 (defun wl-complete-field ()
389 (start (save-excursion
390 (skip-chars-backward "_a-zA-Z0-9+@%.!\\-")
393 (pattern (buffer-substring start end
))
394 (cl wl-draft-field-completion-list
))
398 (let ((completion-ignore-case t
))
399 (try-completion pattern cl
)))
400 (cond ((eq completion t
)
401 (let ((alias (assoc pattern cl
)))
404 (delete-region start end
)
406 ;;; (wl-highlight-message (point-min)(point-max) t)
408 (wl-complete-window-delete))
410 (message "Can't find completion for \"%s\"" pattern
)
412 ((not (string= pattern completion
))
413 (delete-region start end
)
415 (wl-complete-window-delete)
416 (wl-highlight-message (point-min)(point-max) t
))
418 (let ((list (all-completions pattern cl
)))
419 (wl-complete-window-show list
)))))))
421 (defun wl-complete-insert (start end pattern completion-list
)
422 (let ((alias (and (consp completion-list
)
423 (assoc pattern completion-list
)))
427 (delete-region start end
)
429 (if (setq comp-buf
(get-buffer wl-completion-buf-name
))
430 (if (setq comp-win
(get-buffer-window comp-buf
))
431 (delete-window comp-win
)))))))
433 (defun wl-complete-field-body (completion-list
434 &optional epand-char skip-chars use-ldap
)
437 (start (save-excursion
438 (skip-chars-backward (or skip-chars
"^:,>\n"))
439 (skip-chars-forward " \t")
442 (pattern (buffer-substring start end
))
443 (len (length pattern
))
444 (completion-ignore-case t
)
445 (cl completion-list
))
447 (setq cl
(wl-address-ldap-search pattern cl
)))
450 (setq completion
(try-completion pattern cl
))
451 (cond ((eq completion t
)
452 (if use-ldap
(setq wl-address-ldap-search-hash nil
))
453 (wl-complete-insert start end pattern cl
)
454 (wl-complete-window-delete)
455 (message "Sole completion"))
458 (or (char-equal (aref pattern
(1- len
)) epand-char
)
459 (char-equal (aref pattern
(1- len
)) ?\
))
460 (assoc (substring pattern
0 (1- len
)) cl
))
463 (substring pattern
0 (1- len
))
466 (message "Can't find completion for \"%s\"" pattern
)
468 ((not (string= pattern completion
))
469 (delete-region start end
)
472 (let ((list (sort (all-completions pattern cl
) 'string
<)))
473 (wl-complete-window-show list
)))))))
475 (defvar wl-address-init-function
'wl-local-address-init
)
477 (defun wl-address-init ()
478 "Call `wl-address-init-function'."
479 (funcall wl-address-init-function
))
481 (defun wl-local-address-init ()
482 "Reload `wl-address-file'.
483 Refresh `wl-address-list', `wl-address-completion-list', and
484 `wl-address-petname-hash'."
485 (message "Updating addresses...")
486 (setq wl-address-list
487 (wl-address-make-address-list wl-address-file
))
488 (setq wl-address-completion-list
489 (wl-address-make-completion-list wl-address-list
))
490 (if (file-readable-p wl-alias-file
)
491 (setq wl-address-completion-list
492 (append wl-address-completion-list
493 (wl-address-make-alist-from-alias-file wl-alias-file
))))
494 (setq wl-address-petname-hash
(elmo-make-hash))
495 (let ((addresses wl-address-list
))
497 (elmo-set-hash-val (downcase (car (car addresses
)))
498 (cadr (car addresses
))
499 wl-address-petname-hash
)
500 (setq addresses
(cdr addresses
))))
501 (message "Updating addresses...done"))
504 (defun wl-address-expand-aliases (alist nest-count
)
505 (when (< nest-count
5)
506 (let (expn-str new-expn-str expn new-expn
(n 0) (expanded nil
))
507 (while (setq expn-str
(cdr (nth n alist
)))
508 (setq new-expn-str nil
)
509 (while (string-match "^[ \t]*\\([^,]+\\)" expn-str
)
510 (setq expn
(elmo-match-string 1 expn-str
))
511 (setq expn-str
(wl-string-delete-match expn-str
0))
512 (if (string-match "^[ \t,]+" expn-str
)
513 (setq expn-str
(wl-string-delete-match expn-str
0)))
514 (if (string-match "[ \t,]+$" expn
)
515 (setq expn
(wl-string-delete-match expn
0)))
516 (setq new-expn
(cdr (assoc expn alist
)))
519 (setq new-expn-str
(concat new-expn-str
(and new-expn-str
", ")
520 (or new-expn expn
))))
522 (setcdr (nth n alist
) new-expn-str
))
525 (wl-address-expand-aliases alist
(1+ nest-count
))))))
527 (defun wl-address-make-alist-from-alias-file (file)
529 (let ((case-fold-search t
)
531 (insert-file-contents file
)
532 (while (re-search-forward ",$" nil t
)
535 (delete-backward-char 1))
536 (goto-char (point-min))
537 (while (re-search-forward "^\\([^#;\n][^:]+\\):[ \t]*\\(.*\\)$" nil t
)
538 (setq alias
(wl-match-buffer 1)
539 expn
(wl-match-buffer 2))
540 (setq alist
(cons (cons alias expn
) alist
)))
541 (wl-address-expand-aliases alist
0)
542 (nreverse alist
) ; return value
545 (defun wl-address-make-address-list (path)
546 (when (and path
(file-readable-p path
))
549 (coding-system-for-read wl-cs-autoconv
))
550 (insert-file-contents path
)
551 (goto-char (point-min))
554 ^\\([^#\n][^ \t\n]+\\)[ \t]+\\(\".*\"\\)[ \t]+\\(\".*\"\\)[ \t]*.*$")
557 (list (wl-match-buffer 1)
558 (read (wl-match-buffer 2))
559 (read (wl-match-buffer 3)))
565 (defsubst wl-address-header-extract-address
(str)
566 "Extracts a real e-mail address from STR and return it.
567 e.g. \"Mine Sakurai <m-sakura@ccs.mt.nec.co.jp>\"
568 -> \"m-sakura@ccs.mt.nec.co.jp\".
569 e.g. \"m-sakura@ccs.mt.nec.co.jp (Mine Sakurai)\"
570 -> \"m-sakura@ccs.mt.nec.co.jp\"."
571 (cond ((string-match ".*<\\([^>]*\\)>" str
) ; .* to extract last <>
572 (wl-match-string 1 str
))
573 ((string-match "\\([^ \t\n]*@[^ \t\n]*\\)" str
)
574 (wl-match-string 1 str
))
577 (defsubst wl-address-header-extract-realname
(str)
578 "Extracts a real name from STR and return it.
579 e.g. \"Mr. bar <hoge@foo.com>\"
581 (cond ((string-match "\\(.*[^ \t]\\)[ \t]*<[^>]*>" str
)
582 (wl-match-string 1 str
))
586 (defun wl-address-get-petname-1 (string)
587 (let ((address (downcase (wl-address-header-extract-address string
))))
588 (elmo-get-hash-val address wl-address-petname-hash
)))
590 (defsubst wl-address-get-petname
(string)
591 (or (wl-address-get-petname-1 string
)
594 (defun wl-address-user-mail-address-p (address)
595 "Judge whether ADDRESS is user's or not."
596 (if wl-user-mail-address-regexp
597 (string-match wl-user-mail-address-regexp
598 (wl-address-header-extract-address address
))
599 (member (downcase (wl-address-header-extract-address address
))
600 (or (mapcar 'downcase wl-user-mail-address-list
)
602 (wl-address-header-extract-address
605 (defun wl-address-delete-user-mail-addresses (address-list)
606 "Delete user mail addresses from list by side effect.
607 Deletion is done by using `elmo-list-delete'."
608 (if wl-user-mail-address-regexp
609 (elmo-list-delete (list wl-user-mail-address-regexp
) address-list
612 (lambda (item) (string-match elem item
))
614 (let ((myself (or wl-user-mail-address-list
615 (list (wl-address-header-extract-address wl-from
)))))
616 (elmo-list-delete myself address-list
619 (lambda (item) (string= (downcase elem
)
623 (defmacro wl-address-concat-token
(string token
)
625 ((eq 'quoted-string
(car ,token
))
626 (concat ,string
"\"" (cdr ,token
) "\""))
627 ((eq 'comment
(car ,token
))
628 (concat ,string
"(" (cdr ,token
) ")"))
630 (concat ,string
(cdr ,token
)))))
632 (defun wl-address-string-without-group-list-contents (sequence)
633 "Return address string from lexical analyzed list SEQUENCE.
634 Group list contents is not included."
635 (let (address-string route-addr-end token seq group-end
)
637 (setq token
(car sequence
))
639 ;; group = phrase ":" [#mailbox] ";"
640 ((and (eq 'specials
(car token
))
641 (string= (cdr token
) ":"))
642 (setq address-string
(concat address-string
(cdr token
))) ; ':'
643 (setq seq
(cdr sequence
))
644 (setq token
(car seq
))
646 (while (not group-end
)
647 (setq token
(car seq
))
649 (setq group-end
(and (eq 'specials
(car token
))
650 (string= (cdr token
) ";"))))
651 (setq address-string
(concat address-string
(cdr token
))) ; ';'
653 ;; route-addr = "<" [route] addr-spec ">"
654 ;; route = 1#("@" domain) ":" ; path-relative
655 ((and (eq 'specials
(car token
))
656 (string= (cdr token
) "<"))
657 (setq seq
(std11-parse-route-addr sequence
))
658 (setq route-addr-end
(car (cdr seq
)))
659 (while (not (eq (car sequence
) route-addr-end
))
660 (setq address-string
(wl-address-concat-token address-string
662 (setq sequence
(cdr sequence
))))
664 (setq address-string
(wl-address-concat-token address-string token
))
665 (setq sequence
(cdr sequence
)))))
668 (defun wl-address-delete (the-email)
669 "Delete address entry in the `wl-address-file'."
670 (let ((output-coding-system
671 (mime-charset-to-coding-system wl-mime-charset
)))
673 (message "Deleting Address...")
674 (insert-file-contents wl-address-file
)
675 (delete-matching-lines (concat "^[ \t]*" the-email
"[ \t]+\".*\"[ \t]+\".*\"$"))
676 (write-region (point-min) (point-max)
677 wl-address-file nil
'no-msg
)
679 (dolist (entry (elmo-string-assoc-all the-email wl-address-list
))
680 (setq wl-address-list
(delete entry wl-address-list
)))
681 (elmo-set-hash-val the-email nil wl-address-petname-hash
)
682 (message "Deleting Address...done"))))
684 (defun wl-address-add-or-change (address
685 &optional default-realname
687 "Add address entry to `wl-address-file', if not registerd.
688 If already registerd, change it."
689 (let ((entry (assoc address wl-address-list
))
690 the-realname the-petname new-addr addr-changed
)
692 (read-from-minibuffer "Real Name: " (or default-realname
694 (setq the-petname
(read-from-minibuffer "Petname: "
698 (setq new-addr
(read-from-minibuffer "E-Mail: " address
))
700 ((or (not (stringp new-addr
))
701 (string-match "^[ \t]*$" new-addr
))
702 (error "empty address"))
703 ((and (not (string= address new-addr
))
704 (assoc new-addr wl-address-list
))
705 (error "'%s' already exists" new-addr
))
709 ;; writing to ~/.address
710 (let ((output-coding-system
711 (mime-charset-to-coding-system wl-mime-charset
)))
713 (if (file-exists-p wl-address-file
)
714 (insert-file-contents wl-address-file
))
718 (goto-char (point-max))
719 (if (and (> (buffer-size) 0)
720 (not (eq (char-after (1- (point-max))) ?
\n)))
723 (while (re-search-forward (concat "^[ \t]*" address
) nil t
)
724 (delete-region (save-excursion (beginning-of-line)
726 (save-excursion (end-of-line)
728 (insert (format "%s\t%s\t%s\n"
729 (or new-addr address
)
730 (prin1-to-string the-petname
)
731 (prin1-to-string the-realname
)))
732 (write-region (point-min) (point-max)
733 wl-address-file nil
'no-msg
)
735 (list (or new-addr address
) the-petname the-realname
)))))
737 ;; Read addresses from minibuffer with completion.
738 (defvar wl-address-minibuffer-history nil
)
739 (defvar wl-address-minibuffer-local-map nil
740 "Keymap to use when reading address from the minibuffer.")
742 (unless wl-address-minibuffer-local-map
743 (let ((map (make-sparse-keymap)))
744 (set-keymap-parent map minibuffer-local-map
)
745 (define-key map
"\C-i"
748 (wl-complete-field-body wl-address-completion-list
749 ?
@ nil wl-use-ldap
)))
750 (setq wl-address-minibuffer-local-map map
)))
752 (defun wl-address-read-from-minibuffer (prompt &optional
755 (read-from-minibuffer prompt
757 wl-address-minibuffer-local-map
759 'wl-address-minibuffer-history
763 (product-provide (provide 'wl-address
) (require 'wl-version
))
765 ;;; wl-address.el ends here