1
;;; elmo-mime.el --- MIME module for ELMO.
3
;; Copyright (C) 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.
37
(luna-define-class mime-elmo-buffer-entity (mime-buffer-entity) ())
38
(luna-define-class mime-elmo-imap-entity (mime-imap-entity) ()))
41
(provide 'mmelmo-imap)
42
(provide 'mmelmo-buffer)
44
(defvar elmo-message-ignored-field-list mime-view-ignored-field-list)
45
(defvar elmo-message-visible-field-list mime-view-visible-field-list)
46
(defvar elmo-message-sorted-field-list nil)
48
(defcustom elmo-mime-header-max-column fill-column
49
"*Header max column number. Default is `fill-colmn'.
50
If a symbol of function is specified, the function is called and its return
52
:type '(choice (integer :tag "Column Number")
53
(function :tag "Function"))
56
(defcustom elmo-mime-display-as-is-coding-system (if (boundp 'MULE)
57
'*autoconv* 'undecided)
58
"*Coding system used when message is displayed as is."
62
(luna-define-method initialize-instance :after ((entity mime-elmo-buffer-entity)
66
(luna-define-method initialize-instance :around ((entity mime-elmo-imap-entity)
68
(luna-call-next-method))
70
;;; Insert sorted header.
71
(defsubst elmo-mime-insert-header-from-buffer (buffer
73
&optional invisible-fields
76
(let ((the-buf (current-buffer))
77
(mode-obj (mime-find-field-presentation-method 'wide))
79
f-b p f-e field-name field field-body
80
vf-alist (sl sort-fields))
84
(narrow-to-region start end)
86
(while (re-search-forward std11-field-head-regexp nil t)
87
(setq f-b (match-beginning 0)
89
field-name (buffer-substring f-b p)
90
f-e (std11-field-end))
91
(when (mime-visible-field-p field-name
92
visible-fields invisible-fields)
94
(capitalize (buffer-substring f-b (1- p))))
95
field-body (buffer-substring p f-e)
96
field-decoder (inline (mime-find-field-decoder-internal
98
(setq vf-alist (append (list
100
(list field-body field-decoder)))
105
(function (lambda (s d)
110
(while (setq re (nth n sl))
112
(and (string-match re sf)
114
(and (string-match re df)
117
(with-current-buffer the-buf
119
(let* ((vf (car vf-alist))
120
(field-name (car vf))
121
(field-body (car (cdr vf)))
122
(field-decoder (car (cdr (cdr vf)))))
124
(insert (if field-decoder
125
(funcall field-decoder field-body
126
(string-width field-name)
127
(if (functionp elmo-mime-header-max-column)
128
(funcall elmo-mime-header-max-column)
129
elmo-mime-header-max-column))
133
(setq vf-alist (cdr vf-alist)))
134
(run-hooks 'mmelmo-header-inserted-hook))))))
136
(luna-define-generic elmo-mime-insert-sorted-header (entity
137
&optional invisible-fields
140
"Insert sorted header fields of the ENTITY.")
142
(luna-define-method elmo-mime-insert-sorted-header ((entity
143
mime-elmo-buffer-entity)
144
&optional invisible-fields
147
(elmo-mime-insert-header-from-buffer
148
(mime-buffer-entity-buffer-internal entity)
149
(mime-buffer-entity-header-start-internal entity)
150
(mime-buffer-entity-header-end-internal entity)
151
invisible-fields visible-fields sorted-fields))
153
(luna-define-method elmo-mime-insert-sorted-header ((entity
154
mime-elmo-imap-entity)
155
&optional invisible-fields
158
(let ((the-buf (current-buffer))
161
(insert (mime-imap-entity-header-string entity))
162
(setq buf (current-buffer)
166
(elmo-mime-insert-header-from-buffer buf p-min p-max
171
(luna-define-method mime-insert-text-content :around
172
((entity mime-elmo-buffer-entity))
173
(luna-call-next-method)
174
(run-hooks 'elmo-message-text-content-inserted-hook))
176
(luna-define-method mime-insert-text-content :around
177
((entity mime-elmo-imap-entity))
178
(luna-call-next-method)
179
(run-hooks 'elmo-message-text-content-inserted-hook))
181
(defun elmo-mime-insert-header (entity situation)
182
(elmo-mime-insert-sorted-header
184
elmo-message-ignored-field-list
185
elmo-message-visible-field-list
186
elmo-message-sorted-field-list)
187
(run-hooks 'elmo-message-header-inserted-hook))
189
(defun elmo-make-mime-message-location (folder number strategy rawbuf unread)
190
;; Return the MIME message location structure.
191
;; FOLDER is the ELMO folder structure.
192
;; NUMBER is the number of the message in the FOLDER.
193
;; STRATEGY is the message fetching strategy.
194
;; RAWBUF is the output buffer for original message.
195
;; If second optional argument UNREAD is non-nil, message is not marked
198
(eq (elmo-fetch-strategy-entireness strategy) 'section))
200
'mime-elmo-imap-location
205
(with-current-buffer rawbuf
206
(let (buffer-read-only)
209
(elmo-message-fetch folder number strategy
214
(defun elmo-mime-message-display (folder number viewbuf rawbuf original-mode
215
&optional ignore-cache unread keymap)
216
"Display MIME message.
217
A message in the FOLDER with NUMBER is displayed on the VIEWBUF using RAWBUF.
218
VIEWBUF is a view buffer and RAWBUF is a raw buffer.
219
ORIGINAL is the major mode of RAWBUF.
220
If optional argument IGNORE-CACHE is specified, existing cache is ignored.
221
If second optional argument UNREAD is specified, message is displayed but
223
Return non-nil if not entire message was fetched."
224
(let (mime-display-header-hook ; Do nothing.
225
(elmo-message-displaying t)
227
(setq entity (elmo-msgdb-overview-get-entity number
230
(setq strategy (elmo-find-fetch-strategy folder entity
232
(mime-display-message
235
(eq (elmo-fetch-strategy-entireness strategy) 'section))
238
(elmo-make-mime-message-location
239
folder number strategy rawbuf unread))
243
(or (elmo-fetch-strategy-use-cache strategy)
244
(eq (elmo-fetch-strategy-entireness strategy)
247
(defun elmo-mime-display-as-is (folder number viewbuf rawbuf original-mode
248
&optional ignore-cache unread keymap)
249
"Display MIME message.
250
A message in the FOLDER with NUMBER is displayed on the VIEWBUF using RAWBUF.
251
VIEWBUF is a view buffer and RAWBUF is a raw buffer.
252
ORIGINAL is the major mode of RAWBUF.
253
If optional argument IGNORE-CACHE is specified, existing cache is ignored.
254
If second optional argument UNREAD is specified, message is displayed but
256
Return non-nil if cache is used."
257
(let ((entity (elmo-msgdb-overview-get-entity number
258
(elmo-folder-msgdb folder)))
259
mime-display-header-hook ; Do nothing.
260
cache-file strategy use-cache)
261
(setq cache-file (elmo-file-cache-get
262
(elmo-msgdb-overview-entity-get-id entity)))
263
(setq use-cache (eq (elmo-file-cache-status cache-file) 'entire))
264
(setq strategy (elmo-make-fetch-strategy
265
'entire use-cache (elmo-message-use-cache-p folder number)
266
(elmo-file-cache-path
268
(elmo-mime-display-as-is-internal
271
(elmo-make-mime-message-location
272
folder number strategy rawbuf unread))
273
viewbuf nil keymap original-mode)
274
(elmo-fetch-strategy-use-cache strategy)))
276
;; Replacement of mime-display-message.
277
(defun elmo-mime-display-as-is-internal (message
278
&optional preview-buffer
279
mother default-keymap-or-function
280
original-major-mode keymap)
281
(mime-maybe-hide-echo-buffer)
282
(let ((win-conf (current-window-configuration)))
285
(concat "*Preview-" (mime-entity-name message) "*")))
286
(or original-major-mode
287
(setq original-major-mode major-mode))
288
(let ((inhibit-read-only t))
289
(set-buffer (get-buffer-create preview-buffer))
293
(setq mime-mother-buffer mother))
294
(setq mime-preview-original-window-configuration win-conf)
295
(setq major-mode 'mime-view-mode)
296
(setq mode-name "MIME-View")
299
(set-buffer-multibyte nil)
300
(mime-insert-entity message)
301
(set-buffer-multibyte t)
302
(decode-coding-region (point-min) (point-max)
303
elmo-mime-display-as-is-coding-system)
305
(std11-narrow-to-header)
306
(run-hooks 'elmo-message-header-inserted-hook))
307
;; set original major mode for mime-preview-quit
308
(put-text-property (point-min) (point-max)
310
`((major-mode . ,original-major-mode)))
313
(if default-keymap-or-function
314
(mime-view-define-keymap default-keymap-or-function)
315
mime-view-mode-default-map)))
317
(next-single-property-change (point-min) 'mime-view-entity)))
320
(goto-char (point-min))
321
(search-forward "\n\n" nil t)))
322
(run-hooks 'mime-view-mode-hook)
323
(set-buffer-modified-p nil)
324
(setq buffer-read-only t)
328
(product-provide (provide 'elmo-mime) (require 'elmo-version))
330
;; elmo-mime.el ends here