1 ;;; mmelmo.el -- mm-backend by ELMO.
3 ;; Copyright 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 (product-provide (provide 'mmelmo) (require 'elmo-version))
38 (require 'mmelmo-imap4)
41 (luna-define-class mime-elmo-entity (mime-buffer-entity)
42 (imap folder number msgdb size))
43 (luna-define-internal-accessors 'mime-elmo-entity))
45 (defvar mmelmo-force-reload nil)
46 (defvar mmelmo-sort-field-list nil)
48 (defvar mmelmo-header-max-column fill-column
49 "*Inserted header is folded with this value.
50 If function is specified, its return value is used.")
52 (defvar mmelmo-header-inserted-hook nil
53 "*A hook called when header is inserted.")
55 (defvar mmelmo-entity-content-inserted-hook nil
56 "*A hook called when entity-content is inserted.")
58 (defun mmelmo-get-original-buffer ()
59 (let ((ret-val (get-buffer (concat mmelmo-entity-buffer-name "0"))))
62 (set-buffer (setq ret-val
64 (concat mmelmo-entity-buffer-name "0"))))
65 (mmelmo-original-mode)))
68 (defun mmelmo-cleanup-entity-buffers ()
69 "Cleanup entity buffers of mmelmo."
71 (if (string-match mmelmo-entity-buffer-name x)
73 (mapcar 'buffer-name (buffer-list))))
76 (defun-maybe mime-entity-body (entity)
77 (luna-send entity 'mime-entity-body))
79 (defun mmelmo-insert-sorted-header-from-buffer (buffer
81 &optional invisible-fields
84 (let ((the-buf (current-buffer))
85 (mode-obj (mime-find-field-presentation-method 'wide))
87 f-b p f-e field-name field field-body
88 vf-alist (sl sorted-fields))
92 (narrow-to-region start end)
94 (while (re-search-forward std11-field-head-regexp nil t)
95 (setq f-b (match-beginning 0)
97 field-name (buffer-substring f-b p)
98 f-e (std11-field-end))
99 (when (mime-visible-field-p field-name
100 visible-fields invisible-fields)
102 (capitalize (buffer-substring f-b (1- p))))
103 field-body (buffer-substring p f-e)
104 field-decoder (inline (mime-find-field-decoder-internal
106 (setq vf-alist (append (list
108 (list field-body field-decoder)))
113 (function (lambda (s d)
118 (while (setq re (nth n sl))
120 (and (string-match re sf)
122 (and (string-match re df)
125 (with-current-buffer the-buf
127 (let* ((vf (car vf-alist))
128 (field-name (car vf))
129 (field-body (car (cdr vf)))
130 (field-decoder (car (cdr (cdr vf)))))
132 (insert (if field-decoder
133 (funcall field-decoder field-body
134 (string-width field-name)
135 (if (functionp mmelmo-header-max-column)
136 (funcall mmelmo-header-max-column)
137 mmelmo-header-max-column))
141 (setq vf-alist (cdr vf-alist)))
142 (run-hooks 'mmelmo-header-inserted-hook))))))
144 (defun mmelmo-original-mode ()
145 (setq major-mode 'mmelmo-original-mode)
146 (setq buffer-read-only t)
147 (elmo-set-buffer-multibyte nil)
148 (setq mode-name "MMELMO-Original"))
150 ;; For FLIMs without rfc2231 feature .
151 (if (not (fboundp 'mime-parse-parameters-from-list))
152 (defun mime-parse-parameters-from-list (attrlist)
154 (if (not (eq (% (length attrlist) 2) 0))
155 (message "Invalid attributes."))
157 (setq ret-val (append ret-val
158 (list (cons (downcase (car attrlist))
159 (car (cdr attrlist))))))
160 (setq attrlist (cdr (cdr attrlist))))
163 (luna-define-method initialize-instance :after ((entity mime-elmo-entity)
165 "The initialization method for elmo.
166 mime-elmo-entity has its own member variable,
167 `imap', `folder', `msgdb' and `size'.
168 imap: boolean. if non-nil, entity becomes mime-elmo-imap4-entity class.
169 folder: string. folder name.
170 msgdb: msgdb of elmo.
171 size: size of the entity."
172 (if (mime-elmo-entity-imap-internal entity)
173 ;; use imap part fetching.
174 ;; child mime-entity's class becomes `mime-elmo-imap4-entity'
175 ;; which implements `entity-buffer' method.
178 (mime-buffer-entity-set-buffer-internal entity nil)
180 (mmelmo-imap4-get-mime-entity
181 (mime-elmo-entity-folder-internal entity) ; folder
182 (mime-elmo-entity-number-internal entity) ; number
183 (mime-elmo-entity-msgdb-internal entity) ; msgdb
185 (mime-entity-set-content-type-internal
187 (mime-entity-content-type-internal new-entity))
188 (mime-entity-set-encoding-internal
190 (mime-entity-encoding-internal new-entity))
191 (mime-entity-set-children-internal
193 (mime-entity-children-internal new-entity))
194 (mime-elmo-entity-set-size-internal
196 (mime-elmo-entity-size-internal new-entity))
197 (mime-entity-set-representation-type-internal
198 entity 'mime-elmo-imap4-entity)
200 (set-buffer (mime-buffer-entity-buffer-internal entity))
201 (mmelmo-original-mode)
202 (when (mime-root-entity-p entity)
203 (let ((buffer-read-only nil)
204 header-end body-start)
206 (elmo-read-msg-with-buffer-cache
207 (mime-elmo-entity-folder-internal entity)
208 (mime-elmo-entity-number-internal entity)
210 (mime-elmo-entity-msgdb-internal entity)
212 (goto-char (point-min))
213 (if (re-search-forward
214 (concat "^" (regexp-quote mail-header-separator) "$\\|^$" )
216 (setq header-end (match-beginning 0)
217 body-start (if (= (match-end 0) (point-max))
220 (setq header-end (point-min)
221 body-start (point-min)))
222 (mime-buffer-entity-set-header-start-internal entity (point-min))
223 (mime-buffer-entity-set-header-end-internal entity header-end)
224 (mime-buffer-entity-set-body-start-internal entity body-start)
225 (mime-buffer-entity-set-body-end-internal entity (point-max))
227 (narrow-to-region (mime-buffer-entity-header-start-internal entity)
228 (mime-buffer-entity-header-end-internal entity))
229 (mime-entity-set-content-type-internal
231 (let ((str (std11-fetch-field "Content-Type")))
233 (mime-parse-Content-Type str)
237 (luna-define-method mime-insert-header ((entity mime-elmo-entity)
238 &optional invisible-fields
240 (mmelmo-insert-sorted-header-from-buffer
241 (mime-buffer-entity-buffer-internal entity)
242 (mime-buffer-entity-header-start-internal entity)
243 (mime-buffer-entity-header-end-internal entity)
244 invisible-fields visible-fields mmelmo-sort-field-list))
246 (luna-define-method mime-insert-text-content :around ((entity
248 (luna-call-next-method)
249 (run-hooks 'mmelmo-entity-content-inserted-hook))
251 (luna-define-method mime-entity-body ((entity mime-elmo-entity))
252 (with-current-buffer (mime-buffer-entity-buffer-internal entity)
253 (buffer-substring (mime-buffer-entity-body-start-internal entity)
254 (mime-buffer-entity-body-end-internal entity))))
256 ;;(luna-define-method mime-entity-content ((entity mime-elmo-entity))
257 ;; (mime-decode-string
258 ;; (with-current-buffer (mime-buffer-entity-buffer-internal entity)
259 ;; (buffer-substring (mime-buffer-entity-body-start-internal entity)
260 ;; (mime-buffer-entity-body-end-internal entity)))
261 ;; (mime-entity-encoding entity)))
263 ;;; mmelmo.el ends here