1 ;;; mew-cache.el --- Cache management for Mew
3 ;; Author: Kazu Yamamoto <Kazu@Mew.org>
4 ;; Created: Mar 23, 1997
5 ;; Revised: Aug 31, 1999
9 (defconst mew-cache-version "mew-cache.el version 0.08")
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ;; Prepare new message --- caching
18 (defmacro mew-cache-decode-syntax (buf)
23 (defmacro mew-cache-decode-error (buf)
28 (defmacro mew-cache-multi-form (buf)
31 mew-syntax-multi-form)))
33 (defmacro mew-cache-icon-spec (buf)
36 mew-syntax-icon-spec)))
38 (defmacro mew-cache-privacy-result (buf)
41 mew-syntax-privacy-result)))
44 "A list of decoded messages cache.
45 The (new ... old) order of ((\"+folder\" . \"message\") . cache-buffer)")
47 (defmacro mew-cache-buffer-get (entry)
50 (defmacro mew-cache-entry-make (fld-msg buf)
51 (` (cons (, fld-msg) (, buf))))
53 (defmacro mew-cache-hit (fld-msg)
54 "Return value associated with key."
55 (` (mew-cache-buffer-get (assoc (, fld-msg) mew-cache))))
57 (defun mew-cache-sort (entry)
58 (setq mew-cache (cons entry (delete entry mew-cache))))
60 (defun mew-cache-add (fld-msg)
61 "Adding (fld-msg . buf) to the top of 'mew-cache'.
62 Returning its cache buffer."
63 (let ((len (length mew-cache))
65 (if (< len mew-cache-size)
66 (setq buf (get-buffer-create (format "%s%d" mew-buffer-cache len)))
67 (setq buf (mew-cache-buffer-get (nth (1- len) mew-cache)))
68 (setcdr (nthcdr (- len 2) mew-cache) nil))
69 (setq mew-cache (cons (mew-cache-entry-make fld-msg buf) mew-cache))
72 (defun mew-cache-delete ()
73 "Delete the most recent cache entry."
74 (let ((buf (mew-cache-buffer-get (car mew-cache))))
75 ;; must preserve the buffer itself because the buffer creation
76 ;; depends on the length of mew-cache.
77 (setq mew-cache (nconc (cdr mew-cache)
78 (list (mew-cache-entry-make nil buf))))))
81 (defmacro mew-cache-attribute-get (file)
82 (` (list (mew-file-get-time (, file)) (mew-file-get-size (, file)))))
84 (defun mew-cache-message (fld msg &optional force)
85 (let* ((fld-msg (cons fld msg))
86 (hit (mew-cache-hit fld-msg))
87 (file (mew-expand-folder fld msg))
91 (mew-cache-sort (mew-cache-entry-make fld-msg hit))
93 (if (or (and (mew-folder-localp fld)
94 (not (equal mew-cache-attribute ;; buffer-local
95 (mew-cache-attribute-get file))))
96 (and force mew-decode-not-decrypted)
97 (and force mew-decode-error))
100 (setq hit (mew-cache-add fld-msg))
107 (setq mew-cache-folder fld)
108 (setq mew-cache-message-number msg)
109 (if (mew-folder-localp fld)
110 (setq mew-cache-attribute (mew-cache-attribute-get file))
111 (setq mew-cache-attribute nil))
113 (let ((mew-header-max-length nil)
114 (mew-header-max-depth nil))
115 (mew-decode fld msg))
116 (mew-decode fld msg)))
119 (message "MIME decoding for %s/%s is quitted." fld msg)
120 nil))) ;; will not be used
121 hit)) ;; retrun value
123 (defun mew-cache-clean-up ()
124 "A function to flush all decoded messages in cache list."
126 (mew-decode-syntax-delete)
128 (while (< n mew-cache-size)
129 (mew-kill-buffer (format "%s%d" mew-buffer-cache n))
131 (mew-current-set 'cache nil)
132 (mew-current-set 'message nil)
133 (mew-current-set 'part nil)
134 (setq mew-cache nil))
136 (fset 'mew-cache-flush (symbol-function 'mew-cache-clean-up))
140 ;;; Copyright Notice:
142 ;; Copyright (C) 1997, 1998, 1999 Mew developing team.
143 ;; All rights reserved.
145 ;; Redistribution and use in source and binary forms, with or without
146 ;; modification, are permitted provided that the following conditions
149 ;; 1. Redistributions of source code must retain the above copyright
150 ;; notice, this list of conditions and the following disclaimer.
151 ;; 2. Redistributions in binary form must reproduce the above copyright
152 ;; notice, this list of conditions and the following disclaimer in the
153 ;; documentation and/or other materials provided with the distribution.
154 ;; 3. Neither the name of the team nor the names of its contributors
155 ;; may be used to endorse or promote products derived from this software
156 ;; without specific prior written permission.
158 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
159 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
160 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
161 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
162 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
163 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
164 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
165 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
166 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
167 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
168 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
170 ;;; mew-cache.el ends here