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
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
36 (require 'eword-decode)
45 (defun-maybe starttls-negotiate (a))
46 (defun-maybe starttls-open-stream (a b c d))
47 (defun-maybe open-ssl-stream (a b c d)))
49 (defmacro elmo-set-buffer-multibyte (flag)
50 "Set the multibyte flag of the current buffer to FLAG."
52 (list 'setq 'mc-flag flag))
55 ((and (boundp 'emacs-major-version) (>= emacs-major-version 20))
56 (list 'set-buffer-multibyte flag))
60 (defvar elmo-work-buf-name " *elmo work*")
61 (defvar elmo-temp-buf-name " *elmo temp*")
63 (or (boundp 'default-enable-multibyte-characters)
64 (defvar default-enable-multibyte-characters (featurep 'mule)
65 "The mock variable except for Emacs 20."))
67 (defun elmo-base64-encode-string (string &optional no-line-break))
68 (defun elmo-base64-decode-string (string))
70 ;; base64 encoding/decoding
72 (fset 'elmo-base64-encode-string
73 (mel-find-function 'mime-encode-string "base64"))
74 (fset 'elmo-base64-decode-string
75 (mel-find-function 'mime-decode-string "base64"))
77 ;; Any Emacsen may have add-name-to-file(), because loadup.el requires it. :-p
78 ;; Check make-symbolic-link() instead. -- 981002 by Fuji
79 (if (fboundp 'make-symbolic-link) ;; xxx
80 (defalias 'elmo-add-name-to-file 'add-name-to-file)
81 (defun elmo-add-name-to-file
82 (filename newname &optional ok-if-already-exists)
83 (copy-file filename newname ok-if-already-exists t)))
86 (broken-facility timezone-y2k
87 "timezone.el does not clear Y2K."
88 (or (not (featurep 'timezone))
89 (string= (aref (timezone-parse-date "Sat, 1 Jan 00 07:00:00 JST") 0)
92 (when-broken timezone-y2k
93 (defun timezone-parse-date (date)
94 "Parse DATE and return a vector [YEAR MONTH DAY TIME TIMEZONE].
95 19 is prepended to year if necessary. Timezone may be nil if nothing.
96 Understands the following styles:
97 (1) 14 Apr 89 03:20[:12] [GMT]
98 (2) Fri, 17 Mar 89 4:01[:33] [GMT]
99 (3) Mon Jan 16 16:12[:37] [GMT] 1989
100 (4) 6 May 1992 1641-JST (Wednesday)
101 (5) 22-AUG-1993 10:59:12.82
102 (6) Thu, 11 Apr 16:17:12 91 [MET]
103 (7) Mon, 6 Jul 16:47:20 T 1992 [MET]"
106 ;; Get rid of any text properties.
108 (or (text-properties-at 0 date)
109 (next-property-change 0 date))
110 (setq date (copy-sequence date))
111 (set-text-properties 0 (length date) nil date))
112 (let ((date (or date ""))
117 (zone nil)) ;This may be nil.
119 "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\'" date)
120 ;; Styles: (6) and (7) without timezone
121 (setq year 6 month 3 day 2 time 4 zone nil))
123 "\\([^ \t,]+\\),[ \t]+\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\(T[ \t]+\\|\\)\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
124 ;; Styles: (6) and (7) with timezone and buggy timezone
125 (setq year 6 month 3 day 2 time 4 zone 7))
127 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\'" date)
128 ;; Styles: (1) and (2) without timezone
129 (setq year 3 month 2 day 1 time 4 zone nil))
131 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
132 ;; Styles: (1) and (2) with timezone and buggy timezone
133 (setq year 3 month 2 day 1 time 4 zone 5))
135 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([0-9]+\\)" date)
136 ;; Styles: (3) without timezone
137 (setq year 4 month 1 day 2 time 3 zone nil))
139 "\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9:]+\\)[ \t]+\\([-+a-zA-Z0-9]+\\)[ \t]+\\([0-9]+\\)" date)
140 ;; Styles: (3) with timezone
141 (setq year 5 month 1 day 2 time 3 zone 4))
143 "\\([0-9]+\\)[ \t]+\\([^ \t,]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]*\\([-+a-zA-Z0-9]+\\)" date)
144 ;; Styles: (4) with timezone
145 (setq year 3 month 2 day 1 time 4 zone 5))
147 "\\([0-9]+\\)-\\([A-Za-z]+\\)-\\([0-9]+\\)[ \t]+\\([0-9]+:[0-9]+:[0-9]+\\)\\.[0-9]+" date)
148 ;; Styles: (5) without timezone.
149 (setq year 3 month 2 day 1 time 4 zone nil))
154 (substring date (match-beginning year)
156 (if (< (length year) 4)
157 (let ((yr (string-to-int year)))
159 (setq yr (- yr 100)))
160 (setq year (format "%d%02d"
165 (let ((string (substring date
166 (match-beginning month)
167 (+ (match-beginning month) 3))))
170 (cdr (assoc (upcase string)
171 timezone-months-assoc)))))
173 (substring date (match-beginning day) (match-end day)))
175 (substring date (match-beginning time)
179 (substring date (match-beginning zone)
182 (vector year month day time zone)
183 (vector "0" "0" "0" "0" nil))
186 (t (signal 'invalid-date (list date))))))
188 (defsubst elmo-call-func (folder func-name &rest args)
189 (let* ((spec (if (stringp folder)
190 (elmo-folder-get-spec folder)
192 (type (symbol-name (car spec)))
193 (backend-str (concat "elmo-" type))
194 (backend-sym (intern backend-str)))
195 (unless (featurep backend-sym)
196 (require backend-sym))
197 (apply (intern (format "%s-%s" backend-str func-name))
201 (defmacro elmo-set-work-buf (&rest body)
202 "Execute BODY on work buffer. Work buffer remains."
204 (set-buffer (get-buffer-create elmo-work-buf-name))
205 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
209 (defmacro elmo-match-substring (pos string from)
210 "Substring of POSth matched string of STRING. "
211 (` (substring (, string)
212 (+ (match-beginning (, pos)) (, from))
213 (match-end (, pos)))))
215 (defmacro elmo-match-string (pos string)
216 "Substring POSth matched string."
217 (` (substring (, string) (match-beginning (, pos)) (match-end (, pos)))))
219 (defmacro elmo-match-buffer (pos)
220 "Substring POSth matched from the current buffer."
221 (` (buffer-substring-no-properties
222 (match-beginning (, pos)) (match-end (, pos)))))
224 (defmacro elmo-bind-directory (dir &rest body)
225 "Set current directory DIR and execute BODY."
226 (` (let ((default-directory (file-name-as-directory (, dir))))
229 (defmacro elmo-folder-get-type (folder)
230 "Get type of FOLDER."
231 (` (and (stringp (, folder))
232 (cdr (assoc (string-to-char (, folder)) elmo-spec-alist)))))
234 (defun elmo-object-load (filename &optional mime-charset no-err)
235 "Load OBJECT from the file specified by FILENAME.
236 File content is decoded with MIME-CHARSET."
237 (if (not (file-readable-p filename))
240 (as-binary-input-file
241 (insert-file-contents filename))
243 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
244 (decode-mime-charset-region (point-min) (point-max) mime-charset))
246 (read (current-buffer))
247 (error (unless no-err
248 (message "Warning: Loading object from %s failed."
250 (elmo-object-save filename nil))
253 (defsubst elmo-save-buffer (filename &optional mime-charset)
254 "Save current buffer to the file specified by FILENAME.
255 Directory of the file is created if it doesn't exist.
256 File content is encoded with MIME-CHARSET."
257 (let ((dir (directory-file-name (file-name-directory filename))))
258 (if (file-directory-p dir)
260 (unless (file-exists-p dir)
261 (elmo-make-directory dir)))
262 (if (file-writable-p filename)
265 ;;(elmo-set-buffer-multibyte default-enable-multibyte-characters)
266 (encode-mime-charset-region (point-min) (point-max) mime-charset))
267 (as-binary-output-file
268 (write-region (point-min) (point-max) filename nil 'no-msg)))
269 (message (format "%s is not writable." filename)))))
271 (defun elmo-object-save (filename object &optional mime-charset)
272 "Save OBJECT to the file specified by FILENAME.
273 Directory of the file is created if it doesn't exist.
274 File content is encoded with MIME-CHARSET."
276 (prin1 object (current-buffer))
277 ;;(princ "\n" (current-buffer))
278 (elmo-save-buffer filename mime-charset)))
280 (defsubst elmo-imap4-decode-folder-string (string)
281 (if elmo-imap4-use-modified-utf7
282 (utf7-decode-string string 'imap)
285 (defsubst elmo-imap4-encode-folder-string (string)
286 (if elmo-imap4-use-modified-utf7
287 (utf7-encode-string string 'imap)
290 (defun elmo-network-get-spec (folder default-server default-port default-tls)
291 (let (server port tls)
292 (if (string-match "\\(@[^@:/!]+\\)?\\(:[0-9]+\\)?\\(!*\\)$" folder)
294 (if (match-beginning 1)
295 (setq server (elmo-match-substring 1 folder 1))
296 (setq server default-server))
297 (if (match-beginning 2)
299 (string-to-int (elmo-match-substring 2 folder 1)))
300 (setq port default-port))
301 (setq tls (elmo-match-string 3 folder))
302 (if (and (match-beginning 3)
304 (setq tls (if (= 2 (length tls)) 'starttls
306 (setq tls default-tls))
307 (setq folder (substring folder 0 (match-beginning 0))))
308 (setq server default-server
311 (cons folder (list server port tls))))
313 (defun elmo-imap4-get-spec (folder)
314 (let ((default-user elmo-default-imap4-user)
315 (default-server elmo-default-imap4-server)
316 (default-port elmo-default-imap4-port)
317 (default-tls elmo-default-imap4-ssl)
318 spec mailbox user auth)
319 (when (string-match "\\(.*\\)@\\(.*\\)" default-server)
320 ;; case: default-imap4-server is specified like
321 ;; "hoge%imap.server@gateway".
322 (setq default-user (elmo-match-string 1 default-server))
323 (setq default-server (elmo-match-string 2 default-server)))
324 (setq spec (elmo-network-get-spec
325 folder default-server default-port default-tls))
326 (setq folder (car spec))
328 "^\\(%\\)\\([^:@!]*\\)\\(:[^/!]+\\)?\\(/[^/:@!]+\\)?"
331 (setq mailbox (if (match-beginning 2)
332 (elmo-match-string 2 folder)
333 elmo-default-imap4-mailbox))
334 (setq user (if (match-beginning 3)
335 (elmo-match-substring 3 folder 1)
337 (setq auth (if (match-beginning 4)
338 (elmo-match-substring 4 folder 1)
339 elmo-default-imap4-authenticate-type))
341 (elmo-imap4-encode-folder-string mailbox)
345 (defsubst elmo-imap4-spec-mailbox (spec)
348 (defsubst elmo-imap4-spec-username (spec)
351 (defsubst elmo-imap4-spec-auth (spec)
354 (defsubst elmo-imap4-spec-hostname (spec)
357 (defsubst elmo-imap4-spec-port (spec)
360 (defsubst elmo-imap4-spec-ssl (spec)
363 (defsubst elmo-imap4-spec-folder (spec) ;; obsolete
366 (defsubst elmo-imap4-connection-get-process (conn)
369 (defsubst elmo-imap4-connection-get-buffer (conn)
372 (defsubst elmo-imap4-connection-get-cwf (conn)
375 (defun elmo-nntp-get-spec (folder)
376 (let (spec group user)
377 (setq spec (elmo-network-get-spec folder
378 elmo-default-nntp-server
379 elmo-default-nntp-port
380 elmo-default-nntp-ssl))
381 (setq folder (car spec))
383 "^\\(-\\)\\([^:@!]*\\)\\(:[^/!]+\\)?\\(/[^/:@!]+\\)?"
386 (if (match-beginning 2)
387 (elmo-match-string 2 folder)))
389 (if (match-beginning 3)
390 (elmo-match-substring 3 folder 1)
391 elmo-default-nntp-user))
392 (append (list 'nntp group user)
395 (defsubst elmo-nntp-spec-group (spec)
398 (defsubst elmo-nntp-spec-username (spec)
402 ;; (defsubst elmo-nntp-spec-auth (spec))
404 (defsubst elmo-nntp-spec-hostname (spec)
407 (defsubst elmo-nntp-spec-port (spec)
410 (defsubst elmo-nntp-spec-ssl (spec)
413 (defun elmo-localdir-get-spec (folder)
416 "^\\(\\+\\)\\(.*\\)$"
418 (if (eq (length (setq fld-name
419 (elmo-match-string 2 folder))) 0)
422 (if (file-name-absolute-p fld-name)
423 (setq path (expand-file-name fld-name))
424 (setq path fld-name))
425 ;(setq path (expand-file-name fld-name
426 ;elmo-localdir-folder-path)))
427 (list (if (elmo-folder-maildir-p folder)
431 (defun elmo-maildir-get-spec (folder)
434 "^\\(\\.\\)\\(.*\\)$"
436 (if (eq (length (setq fld-name
437 (elmo-match-string 2 folder))) 0)
439 (if (file-name-absolute-p fld-name)
440 (setq path (expand-file-name fld-name))
441 (setq path fld-name))
442 (list 'maildir path))))
444 (defun elmo-folder-maildir-p (folder)
446 (let ((li elmo-maildir-list))
448 (if (string-match (car li) folder)
450 (setq li (cdr li))))))
452 (defun elmo-localnews-get-spec (folder)
457 (if (eq (length (setq fld-name
458 (elmo-match-string 2 folder))) 0)
462 (elmo-replace-in-string fld-name "\\." "/")))))
464 (defun elmo-cache-get-spec (folder)
469 (if (eq (length (setq fld-name
470 (elmo-match-string 2 folder))) 0)
474 (elmo-replace-in-string fld-name "\\." "/")))))
476 ;; Archive interface by OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
477 (defun elmo-archive-get-spec (folder)
478 (require 'elmo-archive)
479 (let (fld-name type prefix)
481 "^\\(\\$\\)\\([^;]*\\);?\\([^;]*\\);?\\([^;]*\\)$"
483 ;; Drive letter is OK!
484 (if (eq (length (setq fld-name
485 (elmo-match-string 2 folder))) 0)
488 (if (eq (length (setq type
489 (elmo-match-string 3 folder))) 0)
490 (setq type (symbol-name elmo-archive-default-type)))
491 (if (eq (length (setq prefix
492 (elmo-match-string 4 folder))) 0)
494 (list 'archive fld-name (intern-soft type) prefix))))
496 (defun elmo-pop3-get-spec (folder)
497 (let (spec user auth)
498 (setq spec (elmo-network-get-spec folder
499 elmo-default-pop3-server
500 elmo-default-pop3-port
501 elmo-default-pop3-ssl))
502 (setq folder (car spec))
504 "^\\(&\\)\\([^:/!]*\\)\\(/[^/:@!]+\\)?"
506 (setq user (if (match-beginning 2)
507 (elmo-match-string 2 folder)))
508 (if (eq (length user) 0)
509 (setq user elmo-default-pop3-user))
510 (setq auth (if (match-beginning 3)
511 (elmo-match-substring 3 folder 1)
512 elmo-default-pop3-authenticate-type))
513 (append (list 'pop3 user auth)
516 (defsubst elmo-pop3-spec-username (spec)
519 (defsubst elmo-pop3-spec-auth (spec)
522 (defsubst elmo-pop3-spec-hostname (spec)
525 (defsubst elmo-pop3-spec-port (spec)
528 (defsubst elmo-pop3-spec-ssl (spec)
531 (defun elmo-internal-get-spec (folder)
532 (if (string-match "\\('\\)\\([^/]*\\)/?\\(.*\\)$" folder)
533 (let* ((item (downcase (elmo-match-string 2 folder)))
534 (sym (and (> (length item) 0) (intern item))))
535 (cond ((or (null sym)
537 (list 'internal sym (elmo-match-string 3 folder)))
539 (list 'cache (elmo-match-string 3 folder)))
540 (t (error "Invalid internal folder spec"))))))
542 (defun elmo-multi-get-spec (folder)
545 "^\\(\\*\\)\\(.*\\)$"
547 (append (list 'multi)
549 (elmo-match-string 2 folder)
552 (defun elmo-filter-get-spec (folder)
557 (let ((spec (elmo-match-string 2 folder))
559 (when (string-match "\\([^/]+\\)/" spec)
560 (setq filter (elmo-match-string 1 spec))
561 (setq spec (substring spec (match-end 0))))
563 ((string-match "^\\(last\\|first\\):\\(.*\\)$" filter) ; partial
564 (setq filter (vector 'partial
565 (elmo-match-string 1 filter)
566 (elmo-match-string 2 filter))))
568 (setq filter (elmo-parse-search-condition filter))))
569 (list 'filter filter spec)))))
571 (defun elmo-pipe-get-spec (folder)
572 (when (string-match "^\\(|\\)\\([^|]*\\)|\\(.*\\)$" folder)
574 (elmo-match-string 2 folder)
575 (elmo-match-string 3 folder))))
577 (defun elmo-folder-get-spec (folder)
578 "return spec of folder"
579 (let ((type (elmo-folder-get-type folder)))
581 (funcall (intern (concat "elmo-" (symbol-name type) "-get-spec"))
583 (error "%s is not supported folder type" folder))))
585 (defun elmo-parse-search-condition (condition)
586 (let ((terms (split-string condition "|")) ; split by OR
589 (setq term (car terms))
591 ((string-match "^\\([a-zA-Z\\-]+\\)=\\(.*\\)$" term)
593 (string-match "tocc" (elmo-match-string 1 term))) ;; syntax sugar
596 (list (vector 'match "to"
597 (elmo-match-string 2 term))
599 (elmo-match-string 2 term)))))
600 (setq ret-val (cons (vector 'match
601 (elmo-match-string 1 term)
602 (elmo-match-string 2 term))
604 ((string-match "^\\([a-zA-Z\\-]+\\)!=\\(.*\\)$" term)
606 (string-match "tocc" (elmo-match-string 1 term))) ;; syntax sugar
609 (list (vector 'unmatch "to"
610 (elmo-match-string 2 term))
611 (vector 'unmatch "cc"
612 (elmo-match-string 2 term)))))
613 (setq ret-val (cons (vector 'unmatch
614 (elmo-match-string 1 term)
615 (elmo-match-string 2 term))
617 ((string-match "^\\(since\\|before\\):\\(.*\\)$" term)
618 (setq ret-val (cons (vector 'date
619 (elmo-match-string 1 term)
620 (elmo-match-string 2 term))
622 (setq terms (cdr terms)))
625 (defun elmo-multi-get-real-folder-number (folder number)
626 (let* ((spec (elmo-folder-get-spec folder))
629 (fld (nth (- (/ num elmo-multi-divide-number) 1) flds)))
630 (cons fld (% num elmo-multi-divide-number))))
632 (defsubst elmo-buffer-replace (regexp &optional newtext)
633 (goto-char (point-min))
634 (while (re-search-forward regexp nil t)
635 (replace-match (or newtext ""))))
637 (defsubst elmo-delete-char (char string &optional unibyte)
640 (let ((coding-system-for-read 'no-conversion)
641 (coding-system-for-write 'no-conversion))
642 (if unibyte (elmo-set-buffer-multibyte nil))
644 (goto-char (point-min))
645 (while (search-forward (char-to-string char) nil t)
649 (defsubst elmo-delete-cr-get-content-type ()
651 (goto-char (point-min))
652 (while (search-forward "\r\n" nil t)
653 (replace-match "\n"))
654 (goto-char (point-min))
655 (or (std11-field-body "content-type")
658 (defun elmo-delete-cr (string)
662 (goto-char (point-min))
663 (while (search-forward "\r\n" nil t)
664 (replace-match "\n"))
667 (defun elmo-uniq-list (lst)
668 "Distractively uniqfy elements of LST."
670 (while tmp (setq tmp (setcdr tmp (and (cdr tmp) (delete (car tmp) (cdr tmp)))))))
673 (defun elmo-string-partial-p (string)
674 (and (stringp string) (string-match "message/partial" string)))
676 (defun elmo-get-file-string (filename &optional remove-final-newline)
678 (let (insert-file-contents-pre-hook ; To avoid autoconv-xmas...
679 insert-file-contents-post-hook)
680 (when (file-exists-p filename)
682 (as-binary-input-file (insert-file-contents filename)))
683 (when (and remove-final-newline
685 (= (char-after (1- (point-max))) ?\n))
686 (goto-char (point-max))
687 (delete-backward-char 1))
690 (defun elmo-save-string (string filename)
693 (as-binary-output-file
695 (write-region (point-min) (point-max)
696 filename nil 'no-msg))
699 (defun elmo-max-of-list (nlist)
703 (if (< max-num (car l))
704 (setq max-num (car l)))
708 (defun elmo-concat-path (path filename)
709 (if (not (string= path ""))
710 (if (string= elmo-path-sep (substring path (- (length path) 1)))
711 (concat path filename)
712 (concat path elmo-path-sep filename))
715 (defvar elmo-passwd-alist nil)
717 (defun elmo-passwd-alist-load ()
719 (let ((filename (expand-file-name elmo-passwd-alist-file-name
721 (tmp-buffer (get-buffer-create " *elmo-passwd-alist-tmp*"))
722 insert-file-contents-pre-hook ; To avoid autoconv-xmas...
723 insert-file-contents-post-hook
725 (if (not (file-readable-p filename))
727 (set-buffer tmp-buffer)
728 (insert-file-contents filename)
731 (read (current-buffer))
733 (kill-buffer tmp-buffer)
736 (defun elmo-passwd-alist-save ()
737 "Save password into file."
740 (let ((filename (expand-file-name elmo-passwd-alist-file-name
742 (tmp-buffer (get-buffer-create " *elmo-passwd-alist-tmp*")))
743 (set-buffer tmp-buffer)
745 (prin1 elmo-passwd-alist tmp-buffer)
746 (princ "\n" tmp-buffer)
747 ; (if (and (file-exists-p filename)
748 ; (not (equal 384 (file-modes filename))))
749 ; (error "%s is not safe.chmod 600 %s!" filename filename))
750 (if (file-writable-p filename)
752 (write-region (point-min) (point-max)
753 filename nil 'no-msg)
754 (set-file-modes filename 384))
755 (message (format "%s is not writable." filename)))
756 (kill-buffer tmp-buffer))))
758 (defun elmo-get-passwd (user-at-host)
759 "Get password from password pool."
761 (if (not elmo-passwd-alist)
762 (setq elmo-passwd-alist (elmo-passwd-alist-load)))
763 (setq data (assoc user-at-host elmo-passwd-alist))
765 (elmo-base64-decode-string (cdr data))
766 (setq pass (elmo-read-passwd (format "Password for %s: "
768 (setq elmo-passwd-alist
769 (append elmo-passwd-alist
770 (list (cons user-at-host
771 (elmo-base64-encode-string pass)))))
774 (defun elmo-remove-passwd (user-at-host)
775 "Remove password from password pool (for failure)."
776 (setq elmo-passwd-alist
777 (delete (assoc user-at-host elmo-passwd-alist)
781 (defmacro elmo-read-char-exclusive ()
782 (cond ((featurep 'xemacs)
783 '(let ((table (quote ((backspace . ?\C-h) (delete . ?\C-?)
788 (key-press-event-p (setq event (next-command-event)))
789 (setq key (or (event-to-character event)
790 (cdr (assq (event-key event) table)))))))
792 ((fboundp 'read-char-exclusive)
793 '(read-char-exclusive))
797 (defun elmo-read-passwd (prompt &optional stars)
798 "Read a single line of text from user without echoing, and return it."
802 (cursor-in-echo-area t)
803 (log-message-max-size 0)
804 message-log-max done msg truncate)
806 (if (or (not stars) (string= "" ans))
808 (setq msg (concat prompt (make-string (length ans) ?.)))
810 (1+ (- (length msg) (window-width (minibuffer-window)))))
812 (setq msg (concat "$" (substring msg (1+ truncate))))))
814 (setq c (elmo-read-char-exclusive))
818 ((or (= c ?\r) (= c ?\n) (= c ?\e))
822 ((and (/= c ?\b) (/= c ?\177))
823 (setq ans (concat ans (char-to-string c))))
825 (setq ans (substring ans 0 -1)))))
835 (defun elmo-replace-in-string (str regexp newtext &optional literal)
836 "Replaces all matches in STR for REGEXP with NEWTEXT string,
837 and returns the new string.
838 Optional LITERAL non-nil means do a literal replacement.
839 Otherwise treat \\ in NEWTEXT string as special:
840 \\& means substitute original matched text,
841 \\N means substitute match for \(...\) number N,
842 \\\\ means insert one \\."
847 (while (setq match (string-match regexp str start))
848 (setq prev-start start
853 (substring str prev-start match)
854 (cond (literal newtext)
861 (cond ((eq c ?\\) "\\")
863 (elmo-match-string 0 str))
864 ((and (>= c ?0) (<= c ?9))
865 (if (> c (+ ?0 (length
868 (error "Invalid match num: %c" c)
870 (elmo-match-string c str)))
871 (t (char-to-string c))))
872 (if (eq c ?\\) (progn (setq special t) nil)
873 (char-to-string c)))))
875 (concat rtn-str (substring str start))))
877 (defun elmo-string-to-list (string)
880 (goto-char (point-min))
882 (goto-char (point-max))
884 (goto-char (point-min))
885 (read (current-buffer))))
887 (defun elmo-plug-on-by-servers (alist &optional servers)
888 (let ((server-list (or servers elmo-plug-on-servers)))
891 (if (elmo-plugged-p (car server-list))
893 (setq server-list (cdr server-list))))))
895 (defun elmo-plug-on-by-exclude-servers (alist &optional servers)
896 (let ((server-list (or servers elmo-plug-on-exclude-servers))
897 server other-servers)
899 (when (and (not (member (setq server (caaar alist)) server-list))
900 (not (member server other-servers)))
901 (push server other-servers))
902 (setq alist (cdr alist)))
903 (elmo-plug-on-by-servers alist other-servers)))
905 (defun elmo-plugged-p (&optional server port alist label-exp)
906 (let ((alist (or alist elmo-plugged-alist))
908 (cond ((and (not port) (not server))
909 (cond ((eq elmo-plugged-condition 'one)
912 (if (nth 2 (car alist))
914 (setq alist (cdr alist)))))
915 ((eq elmo-plugged-condition 'all)
918 (if (not (nth 2 (car alist)))
919 (throw 'plugged nil))
920 (setq alist (cdr alist)))
922 ((functionp elmo-plugged-condition)
923 (funcall elmo-plugged-condition alist))
926 ((not port) ;; server
929 (when (string= server (caaar alist))
930 (if (nth 2 (car alist))
932 (setq alist (cdr alist)))))
934 (setq plugged-info (assoc (cons server port) alist))
935 (if (not plugged-info)
936 ;; add elmo-plugged-alist automatically
938 (elmo-set-plugged elmo-plugged server port nil nil label-exp)
940 (if (and elmo-auto-change-plugged
941 (> elmo-auto-change-plugged 0)
942 (nth 3 plugged-info) ;; time
943 (elmo-time-expire (nth 3 plugged-info)
944 elmo-auto-change-plugged))
946 (nth 2 plugged-info)))))))
948 (defun elmo-set-plugged (plugged &optional server port time
950 (let ((alist (or alist elmo-plugged-alist))
952 (cond ((and (not port) (not server))
953 (setq elmo-plugged plugged)
954 ;; set plugged all element of elmo-plugged-alist.
956 (setcdr (cdar alist) (list plugged time))
957 (setq alist (cdr alist))))
959 ;; set plugged all port of server
961 (when (string= server (caaar alist))
962 (setcdr (cdar alist) (list plugged time)))
963 (setq alist (cdr alist))))
965 ;; set plugged one port of server
966 (setq plugged-info (assoc (cons server port) alist))
967 (setq label (if label-exp
969 (nth 1 plugged-info)))
971 ;; if add is non-nil, don't reset plug state.
973 (setcdr plugged-info (list label plugged time)))
975 (setq elmo-plugged-alist
976 (nconc elmo-plugged-alist
978 (list (cons server port) label plugged time))))))))
981 (defun elmo-delete-plugged (&optional server port alist)
982 (let* ((alist (or alist elmo-plugged-alist))
984 (cond ((and (not port) (not server))
987 ;; delete plugged all port of server
989 (when (string= server (caaar alist2))
990 (setq alist (delete (car alist2) alist)))
991 (setq alist2 (cdr alist2))))
993 ;; delete plugged one port of server
995 (delete (assoc (cons server port) alist)) alist)))
998 (defun elmo-disk-usage (path)
999 "Get disk usage (bytes) in PATH."
1001 (condition-case () (file-attributes path) (error nil))))
1003 (if (nth 0 file-attr) ; directory
1004 (let ((files (condition-case ()
1005 (directory-files path t "^[^\\.]")
1008 ;; (result (nth 7 file-attr))) ... directory size
1010 (setq result (+ result (or (elmo-disk-usage (car files)) 0)))
1011 (setq files (cdr files)))
1013 (float (nth 7 file-attr))))))
1015 (defun elmo-get-last-accessed-time (path &optional dir)
1016 "Returns last accessed time."
1017 (let ((last-accessed (nth 4 (file-attributes (or (and dir
1022 (setq last-accessed (+ (* (nth 0 last-accessed)
1023 (float 65536)) (nth 1 last-accessed)))
1026 (defun elmo-get-last-modification-time (path &optional dir)
1027 "Returns last accessed time."
1028 (let ((last-modified (nth 5 (file-attributes (or (and dir
1032 (setq last-modified (+ (* (nth 0 last-modified)
1033 (float 65536)) (nth 1 last-modified)))))
1035 (defun elmo-make-directory (path)
1036 "create directory recursively."
1037 (let ((parent (directory-file-name (file-name-directory path))))
1038 (if (null (file-directory-p parent))
1039 (elmo-make-directory parent))
1040 (make-directory path)
1041 (if (string= path (expand-file-name elmo-msgdb-dir))
1042 (set-file-modes path 448) ; 700
1045 (defun elmo-delete-directory (path &optional no-hierarchy)
1046 "delete directory recursively."
1047 (let ((dirent (directory-files path))
1048 relpath abspath hierarchy)
1050 (setq relpath (car dirent)
1052 abspath (expand-file-name relpath path))
1053 (when (not (string-match "^\\.\\.?$" relpath))
1054 (if (eq (nth 0 (file-attributes abspath)) t)
1057 (elmo-delete-directory abspath no-hierarchy))
1058 (delete-file abspath))))
1060 (delete-directory path))))
1062 (defun elmo-list-filter (l1 l2)
1065 ;; t means filter all.
1068 (elmo-delete-if (lambda (x) (not (memq x l1))) l2)
1072 (defun elmo-folder-local-p (folder)
1073 "Return whether FOLDER is a local folder or not."
1074 (let ((type (elmo-folder-get-type folder)))
1075 (memq type '(localdir localnews archive maildir internal cache))))
1077 (defun elmo-folder-writable-p (folder)
1078 (let ((type (elmo-folder-get-type folder)))
1079 (memq type '(imap4 localdir archive))))
1081 (defun elmo-multi-get-intlist-list (numlist &optional as-is)
1082 (let ((numbers (sort numlist '<))
1084 one-list int-list-list)
1086 (setq cur-number (+ cur-number 1))
1091 (* elmo-multi-divide-number cur-number))
1092 elmo-multi-divide-number)))
1093 (setq one-list (nconc
1099 (* elmo-multi-divide-number cur-number))))))
1100 (setq numbers (cdr numbers)))
1101 (setq int-list-list (nconc int-list-list (list one-list))))
1104 (defsubst elmo-list-delete-if-smaller (list number)
1105 (let ((ret-val (copy-sequence list)))
1107 (if (< (car list) number)
1108 (setq ret-val (delq (car list) ret-val)))
1109 (setq list (cdr list)))
1112 (defun elmo-list-diff (list1 list2 &optional mes)
1115 (let ((clist1 (copy-sequence list1))
1116 (clist2 (copy-sequence list2)))
1118 (setq clist1 (delq (car list2) clist1))
1119 (setq list2 (cdr list2)))
1121 (setq clist2 (delq (car list1) clist2))
1122 (setq list1 (cdr list1)))
1124 (message (concat mes "done.")))
1125 (list clist1 clist2)))
1127 (defun elmo-list-bigger-diff (list1 list2 &optional mes)
1128 "Returns a list (- +). + is bigger than max of LIST1, in LIST2"
1133 (max-of-l2 (or (nth (max 0 (1- (length l2))) l2) 0))
1137 (setq num (+ (length l1)))
1139 (if (memq (car l1) l2)
1140 (if (eq (car l1) (car l2))
1143 (if (> (car l1) max-of-l2)
1144 (setq diff1 (nconc diff1 (list (car l1))))))
1148 (setq percent (/ (* i 100) num))
1149 (if (eq (% percent 5) 0)
1150 (elmo-display-progress
1151 'elmo-list-bigger-diff "%s%d%%" percent mes))))
1153 (cons diff1 (list l2)))))
1155 (defun elmo-multi-list-bigger-diff (list1 list2 &optional mes)
1156 (let ((list1-list (elmo-multi-get-intlist-list list1 t))
1157 (list2-list (elmo-multi-get-intlist-list list2 t))
1160 (while (or list1-list list2-list)
1161 (setq result (elmo-list-bigger-diff (car list1-list) (car list2-list)
1163 (setq dels (append dels (car result)))
1164 (setq news (append news (cadr result)))
1165 (setq list1-list (cdr list1-list))
1166 (setq list2-list (cdr list2-list)))
1167 (cons dels (list news))))
1169 (defvar elmo-imap4-name-space-regexp-list nil)
1170 (defun elmo-imap4-identical-name-space-p (fld1 fld2)
1172 (if (or (eq (string-to-char fld1) ?#)
1173 (eq (string-to-char fld2) ?#))
1174 (string= (car (split-string fld1 "/"))
1175 (car (split-string fld2 "/")))
1178 (defun elmo-folder-identical-system-p (folder1 folder2)
1179 "folder1 and folder2 should be real folder (not virtual)."
1180 (cond ((eq (elmo-folder-get-type folder1) 'imap4)
1181 (let ((spec1 (elmo-folder-get-spec folder1))
1182 (spec2 (elmo-folder-get-spec folder2)))
1183 (and (elmo-imap4-identical-name-space-p
1184 (nth 1 spec1) (nth 1 spec2))
1185 (string= (elmo-imap4-spec-hostname spec1)
1186 (elmo-imap4-spec-hostname spec2)) ; hostname
1187 (string= (elmo-imap4-spec-username spec1)
1188 (elmo-imap4-spec-username spec2))))) ; username
1190 (elmo-folder-direct-copy-p folder1 folder2))))
1192 (defconst elmo-folder-direct-copy-alist
1193 '((localdir . (localdir localnews archive))
1194 (maildir . (maildir localdir localnews archive))
1195 (localnews . (localdir localnews archive))
1196 (archive . (localdir localnews archive))
1197 (cache . (localdir localnews archive))))
1199 (defun elmo-folder-direct-copy-p (src-folder dst-folder)
1200 (let ((src-type (car (elmo-folder-get-spec src-folder)))
1201 (dst-type (car (elmo-folder-get-spec dst-folder)))
1203 (and (setq dst-copy-type
1204 (cdr (assq src-type elmo-folder-direct-copy-alist)))
1205 (memq dst-type dst-copy-type))))
1207 (defmacro elmo-filter-type (filter)
1208 (` (aref (, filter) 0)))
1210 (defmacro elmo-filter-key (filter)
1211 (` (aref (, filter) 1)))
1213 (defmacro elmo-filter-value (filter)
1214 (` (aref (, filter) 2)))
1216 (defsubst elmo-buffer-field-condition-match (condition)
1220 (goto-char (point-min))
1221 (setq term (car condition))
1223 ((and (eq (elmo-filter-type term) 'date)
1224 (string= (elmo-filter-key term) "since"))
1225 (let ((date (elmo-date-get-datevec (elmo-filter-value term))))
1227 (timezone-make-sortable-date (aref date 0)
1230 (timezone-make-time-string
1234 (timezone-make-date-sortable (std11-field-body "date")))
1236 ((and (eq (elmo-filter-type term) 'date)
1237 (string= (elmo-filter-key term) "before"))
1238 (let ((date (elmo-date-get-datevec (elmo-filter-value term))))
1240 (timezone-make-date-sortable (std11-field-body "date"))
1241 (timezone-make-sortable-date (aref date 0)
1244 (timezone-make-time-string
1249 ((eq (elmo-filter-type term) 'match)
1250 (if (string= "body" (elmo-filter-key term))
1252 (re-search-forward "^$" nil t) ; goto body
1253 (if (search-forward (elmo-filter-value term) nil t)
1255 (let ((fval (eword-decode-string
1256 (or (std11-field-body (elmo-filter-key term)) ""))))
1257 (if (and fval (string-match (elmo-filter-value term)
1260 ((eq (elmo-filter-type term) 'unmatch)
1261 (if (string= "body" (elmo-filter-key term))
1263 (re-search-forward "^$" nil t) ; goto body
1264 (if (not (search-forward (elmo-filter-value term) nil t))
1266 (let ((fval (eword-decode-string
1267 (or (std11-field-body (elmo-filter-key term)) ""))))
1269 (if (not (string-match (elmo-filter-value term)
1272 (throw 'done t)))))) ; OK?
1273 (setq condition (cdr condition)))
1274 (throw 'done nil))))
1276 (defsubst elmo-file-field-condition-match (file condition)
1278 (as-binary-input-file
1279 (insert-file-contents file))
1280 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
1281 (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
1282 (elmo-buffer-field-condition-match condition)))
1284 (defun elmo-cross-device-link-error-p (err)
1289 (if (and (stringp (setq cur (car errobj)))
1290 (or (string-match "cross-device" cur)
1291 (string-match "operation not supported" cur)))
1293 (setq errobj (cdr errobj)))
1296 (defmacro elmo-get-hash-val (string hashtable)
1297 (let ((sym (list 'intern-soft string hashtable)))
1298 (list 'if (list 'boundp sym)
1299 (list 'symbol-value sym))))
1301 (defmacro elmo-set-hash-val (string value hashtable)
1302 (list 'set (list 'intern string hashtable) value))
1304 ;; Make a hash table (default and minimum size is 1024).
1305 (defun elmo-make-hash (&optional hashsize)
1306 (make-vector (if hashsize (max (elmo-create-hash-size hashsize) 1024) 1024) 0))
1308 (defsubst elmo-mime-string (string)
1309 "Normalize MIME encoded string."
1313 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
1314 (setq str (eword-decode-string
1315 (decode-mime-charset-string string elmo-mime-charset)))
1316 (setq str (encode-mime-charset-string str elmo-mime-charset))
1317 (elmo-set-buffer-multibyte nil)
1320 (defsubst elmo-collect-field (beg end downcase-field-name)
1323 (narrow-to-region beg end)
1324 (goto-char (point-min))
1325 (let ((regexp (concat "\\(" std11-field-head-regexp "\\)[ \t]*"))
1327 (while (re-search-forward regexp nil t)
1328 (setq name (buffer-substring-no-properties
1329 (match-beginning 1)(1- (match-end 1))))
1330 (if downcase-field-name
1331 (setq name (downcase name)))
1332 (setq body (buffer-substring-no-properties
1333 (match-end 0) (std11-field-end)))
1334 (or (assoc name dest)
1335 (setq dest (cons (cons name body) dest))))
1338 (defsubst elmo-collect-field-from-string (string downcase-field-name)
1341 (goto-char (point-min))
1342 (let ((regexp (concat "\\(" std11-field-head-regexp "\\)[ \t]*"))
1344 (while (re-search-forward regexp nil t)
1345 (setq name (buffer-substring-no-properties
1346 (match-beginning 1)(1- (match-end 1))))
1347 (if downcase-field-name
1348 (setq name (downcase name)))
1349 (setq body (buffer-substring-no-properties
1350 (match-end 0) (std11-field-end)))
1351 (or (assoc name dest)
1352 (setq dest (cons (cons name body) dest))))
1355 (defun elmo-create-hash-size (min)
1361 (defun elmo-safe-filename (folder)
1362 (elmo-replace-in-string
1363 (elmo-replace-in-string
1364 (elmo-replace-in-string folder "/" " ")
1368 (defvar elmo-msgid-replace-chars nil)
1370 (defsubst elmo-replace-msgid-as-filename (msgid)
1371 "Replace message-id string as filename."
1372 (setq msgid (elmo-replace-in-string msgid " " " "))
1373 (if (null elmo-msgid-replace-chars)
1374 (setq elmo-msgid-replace-chars
1375 (regexp-quote (mapconcat
1376 'car elmo-msgid-replace-string-alist ""))))
1377 (while (string-match (concat "[" elmo-msgid-replace-chars "]")
1380 (substring msgid 0 (match-beginning 0))
1383 (match-beginning 0) (match-end 0))
1384 elmo-msgid-replace-string-alist))
1385 (substring msgid (match-end 0)))))
1388 (defsubst elmo-recover-msgid-from-filename (filename)
1389 "Recover Message-ID from filename."
1391 (while (string-match " " filename)
1392 (setq tmp (substring filename
1394 (+ (match-end 0) 1)))
1395 (if (string= tmp " ")
1397 (setq tmp (car (rassoc tmp
1398 elmo-msgid-replace-string-alist))))
1401 (substring filename 0 (match-beginning 0))
1403 (setq filename (substring filename (+ (match-end 0) 1))))
1404 (concat result filename)))
1406 (defsubst elmo-copy-file (src dst)
1408 (elmo-add-name-to-file src dst t)
1409 (error (if (elmo-cross-device-link-error-p err)
1410 (copy-file src dst t)
1411 (error "copy file failed")))))
1413 (defmacro elmo-buffer-exists-p (buffer)
1415 (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
1418 (defmacro elmo-kill-buffer (buffer)
1419 (` (when (elmo-buffer-exists-p (, buffer))
1420 (kill-buffer (, buffer)))))
1422 (defun elmo-delete-if (pred lst)
1423 "Returns new list contains items which don't satisfy PRED in LST."
1426 (unless (funcall pred (car lst))
1427 (setq result (nconc result (list (car lst)))))
1428 (setq lst (cdr lst)))
1431 (defun elmo-list-delete (list1 list2)
1432 "Delete by side effect any occurrences equal to elements of LIST1 from LIST2.
1433 Return the modified LIST2. Deletion is done with `delete'.
1434 Write `(setq foo (elmo-list-delete bar foo))' to be sure of changing
1435 the value of `foo'."
1437 (setq list2 (delete (car list1) list2))
1438 (setq list1 (cdr list1)))
1441 (defun elmo-list-member (list1 list2)
1442 "If any element of list1 is member of list2, returns t."
1445 (if (member (car list1) list2)
1447 (setq list1 (cdr list1)))))
1449 (defun elmo-count-matches (regexp beg end)
1453 (while (re-search-forward regexp end t)
1454 (setq count (1+ count)))
1457 (if (fboundp 'display-error)
1458 (defalias 'elmo-display-error 'display-error)
1459 (defun elmo-display-error (error-object stream)
1460 "a tiny function to display error-object to the stream."
1462 (errobj error-object)
1465 (setq err-mes (concat err-mes (format
1466 (if (stringp (car errobj))
1468 (if (boundp 'nemacs-version)
1470 "%S")) (car errobj))))
1471 (setq errobj (cdr errobj))
1472 (if errobj (setq err-mes (concat err-mes (if first ": " ", "))))
1474 (princ err-mes stream))))
1476 (if (fboundp 'lprogress-display)
1477 (defalias 'elmo-display-progress 'lprogress-display)
1478 (defun elmo-display-progress (label format &optional value &rest args)
1479 "Print a progress message."
1480 (if (and (null format) (null args))
1482 (apply (function message) (concat format " %d%%")
1483 (nconc args (list value))))))
1485 (defun elmo-time-expire (before-time diff-time)
1486 (let* ((current (current-time))
1487 (rest (when (< (nth 1 current) (nth 1 before-time))
1491 (list (- (+ (car current) (if rest -1 0)) (car before-time))
1492 (- (+ (or rest 0) (nth 1 current)) (nth 1 before-time))))
1493 (and (eq (car diff) 0)
1494 (< diff-time (nth 1 diff)))))
1496 (defun elmo-open-network-stream (name buffer host service ssl)
1497 (let ((auto-plugged (and elmo-auto-change-plugged
1498 (> elmo-auto-change-plugged 0)))
1500 (if (eq ssl 'starttls)
1502 (if ssl (require 'ssl)))
1504 (let (process-connection-type)
1506 (if (eq ssl 'starttls)
1507 (starttls-open-stream name buffer host service)
1509 (open-ssl-stream name buffer host service)
1510 (open-network-stream name buffer host service)))))
1513 (elmo-set-plugged nil host service (current-time))
1514 (message "Auto plugged off at %s:%d" host service)
1516 (signal (car err) (cdr err))))
1518 (process-kill-without-query process)
1520 (elmo-set-plugged t host service))
1523 (if (fboundp 'std11-fetch-field)
1524 (defalias 'elmo-field-body 'std11-fetch-field) ;;no narrow-to-region
1525 (defalias 'elmo-field-body 'std11-field-body))
1527 (defmacro elmo-string (string)
1528 "String without text property"
1529 (` (let ((obj (copy-sequence (, string))))
1530 (set-text-properties 0 (length obj) nil obj)
1533 (defun elmo-y-or-n-p (prompt &optional auto default)
1534 "Same as `y-or-n-p'.
1535 But if optional argument AUTO is non-nil, DEFAULT is returned."
1540 (defun elmo-string-member (string slist)
1541 "Returns t if STRING is a member of the SLIST."
1544 (if (and (stringp (car slist))
1545 (string= string (car slist)))
1547 (setq slist (cdr slist)))))
1549 (defun elmo-string-match-member (str list &optional case-ignore)
1550 (let ((case-fold-search case-ignore))
1553 (if (string-match (car list) str)
1554 (throw 'member (car list)))
1555 (setq list (cdr list))))))
1557 (defsubst elmo-string-delete-match (string pos)
1558 (concat (substring string
1559 0 (match-beginning pos))
1564 (defun elmo-string-match-assoc (key alist &optional case-ignore)
1565 (let ((case-fold-search case-ignore)
1569 (setq a (car alist))
1572 (string-match key (car a)))
1574 (setq alist (cdr alist))))))
1576 (defun elmo-string-matched-assoc (key alist &optional case-ignore)
1577 (let ((case-fold-search case-ignore)
1581 (setq a (car alist))
1584 (string-match (car a) key))
1586 (setq alist (cdr alist))))))
1588 (defun elmo-string-assoc (key alist)
1592 (setq a (car alist))
1595 (string= key (car a)))
1597 (setq alist (cdr alist))))))
1599 (defun elmo-string-rassoc (key alist)
1603 (setq a (car alist))
1606 (string= key (cdr a)))
1608 (setq alist (cdr alist))))))
1610 (provide 'elmo-util)
1612 ;;; elmo-util.el ends here