* wl-summary.el (wl-summary-detect-mark-position): Use
[elisp/wanderlust.git] / elmo / modb-legacy.el
index 3104ccf..bbd7a21 100644 (file)
 ;;;
 ;; Internal use only (obsolete interface)
 ;;
-;;
-;; mime decode cache
-;;
-(defvar elmo-msgdb-decoded-cache-hashtb nil)
-(make-variable-buffer-local 'elmo-msgdb-decoded-cache-hashtb)
-
-(defsubst elmo-msgdb-get-decoded-cache (string)
-  (if elmo-use-decoded-cache
-      (let ((hashtb (or elmo-msgdb-decoded-cache-hashtb
-                       (setq elmo-msgdb-decoded-cache-hashtb
-                             (elmo-make-hash 2048))))
-           decoded)
-       (or (elmo-get-hash-val string hashtb)
-           (progn
-             (elmo-set-hash-val
-              string
-              (setq decoded
-                    (decode-mime-charset-string string elmo-mime-charset))
-              hashtb)
-             decoded)))
-    (decode-mime-charset-string string elmo-mime-charset)))
-
 (defsubst elmo-msgdb-overview-entity-get-id (entity)
   (and entity (car entity)))
 
@@ -609,247 +587,6 @@ Return a list of message numbers which have duplicated message-ids."
         ((numberp key) (format "#%d" key)))
    (elmo-msgdb-get-entity-hashtb msgdb)))
 
-;;; Message entity handling.
-(defsubst modb-legacy-make-message-entity (args)
-  "Make an message entity."
-  (cons (plist-get args :message-id)
-       (vector (plist-get args :number)
-               (plist-get args :references)
-               (plist-get args :from)
-               (plist-get args :subject)
-               (plist-get args :date)
-               (plist-get args :to)
-               (plist-get args :cc)
-               (plist-get args :size)
-               (plist-get args :extra))))
-
-(luna-define-method elmo-msgdb-make-message-entity ((msgdb modb-legacy)
-                                                   args)
-  (modb-legacy-make-message-entity args))
-
-(luna-define-method elmo-msgdb-create-message-entity-from-buffer
-  ((msgdb modb-legacy) number args)
-  (let ((extras elmo-msgdb-extra-fields)
-       (default-mime-charset default-mime-charset)
-       entity message-id references from subject to cc date
-       extra field-body charset size)
-    (save-excursion
-      (setq entity (modb-legacy-make-message-entity args))
-      (elmo-set-buffer-multibyte default-enable-multibyte-characters)
-      (setq message-id (elmo-msgdb-get-message-id-from-buffer))
-      (and (setq charset (cdr (assoc "charset" (mime-read-Content-Type))))
-          (setq charset (intern-soft charset))
-          (setq default-mime-charset charset))
-      (setq references
-           (or (elmo-msgdb-get-last-message-id
-                (elmo-field-body "in-reply-to"))
-               (elmo-msgdb-get-last-message-id
-                (elmo-field-body "references")))
-           from (elmo-replace-in-string
-                 (elmo-mime-string (or (elmo-field-body "from")
-                                       elmo-no-from))
-                 "\t" " ")
-           subject (elmo-replace-in-string
-                    (elmo-mime-string (or (elmo-field-body "subject")
-                                          elmo-no-subject))
-                    "\t" " ")
-           date (elmo-field-body "date")
-           to   (mapconcat 'identity (elmo-multiple-field-body "to") ",")
-           cc   (mapconcat 'identity (elmo-multiple-field-body "cc") ","))
-      (unless (elmo-msgdb-message-entity-field msgdb entity 'size)
-       (if (setq size (elmo-field-body "content-length"))
-           (setq size (string-to-int size))
-         (setq size 0)))
-      (while extras
-       (if (setq field-body (elmo-field-body (car extras)))
-           (elmo-msgdb-message-entity-set-field
-            msgdb entity (intern (downcase (car extras))) field-body))
-       (setq extras (cdr extras)))
-      (dolist (field '(message-id number references from subject
-                                 date to cc size))
-       (when (symbol-value field)
-         (elmo-msgdb-message-entity-set-field
-          msgdb entity field (symbol-value field))))
-      entity)))
-
-;;; Message entity interface
-;;
-(luna-define-method elmo-msgdb-message-entity-number ((msgdb modb-legacy)
-                                                     entity)
-  (and entity (aref (cdr entity) 0)))
-
-(luna-define-method elmo-msgdb-message-entity-set-number ((msgdb modb-legacy)
-                                                         entity
-                                                         number)
-  (and entity (aset (cdr entity) 0 number))
-  entity)
-
-(luna-define-method elmo-msgdb-message-entity-field ((msgdb modb-legacy)
-                                                    entity field
-                                                    &optional decode)
-  (and entity
-       (let ((field-value
-             (case field
-               (to (aref (cdr entity) 5))
-               (cc (aref (cdr entity) 6))
-               (date (aref (cdr entity) 4))
-               (subject (aref (cdr entity) 3))
-               (from (aref (cdr entity) 2))
-               (message-id (car entity))
-               (references (aref (cdr entity) 1))
-               (size (aref (cdr entity) 7))
-               (t (cdr (assoc (symbol-name field) (aref (cdr entity) 8)))))))
-        (if (and decode (memq field '(from subject)))
-            (elmo-msgdb-get-decoded-cache field-value)
-          field-value))))
-
-(luna-define-method elmo-msgdb-message-entity-set-field ((msgdb modb-legacy)
-                                                        entity field value)
-  (and entity
-       (case field
-        (number (aset (cdr entity) 0 value))
-        (to (aset (cdr entity) 5 value))
-        (cc (aset (cdr entity) 6 value))
-        (date (aset (cdr entity) 4 value))
-        (subject (aset (cdr entity) 3 value))
-        (from (aset (cdr entity) 2 value))
-        (message-id (setcar entity value))
-        (references (aset (cdr entity) 1 value))
-        (size (aset (cdr entity) 7 value))
-        (t
-         (let ((extras (and entity (aref (cdr entity) 8)))
-               extra)
-           (if (setq extra (assoc (symbol-name field) extras))
-               (setcdr extra value)
-             (aset (cdr entity) 8 (cons (cons (symbol-name field)
-                                              value) extras))))))))
-
-(luna-define-method elmo-msgdb-copy-message-entity ((msgdb modb-legacy)
-                                                   entity)
-  (cons (car entity)
-       (copy-sequence (cdr entity))))
-
-(luna-define-method elmo-msgdb-match-condition-internal ((msgdb modb-legacy)
-                                                        condition
-                                                        entity flags numbers)
-  (cond
-   ((vectorp condition)
-    (elmo-msgdb-match-condition-primitive condition entity flags numbers))
-   ((eq (car condition) 'and)
-    (let ((lhs (elmo-msgdb-match-condition-internal msgdb
-                                                   (nth 1 condition)
-                                                   entity flags numbers)))
-      (cond
-       ((elmo-filter-condition-p lhs)
-       (let ((rhs (elmo-msgdb-match-condition-internal
-                   msgdb (nth 2 condition) entity flags numbers)))
-         (cond ((elmo-filter-condition-p rhs)
-                (list 'and lhs rhs))
-               (rhs
-                lhs))))
-       (lhs
-       (elmo-msgdb-match-condition-internal msgdb (nth 2 condition)
-                                            entity flags numbers)))))
-   ((eq (car condition) 'or)
-    (let ((lhs (elmo-msgdb-match-condition-internal msgdb (nth 1 condition)
-                                                   entity flags numbers)))
-      (cond
-       ((elmo-filter-condition-p lhs)
-       (let ((rhs (elmo-msgdb-match-condition-internal msgdb
-                                                       (nth 2 condition)
-                                                       entity flags numbers)))
-         (cond ((elmo-filter-condition-p rhs)
-                (list 'or lhs rhs))
-               (rhs
-                t)
-               (t
-                lhs))))
-       (lhs
-       t)
-       (t
-       (elmo-msgdb-match-condition-internal msgdb
-                                            (nth 2 condition)
-                                            entity flags numbers)))))))
-
-;;
-(defun elmo-msgdb-match-condition-primitive (condition entity flags numbers)
-  (catch 'unresolved
-    (let ((key (elmo-filter-key condition))
-         (case-fold-search t)
-         result)
-      (cond
-       ((string= key "last")
-       (setq result (<= (length (memq
-                                 (elmo-msgdb-overview-entity-get-number
-                                  entity)
-                                 numbers))
-                        (string-to-int (elmo-filter-value condition)))))
-       ((string= key "first")
-       (setq result (< (-
-                        (length numbers)
-                        (length (memq
-                                 (elmo-msgdb-overview-entity-get-number
-                                  entity)
-                                 numbers)))
-                       (string-to-int (elmo-filter-value condition)))))
-       ((string= key "flag")
-       (setq result
-             (cond
-              ((string= (elmo-filter-value condition) "any")
-               (or (memq 'important flags)
-                   (memq 'answered flags)
-                   (memq 'unread flags)))
-              ((string= (elmo-filter-value condition) "digest")
-               (or (memq 'important flags)
-                   (memq 'unread flags)))
-              ((string= (elmo-filter-value condition) "unread")
-               (memq 'unread flags))
-              ((string= (elmo-filter-value condition) "important")
-               (memq 'important flags))
-              ((string= (elmo-filter-value condition) "answered")
-               (memq 'answered flags)))))
-       ((string= key "from")
-       (setq result (string-match
-                     (elmo-filter-value condition)
-                     (elmo-msgdb-overview-entity-get-from entity))))
-       ((string= key "subject")
-       (setq result (string-match
-                     (elmo-filter-value condition)
-                     (elmo-msgdb-overview-entity-get-subject entity))))
-       ((string= key "to")
-       (setq result (string-match
-                     (elmo-filter-value condition)
-                     (elmo-msgdb-overview-entity-get-to entity))))
-       ((string= key "cc")
-       (setq result (string-match
-                     (elmo-filter-value condition)
-                     (elmo-msgdb-overview-entity-get-cc entity))))
-       ((or (string= key "since")
-           (string= key "before"))
-       (let ((field-date (elmo-date-make-sortable-string
-                          (timezone-fix-time
-                           (elmo-msgdb-overview-entity-get-date entity)
-                           (current-time-zone) nil)))
-             (specified-date
-              (elmo-date-make-sortable-string
-               (elmo-date-get-datevec
-                (elmo-filter-value condition)))))
-         (setq result (if (string= key "since")
-                          (or (string= specified-date field-date)
-                              (string< specified-date field-date))
-                        (string< field-date specified-date)))))
-       ((member key elmo-msgdb-extra-fields)
-       (let ((extval (elmo-msgdb-overview-entity-get-extra-field entity key)))
-         (when (stringp extval)
-           (setq result (string-match
-                         (elmo-filter-value condition)
-                         extval)))))
-       (t
-       (throw 'unresolved condition)))
-      (if (eq (elmo-filter-type condition) 'unmatch)
-         (not result)
-       result))))
-
 (require 'product)
 (product-provide (provide 'modb-legacy) (require 'elmo-version))