1 ;;; elmo-util.el -- Utilities for Elmo.
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7 ;; Time-stamp: <2000-03-29 09:42:41 teranisi>
9 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
35 (eval-when-compile (require 'cl))
37 (require 'eword-decode)
46 (defun-maybe starttls-negotiate (a))
47 (defun-maybe starttls-open-stream (a b c d))
48 (defun-maybe open-ssl-stream (a b c d)))
50 (defmacro elmo-set-buffer-multibyte (flag)
51 "Set the multibyte flag of the current buffer to FLAG."
53 (list 'setq 'mc-flag flag))
56 ((and (boundp 'emacs-major-version) (>= emacs-major-version 20))
57 (list 'set-buffer-multibyte flag))
61 (defvar elmo-work-buf-name " *elmo work*")
62 (defvar elmo-temp-buf-name " *elmo temp*")
64 (or (boundp 'default-enable-multibyte-characters)
65 (defvar default-enable-multibyte-characters (featurep 'mule)
66 "The mock variable except for Emacs 20."))
68 (defun elmo-base64-encode-string (string &optional no-line-break))
69 (defun elmo-base64-decode-string (string))
71 ;; base64 encoding/decoding
73 (fset 'elmo-base64-encode-string
74 (mel-find-function 'mime-encode-string "base64"))
75 (fset 'elmo-base64-decode-string
76 (mel-find-function 'mime-decode-string "base64"))
78 ;; Any Emacsen may have add-name-to-file(), because loadup.el requires it. :-p
79 ;; Check make-symbolic-link() instead. -- 981002 by Fuji
80 (if (fboundp 'make-symbolic-link) ;; xxx
81 (defalias 'elmo-add-name-to-file 'add-name-to-file)
82 (defun elmo-add-name-to-file
83 (filename newname &optional ok-if-already-exists)
84 (copy-file filename newname ok-if-already-exists t)))
87 (broken-facility timezone-y2k
88 "timezone.el does not clear Y2K."
89 (or (not (featurep 'timezone))
90 (string= (aref (timezone-parse-date "Sat, 1 Jan 00 07:00:00 JST") 0)
93 (when-broken timezone-y2k
94 (defun timezone-parse-date (date)
95 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE].
96 19 is prepended to year if necessary. Timezone may be nil if nothing.
97 Understands the following styles:
98 (1) 14 Apr 89 03:20[:12] [GMT]
99 (2) Fri, 17 Mar 89 4:01[:33] [GMT]
100 (3) Mon Jan 16 16:12[:37] [GMT] 1989
101 (4) 6 May 1992 1641-JST (Wednesday)
102 (5) 22-AUG-1993 10:59:12.82
103 (6) Thu, 11 Apr 16:17:12 91 [MET]
104 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]"
107 ;; Get rid of any text properties.
109 (or (text-properties-at 0 date)
110 (next-property-change 0 date))
111 (setq date (copy-sequence date))
112 (set-text-properties 0 (length date) nil date))
113 (let ((date (or date ""))
118 (zone nil)) ;This may be nil.
120 "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\'" date)
121 ;; Styles: (6) and (7) without timezone
122 (setq year 6 month 3 day 2 time 4 zone nil))
124 "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
125 ;; Styles: (6) and (7) with timezone and buggy timezone
126 (setq year 6 month 3 day 2 time 4 zone 7))
128 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\'" date)
129 ;; Styles: (1) and (2) without timezone
130 (setq year 3 month 2 day 1 time 4 zone nil))
132 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
133 ;; Styles: (1) and (2) with timezone and buggy timezone
134 (setq year 3 month 2 day 1 time 4 zone 5))
136 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([0-9]+\\)" date)
137 ;; Styles: (3) without timezone
138 (setq year 4 month 1 day 2 time 3 zone nil))
140 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([-+a-zA-Z0-9]+\\)[ \t]+\\([0-9]+\\)" date)
141 ;; Styles: (3) with timezone
142 (setq year 5 month 1 day 2 time 3 zone 4))
144 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
145 ;; Styles: (4) with timezone
146 (setq year 3 month 2 day 1 time 4 zone 5))
148 "\\([0-9]+\\)-\\([A-Za-z]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)\\.[0-9]+" date)
149 ;; Styles: (5) without timezone.
150 (setq year 3 month 2 day 1 time 4 zone nil))
155 (substring date (match-beginning year)
157 (if (< (length year) 4)
158 (let ((yr (string-to-int year)))
160 (setq yr (- yr 100)))
161 (setq year (format "%d%02d"
166 (let ((string (substring date
167 (match-beginning month)
168 (+ (match-beginning month) 3))))
171 (cdr (assoc (upcase string)
172 timezone-months-assoc)))))
174 (substring date (match-beginning day) (match-end day)))
176 (substring date (match-beginning time)
180 (substring date (match-beginning zone)
183 (vector year month day time zone)
184 (vector "0" "0" "0" "0" nil))
187 (t (signal 'invalid-date (list date))))))
189 (defsubst elmo-call-func (folder func-name &rest args)
190 (let* ((spec (if (stringp folder)
191 (elmo-folder-get-spec folder)
193 (type (symbol-name (car spec)))
194 (backend-str (concat "elmo-" type))
195 (backend-sym (intern backend-str)))
196 (unless (featurep backend-sym)
197 (require backend-sym))
198 (apply (intern (format "%s-%s" backend-str func-name))
202 (defmacro elmo-set-work-buf (&rest body)
203 "Execute BODY on work buffer. Work buffer remains."
205 (set-buffer (get-buffer-create elmo-work-buf-name))
206 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
210 (defmacro elmo-match-substring (pos string from)
211 "Substring of POSth matched string of STRING. "
212 (` (substring (, string)
213 (+ (match-beginning (, pos)) (, from))
214 (match-end (, pos)))))
216 (defmacro elmo-match-string (pos string)
217 "Substring POSth matched string."
218 (` (substring (, string) (match-beginning (, pos)) (match-end (, pos)))))
220 (defmacro elmo-match-buffer (pos)
221 "Substring POSth matched from the current buffer."
222 (` (buffer-substring-no-properties
223 (match-beginning (, pos)) (match-end (, pos)))))
225 (defmacro elmo-bind-directory (dir &rest body)
226 "Set current directory DIR and execute BODY."
227 (` (let ((default-directory (file-name-as-directory (, dir))))
230 (defmacro elmo-folder-get-type (folder)
231 "Get type of FOLDER."
232 (` (and (stringp (, folder))
233 (cdr (assoc (string-to-char (, folder)) elmo-spec-alist)))))
235 (defun elmo-object-load (filename &optional mime-charset no-err)
236 "Load OBJECT from the file specified by FILENAME.
237 File content is decoded with MIME-CHARSET."
238 (if (not (file-readable-p filename))
241 (as-binary-input-file
242 (insert-file-contents filename))
244 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
245 (decode-mime-charset-region (point-min) (point-max) mime-charset))
247 (read (current-buffer))
248 (error (unless no-err
249 (message "Warning: Loading object from %s failed."
251 (elmo-object-save filename nil))
254 (defsubst elmo-save-buffer (filename &optional mime-charset)
255 "Save current buffer to the file specified by FILENAME.
256 Directory of the file is created if it doesn't exist.
257 File content is encoded with MIME-CHARSET."
258 (let ((dir (directory-file-name (file-name-directory filename))))
259 (if (file-directory-p dir)
261 (unless (file-exists-p dir)
262 (elmo-make-directory dir)))
263 (if (file-writable-p filename)
266 ;;(elmo-set-buffer-multibyte default-enable-multibyte-characters)
267 (encode-mime-charset-region (point-min) (point-max) mime-charset))
268 (as-binary-output-file
269 (write-region (point-min) (point-max) filename nil 'no-msg)))
270 (message (format "%s is not writable." filename)))))
272 (defun elmo-object-save (filename object &optional mime-charset)
273 "Save OBJECT to the file specified by FILENAME.
274 Directory of the file is created if it doesn't exist.
275 File content is encoded with MIME-CHARSET."
277 (prin1 object (current-buffer))
278 ;;(princ "\n" (current-buffer))
279 (elmo-save-buffer filename mime-charset)))
281 (defsubst elmo-imap4-decode-folder-string (string)
282 (if elmo-imap4-use-modified-utf7
283 (utf7-decode-string string 'imap)
286 (defsubst elmo-imap4-encode-folder-string (string)
287 (if elmo-imap4-use-modified-utf7
288 (utf7-encode-string string 'imap)
291 (defun elmo-network-get-spec (folder default-server default-port default-tls)
292 (let (server port tls)
293 (if (string-match "\\(@[^@:/!]+\\)?\\(:[0-9]+\\)?\\(!*\\)$" folder)
295 (if (match-beginning 1)
296 (setq server (elmo-match-substring 1 folder 1))
297 (setq server default-server))
298 (if (match-beginning 2)
300 (string-to-int (elmo-match-substring 2 folder 1)))
301 (setq port default-port))
302 (setq tls (elmo-match-string 3 folder))
303 (if (and (match-beginning 3)
305 (setq tls (if (= 2 (length tls)) 'starttls
307 (setq tls default-tls))
308 (setq folder (substring folder 0 (match-beginning 0))))
309 (setq server default-server
312 (cons folder (list server port tls))))
314 (defun elmo-imap4-get-spec (folder)
315 (let ((default-user elmo-default-imap4-user)
316 (default-server elmo-default-imap4-server)
317 (default-port elmo-default-imap4-port)
318 (default-tls elmo-default-imap4-ssl)
319 spec mailbox user auth)
320 (when (string-match "\\(.*\\)@\\(.*\\)" default-server)
321 ;; case: default-imap4-server is specified like
322 ;; "hoge%imap.server@gateway".
323 (setq default-user (elmo-match-string 1 default-server))
324 (setq default-server (elmo-match-string 2 default-server)))
325 (setq spec (elmo-network-get-spec
326 folder default-server default-port default-tls))
327 (setq folder (car spec))
329 "^\\(%\\)\\([^:@!]*\\)\\(:[^/!]+\\)?\\(/[^/:@!]+\\)?"
332 (setq mailbox (if (match-beginning 2)
333 (elmo-match-string 2 folder)
334 elmo-default-imap4-mailbox))
335 (setq user (if (match-beginning 3)
336 (elmo-match-substring 3 folder 1)
338 (setq auth (if (match-beginning 4)
339 (elmo-match-substring 4 folder 1)
340 elmo-default-imap4-authenticate-type))
342 (elmo-imap4-encode-folder-string mailbox)
346 (defsubst elmo-imap4-spec-mailbox (spec)
349 (defsubst elmo-imap4-spec-username (spec)
352 (defsubst elmo-imap4-spec-auth (spec)
355 (defsubst elmo-imap4-spec-hostname (spec)
358 (defsubst elmo-imap4-spec-port (spec)
361 (defsubst elmo-imap4-spec-ssl (spec)
364 (defsubst elmo-imap4-spec-folder (spec) ;; obsolete
367 (defsubst elmo-imap4-connection-get-process (conn)
370 (defsubst elmo-imap4-connection-get-buffer (conn)
373 (defsubst elmo-imap4-connection-get-cwf (conn)
376 (defun elmo-nntp-get-spec (folder)
377 (let (spec group user)
378 (setq spec (elmo-network-get-spec folder
379 elmo-default-nntp-server
380 elmo-default-nntp-port
381 elmo-default-nntp-ssl))
382 (setq folder (car spec))
384 "^\\(-\\)\\([^:@!]*\\)\\(:[^/!]+\\)?\\(/[^/:@!]+\\)?"
387 (if (match-beginning 2)
388 (elmo-match-string 2 folder)))
390 (if (match-beginning 3)
391 (elmo-match-substring 3 folder 1)
392 elmo-default-nntp-user))
393 (append (list 'nntp group user)
396 (defsubst elmo-nntp-spec-group (spec)
399 (defsubst elmo-nntp-spec-username (spec)
403 ;; (defsubst elmo-nntp-spec-auth (spec))
405 (defsubst elmo-nntp-spec-hostname (spec)
408 (defsubst elmo-nntp-spec-port (spec)
411 (defsubst elmo-nntp-spec-ssl (spec)
414 (defun elmo-localdir-get-spec (folder)
417 "^\\(\\+\\)\\(.*\\)$"
419 (if (eq (length (setq fld-name
420 (elmo-match-string 2 folder))) 0)
423 (if (file-name-absolute-p fld-name)
424 (setq path (expand-file-name fld-name))
425 (setq path fld-name))
426 ;(setq path (expand-file-name fld-name
427 ;elmo-localdir-folder-path)))
428 (list (if (elmo-folder-maildir-p folder)
432 (defun elmo-maildir-get-spec (folder)
435 "^\\(\\.\\)\\(.*\\)$"
437 (if (eq (length (setq fld-name
438 (elmo-match-string 2 folder))) 0)
440 (if (file-name-absolute-p fld-name)
441 (setq path (expand-file-name fld-name))
442 (setq path fld-name))
443 (list 'maildir path))))
445 (defun elmo-folder-maildir-p (folder)
447 (let ((li elmo-maildir-list))
449 (if (string-match (car li) folder)
451 (setq li (cdr li))))))
453 (defun elmo-localnews-get-spec (folder)
458 (if (eq (length (setq fld-name
459 (elmo-match-string 2 folder))) 0)
463 (elmo-replace-in-string fld-name "\\." "/")))))
465 (defun elmo-cache-get-spec (folder)
470 (if (eq (length (setq fld-name
471 (elmo-match-string 2 folder))) 0)
475 (elmo-replace-in-string fld-name "\\." "/")))))
477 ;; Archive interface by OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
478 (defun elmo-archive-get-spec (folder)
479 (require 'elmo-archive)
480 (let (fld-name type prefix)
482 "^\\(\\$\\)\\([^;]*\\);?\\([^;]*\\);?\\([^;]*\\)$"
484 ;; Drive letter is OK!
485 (if (eq (length (setq fld-name
486 (elmo-match-string 2 folder))) 0)
489 (if (eq (length (setq type
490 (elmo-match-string 3 folder))) 0)
491 (setq type (symbol-name elmo-archive-default-type)))
492 (if (eq (length (setq prefix
493 (elmo-match-string 4 folder))) 0)
495 (list 'archive fld-name (intern-soft type) prefix))))
497 (defun elmo-pop3-get-spec (folder)
498 (let (spec user auth)
499 (setq spec (elmo-network-get-spec folder
500 elmo-default-pop3-server
501 elmo-default-pop3-port
502 elmo-default-pop3-ssl))
503 (setq folder (car spec))
505 "^\\(&\\)\\([^:/!]*\\)\\(/[^/:@!]+\\)?"
507 (setq user (if (match-beginning 2)
508 (elmo-match-string 2 folder)))
509 (if (eq (length user) 0)
510 (setq user elmo-default-pop3-user))
511 (setq auth (if (match-beginning 3)
512 (elmo-match-substring 3 folder 1)
513 elmo-default-pop3-authenticate-type))
514 (append (list 'pop3 user auth)
517 (defsubst elmo-pop3-spec-username (spec)
520 (defsubst elmo-pop3-spec-auth (spec)
523 (defsubst elmo-pop3-spec-hostname (spec)
526 (defsubst elmo-pop3-spec-port (spec)
529 (defsubst elmo-pop3-spec-ssl (spec)
532 (defun elmo-internal-get-spec (folder)
533 (if (string-match "\\('\\)\\([^/]*\\)/?\\(.*\\)$" folder)
534 (let* ((item (downcase (elmo-match-string 2 folder)))
535 (sym (and (> (length item) 0) (intern item))))
536 (cond ((or (null sym)
538 (list 'internal sym (elmo-match-string 3 folder)))
540 (list 'cache (elmo-match-string 3 folder)))
541 (t (error "Invalid internal folder spec"))))))
543 (defun elmo-multi-get-spec (folder)
546 "^\\(\\*\\)\\(.*\\)$"
548 (append (list 'multi)
550 (elmo-match-string 2 folder)
553 (defun elmo-filter-get-spec (folder)
558 (let ((spec (elmo-match-string 2 folder))
560 (when (string-match "\\([^/]+\\)/" spec)
561 (setq filter (elmo-match-string 1 spec))
562 (setq spec (substring spec (match-end 0))))
564 ((string-match "^\\(last\\|first\\):\\(.*\\)$" filter) ; partial
565 (setq filter (vector 'partial
566 (elmo-match-string 1 filter)
567 (elmo-match-string 2 filter))))
569 (setq filter (elmo-parse-search-condition filter))))
570 (list 'filter filter spec)))))
572 (defun elmo-pipe-get-spec (folder)
573 (when (string-match "^\\(|\\)\\([^|]*\\)|\\(.*\\)$" folder)
575 (elmo-match-string 2 folder)
576 (elmo-match-string 3 folder))))
578 (defun elmo-folder-get-spec (folder)
579 "return spec of folder"
580 (let ((type (elmo-folder-get-type folder)))
582 (funcall (intern (concat "elmo-" (symbol-name type) "-get-spec"))
584 (error "%s is not supported folder type" folder))))
586 (defun elmo-parse-search-condition (condition)
587 (let ((terms (split-string condition "|")) ; split by OR
590 (setq term (car terms))
592 ((string-match "^\\([a-zA-Z\\-]+\\)=\\(.*\\)$" term)
594 (string-match "tocc" (elmo-match-string 1 term))) ;; syntax sugar
597 (list (vector 'match "to"
598 (elmo-match-string 2 term))
600 (elmo-match-string 2 term)))))
601 (setq ret-val (cons (vector 'match
602 (elmo-match-string 1 term)
603 (elmo-match-string 2 term))
605 ((string-match "^\\([a-zA-Z\\-]+\\)!=\\(.*\\)$" term)
607 (string-match "tocc" (elmo-match-string 1 term))) ;; syntax sugar
610 (list (vector 'unmatch "to"
611 (elmo-match-string 2 term))
612 (vector 'unmatch "cc"
613 (elmo-match-string 2 term)))))
614 (setq ret-val (cons (vector 'unmatch
615 (elmo-match-string 1 term)
616 (elmo-match-string 2 term))
618 ((string-match "^\\(since\\|before\\):\\(.*\\)$" term)
619 (setq ret-val (cons (vector 'date
620 (elmo-match-string 1 term)
621 (elmo-match-string 2 term))
623 (setq terms (cdr terms)))
626 (defun elmo-multi-get-real-folder-number (folder number)
627 (let* ((spec (elmo-folder-get-spec folder))
630 (fld (nth (- (/ num elmo-multi-divide-number) 1) flds)))
631 (cons fld (% num elmo-multi-divide-number))))
633 (defsubst elmo-buffer-replace (regexp &optional newtext)
634 (goto-char (point-min))
635 (while (re-search-forward regexp nil t)
636 (replace-match (or newtext ""))))
638 (defsubst elmo-delete-char (char string &optional unibyte)
641 (let ((coding-system-for-read 'no-conversion)
642 (coding-system-for-write 'no-conversion))
643 (if unibyte (elmo-set-buffer-multibyte nil))
645 (goto-char (point-min))
646 (while (search-forward (char-to-string char) nil t)
650 (defsubst elmo-delete-cr-get-content-type ()
652 (goto-char (point-min))
653 (while (search-forward "\r\n" nil t)
654 (replace-match "\n"))
655 (goto-char (point-min))
656 (or (std11-field-body "content-type")
659 (defun elmo-delete-cr (string)
663 (goto-char (point-min))
664 (while (search-forward "\r\n" nil t)
665 (replace-match "\n"))
668 (defun elmo-uniq-list (lst)
669 "Distractively uniqfy elements of LST."
671 (while tmp (setq tmp (setcdr tmp (and (cdr tmp) (delete (car tmp) (cdr tmp)))))))
674 (defun elmo-string-partial-p (string)
675 (and (stringp string) (string-match "message/partial" string)))
677 (defun elmo-get-file-string (filename &optional remove-final-newline)
679 (let (insert-file-contents-pre-hook ; To avoid autoconv-xmas...
680 insert-file-contents-post-hook)
681 (when (file-exists-p filename)
683 (as-binary-input-file (insert-file-contents filename)))
684 (when (and remove-final-newline
686 (= (char-after (1- (point-max))) ?\n))
687 (goto-char (point-max))
688 (delete-backward-char 1))
691 (defun elmo-save-string (string filename)
694 (as-binary-output-file
696 (write-region (point-min) (point-max)
697 filename nil 'no-msg))
700 (defun elmo-max-of-list (nlist)
704 (if (< max-num (car l))
705 (setq max-num (car l)))
709 (defun elmo-concat-path (path filename)
710 (if (not (string= path ""))
711 (if (string= elmo-path-sep (substring path (- (length path) 1)))
712 (concat path filename)
713 (concat path elmo-path-sep filename))
716 (defvar elmo-passwd-alist nil)
718 (defun elmo-passwd-alist-load ()
720 (let ((filename (expand-file-name elmo-passwd-alist-file-name
722 (tmp-buffer (get-buffer-create " *elmo-passwd-alist-tmp*"))
723 insert-file-contents-pre-hook ; To avoid autoconv-xmas...
724 insert-file-contents-post-hook
726 (if (not (file-readable-p filename))
728 (set-buffer tmp-buffer)
729 (insert-file-contents filename)
732 (read (current-buffer))
734 (kill-buffer tmp-buffer)
737 (defun elmo-passwd-alist-save ()
738 "Save password into file."
741 (let ((filename (expand-file-name elmo-passwd-alist-file-name
743 (tmp-buffer (get-buffer-create " *elmo-passwd-alist-tmp*")))
744 (set-buffer tmp-buffer)
746 (prin1 elmo-passwd-alist tmp-buffer)
747 (princ "\n" tmp-buffer)
748 ; (if (and (file-exists-p filename)
749 ; (not (equal 384 (file-modes filename))))
750 ; (error "%s is not safe.chmod 600 %s!" filename filename))
751 (if (file-writable-p filename)
753 (write-region (point-min) (point-max)
754 filename nil 'no-msg)
755 (set-file-modes filename 384))
756 (message (format "%s is not writable." filename)))
757 (kill-buffer tmp-buffer))))
759 (defun elmo-get-passwd (user-at-host)
760 "Get password from password pool."
762 (if (not elmo-passwd-alist)
763 (setq elmo-passwd-alist (elmo-passwd-alist-load)))
764 (setq data (assoc user-at-host elmo-passwd-alist))
766 (elmo-base64-decode-string (cdr data))
767 (setq pass (elmo-read-passwd (format "Password for %s: "
769 (setq elmo-passwd-alist
770 (append elmo-passwd-alist
771 (list (cons user-at-host
772 (elmo-base64-encode-string pass)))))
775 (defun elmo-remove-passwd (user-at-host)
776 "Remove password from password pool (for failure)."
777 (setq elmo-passwd-alist
778 (delete (assoc user-at-host elmo-passwd-alist)
782 (defmacro elmo-read-char-exclusive ()
783 (cond ((featurep 'xemacs)
784 '(let ((table (quote ((backspace . ?\C-h) (delete . ?\C-?)
789 (key-press-event-p (setq event (next-command-event)))
790 (setq key (or (event-to-character event)
791 (cdr (assq (event-key event) table)))))))
793 ((fboundp 'read-char-exclusive)
794 '(read-char-exclusive))
798 (defun elmo-read-passwd (prompt &optional stars)
799 "Read a single line of text from user without echoing, and return it."
803 (cursor-in-echo-area t)
804 (log-message-max-size 0)
805 message-log-max done msg truncate)
807 (if (or (not stars) (string= "" ans))
809 (setq msg (concat prompt (make-string (length ans) ?.)))
811 (1+ (- (length msg) (window-width (minibuffer-window)))))
813 (setq msg (concat "$" (substring msg (1+ truncate))))))
815 (setq c (elmo-read-char-exclusive))
819 ((or (= c ?\r) (= c ?\n) (= c ?\e))
823 ((and (/= c ?\b) (/= c ?\177))
824 (setq ans (concat ans (char-to-string c))))
826 (setq ans (substring ans 0 -1)))))
836 (defun elmo-replace-in-string (str regexp newtext &optional literal)
837 "Replaces all matches in STR for REGEXP with NEWTEXT string,
838 and returns the new string.
839 Optional LITERAL non-nil means do a literal replacement.
840 Otherwise treat \\ in NEWTEXT string as special:
841 \\& means substitute original matched text,
842 \\N means substitute match for \(...\) number N,
843 \\\\ means insert one \\."
848 (while (setq match (string-match regexp str start))
849 (setq prev-start start
854 (substring str prev-start match)
855 (cond (literal newtext)
862 (cond ((eq c ?\\) "\\")
864 (elmo-match-string 0 str))
865 ((and (>= c ?0) (<= c ?9))
866 (if (> c (+ ?0 (length
869 (error "Invalid match num: %c" c)
871 (elmo-match-string c str)))
872 (t (char-to-string c))))
873 (if (eq c ?\\) (progn (setq special t) nil)
874 (char-to-string c)))))
876 (concat rtn-str (substring str start))))
878 (defun elmo-string-to-list (string)
881 (goto-char (point-min))
883 (goto-char (point-max))
885 (goto-char (point-min))
886 (read (current-buffer))))
888 (defun elmo-plug-on-by-servers (alist &optional servers)
889 (let ((server-list (or servers elmo-plug-on-servers)))
892 (if (elmo-plugged-p (car server-list))
894 (setq server-list (cdr server-list))))))
896 (defun elmo-plug-on-by-exclude-servers (alist &optional servers)
897 (let ((server-list (or servers elmo-plug-on-exclude-servers))
898 server other-servers)
900 (when (and (not (member (setq server (caaar alist)) server-list))
901 (not (member server other-servers)))
902 (push server other-servers))
903 (setq alist (cdr alist)))
904 (elmo-plug-on-by-servers alist other-servers)))
906 (defun elmo-plugged-p (&optional server port alist label-exp)
907 (let ((alist (or alist elmo-plugged-alist))
909 (cond ((and (not port) (not server))
910 (cond ((eq elmo-plugged-condition 'one)
913 (if (nth 2 (car alist))
915 (setq alist (cdr alist)))))
916 ((eq elmo-plugged-condition 'all)
919 (if (not (nth 2 (car alist)))
920 (throw 'plugged nil))
921 (setq alist (cdr alist)))
923 ((functionp elmo-plugged-condition)
924 (funcall elmo-plugged-condition alist))
927 ((not port) ;; server
930 (when (string= server (caaar alist))
931 (if (nth 2 (car alist))
933 (setq alist (cdr alist)))))
935 (setq plugged-info (assoc (cons server port) alist))
936 (if (not plugged-info)
937 ;; add elmo-plugged-alist automatically
939 (elmo-set-plugged elmo-plugged server port nil nil label-exp)
941 (if (and elmo-auto-change-plugged
942 (> elmo-auto-change-plugged 0)
943 (nth 3 plugged-info) ;; time
944 (elmo-time-expire (nth 3 plugged-info)
945 elmo-auto-change-plugged))
947 (nth 2 plugged-info)))))))
949 (defun elmo-set-plugged (plugged &optional server port time
951 (let ((alist (or alist elmo-plugged-alist))
953 (cond ((and (not port) (not server))
954 (setq elmo-plugged plugged)
955 ;; set plugged all element of elmo-plugged-alist.
957 (setcdr (cdar alist) (list plugged time))
958 (setq alist (cdr alist))))
960 ;; set plugged all port of server
962 (when (string= server (caaar alist))
963 (setcdr (cdar alist) (list plugged time)))
964 (setq alist (cdr alist))))
966 ;; set plugged one port of server
967 (setq plugged-info (assoc (cons server port) alist))
968 (setq label (if label-exp
970 (nth 1 plugged-info)))
972 ;; if add is non-nil, don't reset plug state.
974 (setcdr plugged-info (list label plugged time)))
976 (setq elmo-plugged-alist
977 (nconc elmo-plugged-alist
979 (list (cons server port) label plugged time))))))))
982 (defun elmo-delete-plugged (&optional server port alist)
983 (let* ((alist (or alist elmo-plugged-alist))
985 (cond ((and (not port) (not server))
988 ;; delete plugged all port of server
990 (when (string= server (caaar alist2))
991 (setq alist (delete (car alist2) alist)))
992 (setq alist2 (cdr alist2))))
994 ;; delete plugged one port of server
996 (delete (assoc (cons server port) alist)) alist)))
999 (defun elmo-disk-usage (path)
1000 "Get disk usage (bytes) in PATH."
1002 (condition-case () (file-attributes path) (error nil))))
1004 (if (nth 0 file-attr) ; directory
1005 (let ((files (condition-case ()
1006 (directory-files path t "^[^\\.]")
1009 ;; (result (nth 7 file-attr))) ... directory size
1011 (setq result (+ result (or (elmo-disk-usage (car files)) 0)))
1012 (setq files (cdr files)))
1014 (float (nth 7 file-attr))))))
1016 (defun elmo-get-last-accessed-time (path &optional dir)
1017 "Returns last accessed time."
1018 (let ((last-accessed (nth 4 (file-attributes (or (and dir
1023 (setq last-accessed (+ (* (nth 0 last-accessed)
1024 (float 65536)) (nth 1 last-accessed)))
1027 (defun elmo-get-last-modification-time (path &optional dir)
1028 "Returns last accessed time."
1029 (let ((last-modified (nth 5 (file-attributes (or (and dir
1033 (setq last-modified (+ (* (nth 0 last-modified)
1034 (float 65536)) (nth 1 last-modified)))))
1036 (defun elmo-make-directory (path)
1037 "create directory recursively."
1038 (let ((parent (directory-file-name (file-name-directory path))))
1039 (if (null (file-directory-p parent))
1040 (elmo-make-directory parent))
1041 (make-directory path)
1042 (if (string= path (expand-file-name elmo-msgdb-dir))
1043 (set-file-modes path 448) ; 700
1046 (defun elmo-delete-directory (path &optional no-hierarchy)
1047 "delete directory recursively."
1048 (let ((dirent (directory-files path))
1049 relpath abspath hierarchy)
1051 (setq relpath (car dirent)
1053 abspath (expand-file-name relpath path))
1054 (when (not (string-match "^\\.\\.?$" relpath))
1055 (if (eq (nth 0 (file-attributes abspath)) t)
1058 (elmo-delete-directory abspath no-hierarchy))
1059 (delete-file abspath))))
1061 (delete-directory path))))
1063 (defun elmo-list-filter (l1 l2)
1066 ;; t means filter all.
1069 (elmo-delete-if (lambda (x) (not (memq x l1))) l2)
1073 (defun elmo-folder-local-p (folder)
1074 "Return whether FOLDER is a local folder or not."
1075 (let ((type (elmo-folder-get-type folder)))
1076 (memq type '(localdir localnews archive maildir internal cache))))
1078 (defun elmo-folder-writable-p (folder)
1079 (let ((type (elmo-folder-get-type folder)))
1080 (memq type '(imap4 localdir archive))))
1082 (defun elmo-multi-get-intlist-list (numlist &optional as-is)
1083 (let ((numbers (sort numlist '<))
1085 one-list int-list-list)
1087 (setq cur-number (+ cur-number 1))
1092 (* elmo-multi-divide-number cur-number))
1093 elmo-multi-divide-number)))
1094 (setq one-list (nconc
1100 (* elmo-multi-divide-number cur-number))))))
1101 (setq numbers (cdr numbers)))
1102 (setq int-list-list (nconc int-list-list (list one-list))))
1105 (defsubst elmo-list-delete-if-smaller (list number)
1106 (let ((ret-val (copy-sequence list)))
1108 (if (< (car list) number)
1109 (setq ret-val (delq (car list) ret-val)))
1110 (setq list (cdr list)))
1113 (defun elmo-list-diff (list1 list2 &optional mes)
1116 (let ((clist1 (copy-sequence list1))
1117 (clist2 (copy-sequence list2)))
1119 (setq clist1 (delq (car list2) clist1))
1120 (setq list2 (cdr list2)))
1122 (setq clist2 (delq (car list1) clist2))
1123 (setq list1 (cdr list1)))
1125 (message (concat mes "done.")))
1126 (list clist1 clist2)))
1128 (defun elmo-list-bigger-diff (list1 list2 &optional mes)
1129 "Returns a list (- +). + is bigger than max of LIST1, in LIST2"
1134 (max-of-l2 (or (nth (max 0 (1- (length l2))) l2) 0))
1138 (setq num (+ (length l1)))
1140 (if (memq (car l1) l2)
1141 (if (eq (car l1) (car l2))
1144 (if (> (car l1) max-of-l2)
1145 (setq diff1 (nconc diff1 (list (car l1))))))
1149 (setq percent (/ (* i 100) num))
1150 (if (eq (% percent 5) 0)
1151 (elmo-display-progress
1152 'elmo-list-bigger-diff "%s%d%%" percent mes))))
1154 (cons diff1 (list l2)))))
1156 (defun elmo-multi-list-bigger-diff (list1 list2 &optional mes)
1157 (let ((list1-list (elmo-multi-get-intlist-list list1 t))
1158 (list2-list (elmo-multi-get-intlist-list list2 t))
1161 (while (or list1-list list2-list)
1162 (setq result (elmo-list-bigger-diff (car list1-list) (car list2-list)
1164 (setq dels (append dels (car result)))
1165 (setq news (append news (cadr result)))
1166 (setq list1-list (cdr list1-list))
1167 (setq list2-list (cdr list2-list)))
1168 (cons dels (list news))))
1170 (defvar elmo-imap4-name-space-regexp-list nil)
1171 (defun elmo-imap4-identical-name-space-p (fld1 fld2)
1173 (if (or (eq (string-to-char fld1) ?#)
1174 (eq (string-to-char fld2) ?#))
1175 (string= (car (split-string fld1 "/"))
1176 (car (split-string fld2 "/")))
1179 (defun elmo-folder-identical-system-p (folder1 folder2)
1180 "folder1 and folder2 should be real folder (not virtual)."
1181 (cond ((eq (elmo-folder-get-type folder1) 'imap4)
1182 (let ((spec1 (elmo-folder-get-spec folder1))
1183 (spec2 (elmo-folder-get-spec folder2)))
1184 (and (elmo-imap4-identical-name-space-p
1185 (nth 1 spec1) (nth 1 spec2))
1186 (string= (elmo-imap4-spec-hostname spec1)
1187 (elmo-imap4-spec-hostname spec2)) ; hostname
1188 (string= (elmo-imap4-spec-username spec1)
1189 (elmo-imap4-spec-username spec2))))) ; username
1191 (elmo-folder-direct-copy-p folder1 folder2))))
1193 (defconst elmo-folder-direct-copy-alist
1194 '((localdir . (localdir localnews archive))
1195 (maildir . (maildir localdir localnews archive))
1196 (localnews . (localdir localnews archive))
1197 (archive . (localdir localnews archive))
1198 (cache . (localdir localnews archive))))
1200 (defun elmo-folder-direct-copy-p (src-folder dst-folder)
1201 (let ((src-type (car (elmo-folder-get-spec src-folder)))
1202 (dst-type (car (elmo-folder-get-spec dst-folder)))
1204 (and (setq dst-copy-type
1205 (cdr (assq src-type elmo-folder-direct-copy-alist)))
1206 (memq dst-type dst-copy-type))))
1208 (defmacro elmo-filter-type (filter)
1209 (` (aref (, filter) 0)))
1211 (defmacro elmo-filter-key (filter)
1212 (` (aref (, filter) 1)))
1214 (defmacro elmo-filter-value (filter)
1215 (` (aref (, filter) 2)))
1217 (defsubst elmo-buffer-field-condition-match (condition)
1221 (goto-char (point-min))
1222 (setq term (car condition))
1224 ((and (eq (elmo-filter-type term) 'date)
1225 (string= (elmo-filter-key term) "since"))
1226 (let ((date (elmo-date-get-datevec (elmo-filter-value term))))
1228 (timezone-make-sortable-date (aref date 0)
1231 (timezone-make-time-string
1235 (timezone-make-date-sortable (std11-field-body "date")))
1237 ((and (eq (elmo-filter-type term) 'date)
1238 (string= (elmo-filter-key term) "before"))
1239 (let ((date (elmo-date-get-datevec (elmo-filter-value term))))
1241 (timezone-make-date-sortable (std11-field-body "date"))
1242 (timezone-make-sortable-date (aref date 0)
1245 (timezone-make-time-string
1250 ((eq (elmo-filter-type term) 'match)
1251 (if (string= "body" (elmo-filter-key term))
1253 (re-search-forward "^$" nil t) ; goto body
1254 (if (search-forward (elmo-filter-value term) nil t)
1256 (let ((fval (eword-decode-string
1257 (or (std11-field-body (elmo-filter-key term)) ""))))
1258 (if (and fval (string-match (elmo-filter-value term)
1261 ((eq (elmo-filter-type term) 'unmatch)
1262 (if (string= "body" (elmo-filter-key term))
1264 (re-search-forward "^$" nil t) ; goto body
1265 (if (not (search-forward (elmo-filter-value term) nil t))
1267 (let ((fval (eword-decode-string
1268 (or (std11-field-body (elmo-filter-key term)) ""))))
1270 (if (not (string-match (elmo-filter-value term)
1273 (throw 'done t)))))) ; OK?
1274 (setq condition (cdr condition)))
1275 (throw 'done nil))))
1277 (defsubst elmo-file-field-condition-match (file condition)
1279 (as-binary-input-file
1280 (insert-file-contents file))
1281 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
1282 (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
1283 (elmo-buffer-field-condition-match condition)))
1285 (defun elmo-cross-device-link-error-p (err)
1290 (if (and (stringp (setq cur (car errobj)))
1291 (or (string-match "cross-device" cur)
1292 (string-match "operation not supported" cur)))
1294 (setq errobj (cdr errobj)))
1297 (defmacro elmo-get-hash-val (string hashtable)
1298 (let ((sym (list 'intern-soft string hashtable)))
1299 (list 'if (list 'boundp sym)
1300 (list 'symbol-value sym))))
1302 (defmacro elmo-set-hash-val (string value hashtable)
1303 (list 'set (list 'intern string hashtable) value))
1305 ;; Make a hash table (default and minimum size is 1024).
1306 (defun elmo-make-hash (&optional hashsize)
1307 (make-vector (if hashsize (max (elmo-create-hash-size hashsize) 1024) 1024) 0))
1309 (defsubst elmo-mime-string (string)
1310 "Normalize MIME encoded string."
1314 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
1315 (setq str (eword-decode-string
1316 (decode-mime-charset-string string elmo-mime-charset)))
1317 (setq str (encode-mime-charset-string str elmo-mime-charset))
1318 (elmo-set-buffer-multibyte nil)
1321 (defsubst elmo-collect-field (beg end downcase-field-name)
1324 (narrow-to-region beg end)
1325 (goto-char (point-min))
1326 (let ((regexp (concat "\\(" std11-field-head-regexp "\\)[ \t]*"))
1328 (while (re-search-forward regexp nil t)
1329 (setq name (buffer-substring-no-properties
1330 (match-beginning 1)(1- (match-end 1))))
1331 (if downcase-field-name
1332 (setq name (downcase name)))
1333 (setq body (buffer-substring-no-properties
1334 (match-end 0) (std11-field-end)))
1335 (or (assoc name dest)
1336 (setq dest (cons (cons name body) dest))))
1339 (defsubst elmo-collect-field-from-string (string downcase-field-name)
1342 (goto-char (point-min))
1343 (let ((regexp (concat "\\(" std11-field-head-regexp "\\)[ \t]*"))
1345 (while (re-search-forward regexp nil t)
1346 (setq name (buffer-substring-no-properties
1347 (match-beginning 1)(1- (match-end 1))))
1348 (if downcase-field-name
1349 (setq name (downcase name)))
1350 (setq body (buffer-substring-no-properties
1351 (match-end 0) (std11-field-end)))
1352 (or (assoc name dest)
1353 (setq dest (cons (cons name body) dest))))
1356 (defun elmo-create-hash-size (min)
1362 (defun elmo-safe-filename (folder)
1363 (elmo-replace-in-string
1364 (elmo-replace-in-string
1365 (elmo-replace-in-string folder "/" " ")
1369 (defvar elmo-msgid-replace-chars nil)
1371 (defsubst elmo-replace-msgid-as-filename (msgid)
1372 "Replace message-id string as filename."
1373 (setq msgid (elmo-replace-in-string msgid " " " "))
1374 (if (null elmo-msgid-replace-chars)
1375 (setq elmo-msgid-replace-chars
1376 (regexp-quote (mapconcat
1377 'car elmo-msgid-replace-string-alist ""))))
1378 (while (string-match (concat "[" elmo-msgid-replace-chars "]")
1381 (substring msgid 0 (match-beginning 0))
1384 (match-beginning 0) (match-end 0))
1385 elmo-msgid-replace-string-alist))
1386 (substring msgid (match-end 0)))))
1389 (defsubst elmo-recover-msgid-from-filename (filename)
1390 "Recover Message-ID from filename."
1392 (while (string-match " " filename)
1393 (setq tmp (substring filename
1395 (+ (match-end 0) 1)))
1396 (if (string= tmp " ")
1398 (setq tmp (car (rassoc tmp
1399 elmo-msgid-replace-string-alist))))
1402 (substring filename 0 (match-beginning 0))
1404 (setq filename (substring filename (+ (match-end 0) 1))))
1405 (concat result filename)))
1407 (defsubst elmo-copy-file (src dst)
1409 (elmo-add-name-to-file src dst t)
1410 (error (if (elmo-cross-device-link-error-p err)
1411 (copy-file src dst t)
1412 (error "copy file failed")))))
1414 (defmacro elmo-buffer-exists-p (buffer)
1416 (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
1419 (defmacro elmo-kill-buffer (buffer)
1420 (` (when (elmo-buffer-exists-p (, buffer))
1421 (kill-buffer (, buffer)))))
1423 (defun elmo-delete-lists (keys list)
1424 "Delete all entries in LIST that equal to KEYS."
1426 (setq list (delete (car keys) list))
1427 (setq keys (cdr keys)))
1430 (defun elmo-delete-if (pred lst)
1431 "Returns new list contains items which don't satisfy PRED in LST."
1434 (unless (funcall pred (car lst))
1435 (setq result (nconc result (list (car lst)))))
1436 (setq lst (cdr lst)))
1439 (defun elmo-list-delete (list1 list2)
1440 "Any element of list1 is deleted from list2."
1442 (setq list2 (delete (car list1) list2))
1443 (setq list1 (cdr list1)))
1446 (defun elmo-list-member (list1 list2)
1447 "If any element of list1 is member of list2, returns t."
1450 (if (member (car list1) list2)
1452 (setq list1 (cdr list1)))))
1454 (defun elmo-count-matches (regexp beg end)
1458 (while (re-search-forward regexp end t)
1459 (setq count (1+ count)))
1462 (if (fboundp 'display-error)
1463 (defalias 'elmo-display-error 'display-error)
1464 (defun elmo-display-error (error-object stream)
1465 "a tiny function to display error-object to the stream."
1467 (errobj error-object)
1470 (setq err-mes (concat err-mes (format
1471 (if (stringp (car errobj))
1473 (if (boundp 'nemacs-version)
1475 "%S")) (car errobj))))
1476 (setq errobj (cdr errobj))
1477 (if errobj (setq err-mes (concat err-mes (if first ": " ", "))))
1479 (princ err-mes stream))))
1481 (if (fboundp 'lprogress-display)
1482 (defalias 'elmo-display-progress 'lprogress-display)
1483 (defun elmo-display-progress (label format &optional value &rest args)
1484 "Print a progress message."
1485 (if (and (null format) (null args))
1487 (apply (function message) (concat format " %d%%")
1488 (nconc args (list value))))))
1490 (defun elmo-time-expire (before-time diff-time)
1491 (let* ((current (current-time))
1492 (rest (when (< (nth 1 current) (nth 1 before-time))
1496 (list (- (+ (car current) (if rest -1 0)) (car before-time))
1497 (- (+ (or rest 0) (nth 1 current)) (nth 1 before-time))))
1498 (and (eq (car diff) 0)
1499 (< diff-time (nth 1 diff)))))
1501 (defun elmo-open-network-stream (name buffer host service ssl)
1502 (let ((auto-plugged (and elmo-auto-change-plugged
1503 (> elmo-auto-change-plugged 0)))
1505 (if (eq ssl 'starttls)
1507 (if ssl (require 'ssl)))
1509 (let (process-connection-type)
1511 (if (eq ssl 'starttls)
1512 (starttls-open-stream name buffer host service)
1514 (open-ssl-stream name buffer host service)
1515 (open-network-stream name buffer host service)))))
1518 (elmo-set-plugged nil host service (current-time))
1519 (message "Auto plugged off at %s:%d" host service)
1521 (signal (car err) (cdr err))))
1523 (process-kill-without-query process)
1525 (elmo-set-plugged t host service))
1528 (if (fboundp 'std11-fetch-field)
1529 (defalias 'elmo-field-body 'std11-fetch-field) ;;no narrow-to-region
1530 (defalias 'elmo-field-body 'std11-field-body))
1532 (defmacro elmo-string (string)
1533 "String without text property"
1534 (` (let ((obj (copy-sequence (, string))))
1535 (set-text-properties 0 (length obj) nil obj)
1538 (defun elmo-y-or-n-p (prompt &optional auto default)
1539 "Same as `y-or-n-p'.
1540 But if optional argument AUTO is non-nil, DEFAULT is returned."
1545 (defun elmo-string-member (string slist)
1546 "Returns t if STRING is a member of the SLIST."
1549 (if (and (stringp (car slist))
1550 (string= string (car slist)))
1552 (setq slist (cdr slist)))))
1554 (defun elmo-string-match-member (str list &optional case-ignore)
1555 (let ((case-fold-search case-ignore))
1558 (if (string-match (car list) str)
1559 (throw 'member (car list)))
1560 (setq list (cdr list))))))
1562 (defsubst elmo-string-delete-match (string pos)
1563 (concat (substring string
1564 0 (match-beginning pos))
1569 (defun elmo-string-match-assoc (key alist &optional case-ignore)
1570 (let ((case-fold-search case-ignore)
1574 (setq a (car alist))
1577 (string-match key (car a)))
1579 (setq alist (cdr alist))))))
1581 (defun elmo-string-matched-assoc (key alist &optional case-ignore)
1582 (let ((case-fold-search case-ignore)
1586 (setq a (car alist))
1589 (string-match (car a) key))
1591 (setq alist (cdr alist))))))
1593 (defun elmo-string-assoc (key alist)
1597 (setq a (car alist))
1600 (string= key (car a)))
1602 (setq alist (cdr alist))))))
1604 (defun elmo-string-rassoc (key alist)
1608 (setq a (car alist))
1611 (string= key (cdr a)))
1613 (setq alist (cdr alist))))))
1615 (provide 'elmo-util)
1617 ;;; elmo-util.el ends here