/usr/share/emacs/site-lisp/wl/elmo/modb-entity.el is in wl 2.14.0-12.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | ;;; modb-entity.el --- Message Entity Interface.
;; Copyright (C) 2003 Yuuichi Teranishi <teranisi@gohome.org>
;; Author: Yuuichi Teranishi <teranisi@gohome.org>
;; Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
;; Keywords: mail, net news
;; This file is part of ELMO (Elisp Library for Message Orchestration).
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;; Commentary:
;;
;; Message entity handling.
;;; Code:
(eval-when-compile (require 'cl))
(require 'luna)
(require 'elmo-vars)
(require 'elmo-util)
(eval-and-compile (luna-define-class modb-entity-handler))
(defcustom modb-entity-default-handler 'modb-legacy-entity-handler
"Default entity handler."
:type 'symbol
:group 'elmo)
(defcustom elmo-msgdb-prefer-in-reply-to-for-parent nil
"*Non-nil to prefer In-Reply-To header for finding parent message on thread,
rather than References header."
:type 'boolean
:group 'elmo)
(defvar modb-entity-default-cache-internal nil)
(defun elmo-message-entity-handler (&optional entity)
"Get modb entity handler instance which corresponds to the ENTITY."
(if (and entity
(car-safe entity)
(not (eq (car entity) t))
(not (stringp (car entity))))
(car entity)
(or modb-entity-default-cache-internal
(setq modb-entity-default-cache-internal
(luna-make-entity modb-entity-default-handler)))))
(luna-define-generic elmo-msgdb-make-message-entity (handler &rest args)
"Make a message entity using HANDLER.")
(luna-define-generic elmo-msgdb-message-entity-number (handler entity)
"Number of the ENTITY.")
(luna-define-generic elmo-msgdb-message-entity-set-number (handler
entity number)
"Set number of the ENTITY.")
(luna-define-generic elmo-msgdb-message-entity-field (handler
entity field
&optional decode)
"Retrieve field value of the message entity.
HANDLER is the message entity handler.
ENTITY is the message entity structure.
FIELD is a symbol of the field.
If optional DECODE is no-nil, the field value is decoded.")
(luna-define-generic elmo-msgdb-message-entity-set-field (handler
entity field value)
"Set the field value of the message entity.
HANDLER is the message entity handler.
ENTITY is the message entity structure.
FIELD is a symbol of the field.
VALUE is the field value to set.")
(luna-define-generic elmo-msgdb-message-entity-update-fields (handler
entity values)
"Update message entity by VALUES.
HANDLER is the message entity handler.
ENTITY is the message entity structure.
VALUES is an alist of field-name and field-value.")
(luna-define-generic elmo-msgdb-copy-message-entity (handler entity)
"Copy message entity.
HANDLER is the message entity handler.
ENTITY is the message entity structure.")
(luna-define-generic elmo-msgdb-create-message-entity-from-file (handler
number
file)
"Create message entity from file.
HANDLER is the message entity handler.
NUMBER is the number of the newly created message entity.
FILE is the message file.")
(luna-define-generic elmo-msgdb-create-message-entity-from-buffer (handler
number
&rest args)
"Create message entity from current buffer.
HANDLER is the message entity handler.
NUMBER is the number of the newly created message entity.
Rest of the ARGS is a plist of message entity field for initial value.
Header region is supposed to be narrowed.")
;; Transitional interface.
(luna-define-generic elmo-msgdb-message-match-condition (handler
condition
entity
flags
numbers)
"Return non-nil when the entity matches the condition.")
;; Generic implementation.
(luna-define-method elmo-msgdb-create-message-entity-from-file
((handler modb-entity-handler) number file)
(let (insert-file-contents-pre-hook ; To avoid autoconv-xmas...
insert-file-contents-post-hook header-end
(attrib (file-attributes file))
ret-val size mtime)
(with-temp-buffer
(if (not (file-exists-p file))
()
(setq size (nth 7 attrib))
(setq mtime (timezone-make-date-arpa-standard
(current-time-string (nth 5 attrib)) (current-time-zone)))
;; insert header from file.
(catch 'done
(condition-case nil
(elmo-msgdb-insert-file-header file)
(error (throw 'done nil)))
(goto-char (point-min))
(setq header-end
(if (re-search-forward "\\(^--.*$\\)\\|\\(\n\n\\)" nil t)
(point)
(point-max)))
(narrow-to-region (point-min) header-end)
(elmo-msgdb-create-message-entity-from-buffer
handler number :size size :date mtime))))))
(luna-define-method elmo-msgdb-make-message-entity ((handler
modb-entity-handler)
args)
(cons handler args))
(luna-define-method elmo-msgdb-message-entity-field ((handler
modb-entity-handler)
entity field
&optional decode)
(plist-get (cdr entity) (intern (concat ":" (symbol-name field)))))
(luna-define-method elmo-msgdb-message-entity-number ((handler
modb-entity-handler)
entity)
(plist-get (cdr entity) :number))
(luna-define-method elmo-msgdb-message-entity-update-fields
((handler modb-entity-handler) entity values)
(let (updated)
(dolist (pair values)
(unless (equal
(cdr pair)
(elmo-msgdb-message-entity-field handler entity (car pair)))
(elmo-msgdb-message-entity-set-field handler entity
(car pair) (cdr pair))
(setq updated t)))
updated))
;; Legacy implementation.
(eval-and-compile (luna-define-class modb-legacy-entity-handler
(modb-entity-handler)))
;;
;; 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)
(prog1
(setq decoded
(elmo-with-enable-multibyte
(decode-mime-charset-string string elmo-mime-charset)))
(elmo-set-hash-val string decoded hashtb))))
(elmo-with-enable-multibyte
(decode-mime-charset-string string elmo-mime-charset))))
(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
((handler modb-legacy-entity-handler) args)
(modb-legacy-make-message-entity args))
(luna-define-method elmo-msgdb-create-message-entity-from-buffer
((handler modb-legacy-entity-handler) 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))
(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
(if elmo-msgdb-prefer-in-reply-to-for-parent
(or (elmo-msgdb-get-last-message-id
(elmo-field-body "in-reply-to"))
(elmo-msgdb-get-last-message-id
(elmo-field-body "references")))
(or (elmo-msgdb-get-last-message-id
(elmo-field-body "references"))
(elmo-msgdb-get-last-message-id
(elmo-field-body "in-reply-to"))))
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-unfold-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 handler 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
handler 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
handler entity field (symbol-value field))))
entity)))
(luna-define-method elmo-msgdb-message-entity-number
((handler modb-legacy-entity-handler) entity)
(and entity (aref (cdr entity) 0)))
(luna-define-method elmo-msgdb-message-entity-set-number
((handler modb-legacy-entity-handler) entity number)
(and entity (aset (cdr entity) 0 number))
entity)
(luna-define-method elmo-msgdb-message-entity-field
((handler modb-legacy-entity-handler) 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
((handler modb-legacy-entity-handler) 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
((handler modb-legacy-entity-handler) entity)
(cons (car entity)
(copy-sequence (cdr entity))))
(luna-define-method elmo-msgdb-message-match-condition
((handler modb-legacy-entity-handler) condition entity flags numbers)
(cond
((vectorp condition)
(elmo-msgdb-match-condition-primitive handler condition
entity flags numbers))
((eq (car condition) 'and)
(let ((lhs (elmo-msgdb-message-match-condition handler
(nth 1 condition)
entity flags numbers)))
(cond
((elmo-filter-condition-p lhs)
(let ((rhs (elmo-msgdb-message-match-condition
handler (nth 2 condition) entity flags numbers)))
(cond ((elmo-filter-condition-p rhs)
(list 'and lhs rhs))
(rhs
lhs))))
(lhs
(elmo-msgdb-message-match-condition handler (nth 2 condition)
entity flags numbers)))))
((eq (car condition) 'or)
(let ((lhs (elmo-msgdb-message-match-condition handler (nth 1 condition)
entity flags numbers)))
(cond
((elmo-filter-condition-p lhs)
(let ((rhs (elmo-msgdb-message-match-condition handler
(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-message-match-condition handler
(nth 2 condition)
entity flags numbers)))))))
;;
(defun elmo-msgdb-match-condition-primitive (handler
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-message-entity-number
handler entity)
numbers))
(string-to-int (elmo-filter-value condition)))))
((string= key "first")
(setq result (< (-
(length numbers)
(length (memq
(elmo-msgdb-message-entity-number
handler 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-message-entity-field
handler entity 'from t))))
((string= key "subject")
(setq result (string-match
(elmo-filter-value condition)
(elmo-msgdb-message-entity-field
handler entity 'subject t))))
((string= key "to")
(setq result (string-match
(elmo-filter-value condition)
(elmo-msgdb-message-entity-field
handler entity 'to))))
((string= key "cc")
(setq result (string-match
(elmo-filter-value condition)
(elmo-msgdb-message-entity-field
handler entity 'cc))))
((or (string= key "since")
(string= key "before"))
(let ((field-date (elmo-date-make-sortable-string
(timezone-fix-time
(elmo-msgdb-message-entity-field
handler entity 'date)
(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-message-entity-field handler
entity
(intern 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-entity) (require 'elmo-version))
;;; modb-entity.el ends here
|