* modb-standard.el (elmo-msgdb-list-flagged): Use append instead
[elisp/wanderlust.git] / elmo / elmo-util.el
index 9dffada..5a7a1bc 100644 (file)
@@ -38,6 +38,7 @@
 (require 'eword-decode)
 (require 'utf7)
 (require 'poem)
+(require 'emu)
 
 (defmacro elmo-set-buffer-multibyte (flag)
   "Set the multibyte flag of the current buffer to FLAG."
@@ -354,9 +355,6 @@ Return value is a cons cell of (STRUCTURE . REST)"
          (nconc list rest))
       (nconc list (list element)))))
 
-(defun elmo-string-partial-p (string)
-  (and (stringp string) (string-match "message/partial" string)))
-
 (defun elmo-get-file-string (filename &optional remove-final-newline)
   (elmo-set-work-buf
    (let (insert-file-contents-pre-hook   ; To avoid autoconv-xmas...
@@ -420,6 +418,9 @@ Return value is a cons cell of (STRUCTURE . REST)"
 (defun elmo-passwd-alist-clear ()
   "Clear password cache."
   (interactive)
+  (dolist (pair elmo-passwd-alist)
+    (when (stringp (cdr-safe pair))
+      (fillarray (cdr pair) 0)))
   (setq elmo-passwd-alist nil))
 
 (defun elmo-passwd-alist-save ()
@@ -467,12 +468,11 @@ Return value is a cons cell of (STRUCTURE . REST)"
 (defun elmo-remove-passwd (key)
   "Remove password from password pool (for failure)."
   (let (pass-cons)
-    (if (setq pass-cons (assoc key elmo-passwd-alist))
-       (progn
-         (unwind-protect
-             (fillarray (cdr pass-cons) 0))
-         (setq elmo-passwd-alist
-               (delete pass-cons elmo-passwd-alist))))))
+    (while (setq pass-cons (assoc key elmo-passwd-alist))
+      (unwind-protect
+         (fillarray (cdr pass-cons) 0)
+       (setq elmo-passwd-alist
+             (delete pass-cons elmo-passwd-alist))))))
 
 (defmacro elmo-read-char-exclusive ()
   (cond ((featurep 'xemacs)
@@ -863,11 +863,12 @@ the directory becomes empty after deletion."
           (setq result (search-forward (elmo-filter-value condition)
                                        nil t))))
      (t
-      (let ((fval (std11-field-body (elmo-filter-key condition))))
+      (dolist (fval (elmo-multiple-field-body (elmo-filter-key condition)))
        (if (eq (length fval) 0) (setq fval nil))
        (if fval (setq fval (eword-decode-string fval)))
-       (setq result (and fval (string-match
-                               (elmo-filter-value condition) fval))))))
+       (setq result (or result
+                        (and fval (string-match
+                                   (elmo-filter-value condition) fval)))))))
     (if (eq (elmo-filter-type condition) 'unmatch)
        (setq result (not result)))
     result))
@@ -953,14 +954,14 @@ the directory becomes empty after deletion."
         file (nth 2 condition) number number-list)))))
 
 (defmacro elmo-get-hash-val (string hashtable)
-  `(and (stringp ,string)
-       ,hashtable
-       (let ((sym (intern-soft ,string ,hashtable)))
-         (if (boundp sym)
-             (symbol-value sym)))))
+  (static-if (fboundp 'unintern)
+      `(symbol-value (intern-soft ,string ,hashtable))
+    `(let ((sym (intern-soft ,string ,hashtable)))
+       (and (boundp sym)
+           (symbol-value sym)))))
 
 (defmacro elmo-set-hash-val (string value hashtable)
-  (list 'set (list 'intern string hashtable) value))
+  `(set (intern ,string ,hashtable) ,value))
 
 (defmacro elmo-clear-hash-val (string hashtable)
   (static-if (fboundp 'unintern)
@@ -1257,6 +1258,11 @@ SPEC is a list as followed (LABEL MAX-VALUE [FORMAT])."
     (defalias 'elmo-field-body 'std11-fetch-field) ;;no narrow-to-region
   (defalias 'elmo-field-body 'std11-field-body))
 
+(defun elmo-unfold-field-body (name)
+  (let ((value (elmo-field-body name)))
+    (and value
+        (std11-unfold-string value))))
+
 (defun elmo-address-quote-specials (word)
   "Make quoted string of WORD if needed."
   (let ((lal (std11-lexical-analyze word)))
@@ -1295,7 +1301,7 @@ But if optional argument AUTO is non-nil, DEFAULT is returned."
          (throw 'found t))
       (setq slist (cdr slist)))))
 
-(cond ((fboundp 'member-ignore-case)
+(static-cond ((fboundp 'member-ignore-case)
        (defalias 'elmo-string-member-ignore-case 'member-ignore-case))
       ((fboundp 'compare-strings)
        (defun elmo-string-member-ignore-case (elt list)
@@ -1755,9 +1761,10 @@ associated with SECTION."
         (method (completing-read (format "Expire by (%s): "
                                          elmo-cache-expire-default-method)
                                  '(("size" . "size")
-                                   ("age" . "age")))))
-    (if (string= method "")
-       (setq method elmo-cache-expire-default-method))
+                                   ("age" . "age"))
+                                 nil t)))
+    (when (string= method "")
+      (setq method elmo-cache-expire-default-method))
     (funcall (intern (concat "elmo-cache-expire-by-" method)))))
 
 (defun elmo-read-float-value-from-minibuffer (prompt &optional initial)
@@ -1996,7 +2003,7 @@ If ALIST is nil, `elmo-obsolete-variable-alist' is used."
          (concat "<" msgid ">")) ; Invaild message-id.
       ;; no message-id, so put dummy msgid.
       (concat "<" (timezone-make-date-sortable
-                  (elmo-field-body "date"))
+                  (elmo-unfold-field-body "date"))
              (nth 1 (eword-extract-address-components
                      (or (elmo-field-body "from") "nobody"))) ">"))))