Mercurial > emacs
annotate lisp/mail/rmailmm.el @ 88306:7b65aade5e20
new file, based on Alexander Pohoyda's code.
author | Alex Schroeder <alex@gnu.org> |
---|---|
date | Tue, 31 Jan 2006 20:53:28 +0000 |
parents | |
children | b72b8d536511 |
rev | line source |
---|---|
88306
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
1 ;;; rmailmm.el --- MIME decoding and display stuff for RMAIL |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
2 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 2006 Free Software Foundation, Inc. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
4 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
5 ;; Maintainer: FSF |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
6 ;; Keywords: mail |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
7 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
9 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
13 ;; any later version. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
14 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
19 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
23 ;; Boston, MA 02110-1301, USA. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
24 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
25 ;;; Commentary: |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
26 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
27 ;; Essentially based on the design of Alexander Pohoyda's MIME |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
28 ;; extensions (mime-display.el and mime.el). The current design tries |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
29 ;; to work on the current buffer, without changing it's text. All it |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
30 ;; does is add text properties: It uses the text property `invisible' |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
31 ;; to hide MIME boundaries and ignored media types, and it uses the |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
32 ;; text property `display' to display something instead of the actual |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
33 ;; MIME part. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
34 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
35 ;;; Code: |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
36 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
37 ;;; Variables |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
38 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
39 (defcustom mime-media-type-handlers-alist |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
40 '(("multipart/.*" mime-multipart-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
41 ("message/rfc822" mime-toggler-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
42 ("message/delivery-status" mime-entity-hider-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
43 ("message/x-body" mime-entity-hider-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
44 ("message/x-command-input" mime-message/x-command-input-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
45 ("message/external-body" mime-message/external-body-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
46 ("text/.*" mime-text-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
47 ("text/\\(x-\\)?patch" mime-bulk-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
48 ("image/.*" mime-image-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
49 ("application/pgp-signature" mime-application/pgp-signature-handler) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
50 ("\\(image\\|audio\\|video\\|application\\)/.*" mime-bulk-handler)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
51 "Alist of media type handlers, also known as agents. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
52 Every handler is a list of type (string symbol) where STRING is a |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
53 regular expression to match the media type with and SYMBOL is a |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
54 function to run." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
55 :type 'list |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
56 :group 'mime) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
57 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
58 (defcustom mime-attachment-dirs-alist |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
59 '(("text/.*" ("~/Documents")) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
60 ("image/.*" ("~/Pictures")) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
61 (".*" ("/tmp/"))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
62 "Default directories to save attachments into. Each media type may have |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
63 it's own directory." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
64 :type 'list |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
65 :group 'mime) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
66 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
67 (defvar mime-total-number-of-bulk-attachments 0 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
68 "A total number of attached bulk bodyparts in the message. If more than 3, |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
69 offer a way to save all attachments at once.") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
70 (put 'mime-total-number-of-bulk-attachments 'permanent-local t) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
71 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
72 ;;; Utility Functions |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
73 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
74 (defun mime-hide-region (from to) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
75 "Put text property `invisible' on the region FROM TO." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
76 (put-text-property from to 'invisible t)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
77 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
78 (defun mime-unhide-region (from to) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
79 "Remove the text property `invisible' on the region FROM TO." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
80 (remove-text-properties from to '(invisible nil))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
81 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
82 (defun mime-display-region-as (from to text) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
83 "Put text property `display' with value TEXT on the region FROM TO." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
84 (put-text-property from to 'display text)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
85 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
86 ;;; Buttons |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
87 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
88 (defun mime-save (button) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
89 "Save the attachment using info in the BUTTON." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
90 (let* ((filename (button-get button 'filename)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
91 (directory (button-get button 'directory)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
92 (data (button-get button 'data))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
93 (setq filename (expand-file-name |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
94 (read-file-name "Save as: " |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
95 directory nil nil filename))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
96 (when (file-regular-p filename) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
97 (error (message "File `%s' already exists" filename))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
98 (with-temp-file filename |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
99 (set-buffer-file-coding-system 'no-conversion) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
100 (insert data)))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
101 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
102 (define-button-type 'mime-save |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
103 'action 'mime-save) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
104 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
105 ;;; Handlers |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
106 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
107 (defun mime-text-handler (content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
108 content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
109 content-transfer-encoding) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
110 "Handle the current buffer as a plain text MIME part.") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
111 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
112 (defun mime-bulk-handler (content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
113 content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
114 content-transfer-encoding) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
115 "Handle the current buffer as an attachment to download." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
116 (setq mime-total-number-of-bulk-attachments |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
117 (1+ mime-total-number-of-bulk-attachments)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
118 ;; Find the default directory for this media type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
119 (let* ((directory (catch 'directory |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
120 (dolist (entry mime-attachment-dirs-alist) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
121 (when (string-match (car entry) (car content-type)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
122 (throw 'directory (cadr entry)))))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
123 (filename (or (cdr (assq 'name (cdr content-type))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
124 (cdr (assq 'filename (cdr content-disposition))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
125 "noname")) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
126 (button (format "\nAttached %s file: %s" |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
127 (car content-type) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
128 (let ((data (buffer-string))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
129 (with-temp-buffer |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
130 (insert-button filename :type 'mime-save |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
131 'filename filename |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
132 'directory directory |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
133 'data data) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
134 (buffer-string)))))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
135 (mime-display-region-as (point-min) (point-max) button))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
136 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
137 (defun mime-multipart-handler (content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
138 content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
139 content-transfer-encoding) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
140 "Handle the current buffer as a multipart MIME body. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
141 The current buffer should be narrowed to the body. CONTENT-TYPE, |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
142 CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING are the values |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
143 of the respective parsed headers. See `mime-handle' for their |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
144 format." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
145 ;; Some MUAs start boundaries with "--", while it should start |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
146 ;; with "CRLF--", as defined by RFC 2046: |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
147 ;; The boundary delimiter MUST occur at the beginning of a line, |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
148 ;; i.e., following a CRLF, and the initial CRLF is considered to |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
149 ;; be attached to the boundary delimiter line rather than part |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
150 ;; of the preceding part. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
151 ;; We currently don't handle that. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
152 (let ((boundary (cdr (assq 'boundary content-type))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
153 (beg (point-min)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
154 next) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
155 (unless boundary |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
156 (error "No boundary defined" content-type content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
157 content-transfer-encoding)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
158 (setq boundary (concat "\n--" boundary)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
159 ;; Hide the body before the first bodypart |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
160 (goto-char beg) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
161 (when (and (search-forward boundary nil t) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
162 (looking-at "[ \t]*\n")) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
163 (mime-hide-region beg (match-end 0)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
164 (setq beg (match-end 0))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
165 ;; Reset the counter |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
166 (setq mime-total-number-of-bulk-attachments 0) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
167 ;; Loop over all body parts, where beg points at the beginning of |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
168 ;; the part and end points at the end of the part. next points at |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
169 ;; the beginning of the next part. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
170 (while (search-forward boundary nil t) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
171 (setq end (match-beginning 0)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
172 ;; If this is the last boundary according to RFC 2046, hide the |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
173 ;; epilogue, else hide the boundary only. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
174 (cond ((looking-at "--[ \t]*\n") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
175 (setq next (point-max))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
176 ((looking-at "[ \t]*\n") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
177 (setq next (match-end 0))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
178 (t |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
179 (error "Malformed boundary" content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
180 content-disposition content-transfer-encoding))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
181 (mime-hide-region end next) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
182 ;; Handle the part. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
183 (save-match-data |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
184 (save-excursion |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
185 (save-restriction |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
186 (narrow-to-region beg end) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
187 ;; FIXME: Do decoding of content-transfer-encoding |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
188 (mime-show)))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
189 (setq beg next) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
190 (goto-char beg)))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
191 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
192 (defun test-mime-multipart-handler () |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
193 "Test of a mail used as an example in RFC 2046." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
194 (let ((mail "From: Nathaniel Borenstein <nsb@bellcore.com> |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
195 To: Ned Freed <ned@innosoft.com> |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
196 Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
197 Subject: Sample message |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
198 MIME-Version: 1.0 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
199 Content-type: multipart/mixed; boundary=\"simple boundary\" |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
200 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
201 This is the preamble. It is to be ignored, though it |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
202 is a handy place for composition agents to include an |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
203 explanatory note to non-MIME conformant readers. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
204 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
205 --simple boundary |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
206 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
207 This is implicitly typed plain US-ASCII text. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
208 It does NOT end with a linebreak. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
209 --simple boundary |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
210 Content-type: text/plain; charset=us-ascii |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
211 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
212 This is explicitly typed plain US-ASCII text. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
213 It DOES end with a linebreak. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
214 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
215 --simple boundary-- |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
216 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
217 This is the epilogue. It is also to be ignored.")) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
218 (switch-to-buffer (get-buffer-create "*test*")) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
219 (erase-buffer) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
220 (insert mail) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
221 (mime-show t) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
222 (buffer-string))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
223 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
224 ;;; Main code |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
225 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
226 (defun mime-handle (content-type content-disposition content-transfer-encoding) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
227 "Handle the current buffer as a MIME part. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
228 The current buffer should be narrowed to the respective body. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
229 CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
230 are the values of the respective parsed headers. The parsed |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
231 headers for CONTENT-TYPE and CONTENT-DISPOSITION have the form |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
232 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
233 \(VALUE . ALIST) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
234 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
235 In other words: |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
236 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
237 \(VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
238 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
239 VALUE is a string and ATTRIBUTE is a symbol. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
240 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
241 Consider the following header, for example: |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
242 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
243 Content-Type: multipart/mixed; |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
244 boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\" |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
245 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
246 The parsed header value: |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
247 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
248 \(\"multipart/mixed\" |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
249 \(\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))" |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
250 (if (string= "inline" (car content-disposition)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
251 (let ((stop nil)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
252 (dolist (entry mime-media-type-handlers-alist) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
253 (when (and (string-match (car entry) (car content-type)) (not stop)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
254 (progn |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
255 (setq stop (funcall (cadr entry) content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
256 content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
257 content-transfer-encoding)))))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
258 ;; treat everything else as an attachment |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
259 (mime-bulk-handler content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
260 content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
261 content-transfer-encoding))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
262 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
263 (defun mime-show (&optional show-headers) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
264 "Handle the current buffer as a MIME message. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
265 If SHOW-HEADERS is non-nil, then the headers of the current part |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
266 are not all hidden, as they usually are \(except for |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
267 message/rfc822 content types\). This is usually only used for |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
268 the top-level call. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
269 |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
270 The current buffer must be narrowed to a single message. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
271 This function will be called recursively if multiple parts |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
272 are available." |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
273 (let ((end (point-min)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
274 content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
275 content-transfer-encoding |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
276 content-disposition) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
277 ;; `point-min' returns the beginning and `end' points at the end |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
278 ;; of the headers. We're not using `rmail-header-get-header' |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
279 ;; because we must be able to handle the case of no headers |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
280 ;; existing in a part. In this case end is at point-min. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
281 (goto-char (point-min)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
282 ;; If we're showing a part without headers, then it will start |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
283 ;; with a newline. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
284 (if (eq (char-after) ?\n) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
285 (setq end (1+ (point))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
286 (when (search-forward "\n\n" nil t) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
287 (setq end (match-end 0)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
288 (save-restriction |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
289 (narrow-to-region (point-min) end) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
290 ;; FIXME: Default disposition of the multipart entities should |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
291 ;; be inherited. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
292 (setq content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
293 (mail-fetch-field "Content-Type") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
294 content-transfer-encoding |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
295 (mail-fetch-field "Content-Transfer-Encoding") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
296 content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
297 (mail-fetch-field "Content-Disposition"))))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
298 (if content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
299 (setq content-type (mail-header-parse-content-type |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
300 content-type)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
301 ;; FIXME: Default "message/rfc822" in a "multipart/digest" |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
302 ;; according to RFC 2046. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
303 (setq content-type '("text/plain"))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
304 (setq content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
305 (if content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
306 (mail-header-parse-content-disposition content-disposition) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
307 ;; If none specified, we are free to choose what we deem |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
308 ;; suitable according to RFC 2183. We like inline. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
309 '("inline"))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
310 ;; Hide headers. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
311 (if (or (string= (car content-type) "message/rfc822") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
312 show-headers) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
313 (rmail-header-hide-headers) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
314 (mime-hide-region (point-min) end)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
315 ;; Unrecognized disposition types are to be treated like |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
316 ;; attachment according to RFC 2183. |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
317 (unless (string= (car content-disposition) "inline") |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
318 (setq content-disposition '("attachment"))) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
319 (save-restriction |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
320 (narrow-to-region end (point-max)) |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
321 (mime-handle content-type content-disposition |
7b65aade5e20
new file, based on Alexander Pohoyda's code.
Alex Schroeder <alex@gnu.org>
parents:
diff
changeset
|
322 content-transfer-encoding)))) |