annotate lisp/mail/rmailmm.el @ 101380:50eed64d8f54

Comment (add Author: header).
author Glenn Morris <rgm@gnu.org>
date Fri, 23 Jan 2009 04:15:56 +0000
parents 42bb3840e9a2
children 4f858364bb26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1 ;;; rmailmm.el --- MIME decoding and display stuff for RMAIL
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
2
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
3 ;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
4
101380
50eed64d8f54 Comment (add Author: header).
Glenn Morris <rgm@gnu.org>
parents: 101370
diff changeset
5 ;; Author: Alexander Pohoyda
50eed64d8f54 Comment (add Author: header).
Glenn Morris <rgm@gnu.org>
parents: 101370
diff changeset
6 ;; Alex Schroeder
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
7 ;; Maintainer: FSF
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
8 ;; Keywords: mail
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
9
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
11
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
15 ;; (at your option) any later version.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
16
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
21
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
24
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
25 ;;; Commentary:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
26
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
27 ;; Essentially based on the design of Alexander Pohoyda's MIME
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
28 ;; extensions (mime-display.el and mime.el). To use, copy a complete
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
29 ;; message into a new buffer and call (mime-show t).
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
30
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
31 ;; To use:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
32
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
33 ;; (autoload 'rmail-mime "rmailmm"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
34 ;; "Show MIME message." t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
35 ;; (add-hook 'rmail-mode-hook
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
36 ;; (lambda ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
37 ;; (define-key rmail-mode-map (kbd "v")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
38 ;; 'rmail-mime)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
39
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
40 ;;; Code:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
41
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
42 (require 'rmail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
43 (require 'mail-parse)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
44
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
45 ;;; Variables
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
46
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
47 (defcustom rmail-mime-media-type-handlers-alist
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
48 '(("multipart/.*" rmail-mime-multipart-handler)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
49 ("text/.*" rmail-mime-text-handler)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
50 ("text/\\(x-\\)?patch" rmail-mime-bulk-handler)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
51 ("application/pgp-signature" rmail-mime-application/pgp-signature-handler)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
52 ("\\(image\\|audio\\|video\\|application\\)/.*" rmail-mime-bulk-handler))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
53 "Alist of media type handlers, also known as agents.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
54 Every handler is a list of type (string symbol) where STRING is a
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
55 regular expression to match the media type with and SYMBOL is a
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
56 function to run. Handlers should return a non-nil value if the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
57 job is done."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
58 :type 'list
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
59 :group 'mime)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
60
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
61 (defcustom rmail-mime-attachment-dirs-alist
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
62 '(("text/.*" "~/Documents")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
63 ("image/.*" "~/Pictures")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
64 (".*" "~/Desktop" "~" "/tmp"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
65 "Default directories to save attachments into.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
66 Each media type may have it's own list of directories in order of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
67 preference. The first existing directory in the list will be
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
68 used."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
69 :type 'list
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
70 :group 'mime)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
71
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
72 (defvar rmail-mime-total-number-of-bulk-attachments 0
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
73 "A total number of attached bulk bodyparts in the message. If more than 3,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
74 offer a way to save all attachments at once.")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
75 (put 'rmail-mime-total-number-of-bulk-attachments 'permanent-local t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
76
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
77 ;;; Buttons
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
78
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
79 (defun rmail-mime-save (button)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
80 "Save the attachment using info in the BUTTON."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
81 (let* ((filename (button-get button 'filename))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
82 (directory (button-get button 'directory))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
83 (data (button-get button 'data)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
84 (while (file-exists-p (expand-file-name filename directory))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
85 (let* ((f (file-name-sans-extension filename))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
86 (i 1))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
87 (when (string-match "-\\([0-9]+\\)$" f)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
88 (setq i (1+ (string-to-number (match-string 1 f)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
89 f (substring f 0 (match-beginning 0))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
90 (setq filename (concat f "-" (number-to-string i) "."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
91 (file-name-extension filename)))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
92 (setq filename (expand-file-name
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
93 (read-file-name (format "Save as (default: %s): " filename)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
94 directory
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
95 (expand-file-name filename directory))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
96 directory))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
97 (when (file-regular-p filename)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
98 (error (message "File `%s' already exists" filename)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
99 (with-temp-file filename
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
100 (set-buffer-file-coding-system 'no-conversion)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
101 (insert data))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
102
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
103 (define-button-type 'rmail-mime-save
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
104 'action 'rmail-mime-save)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
105
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
106 ;;; Handlers
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
107
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
108 (defun rmail-mime-text-handler (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
109 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
110 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
111 "Handle the current buffer as a plain text MIME part."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
112 (let* ((charset (cdr (assq 'charset (cdr content-type))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
113 (coding-system (when charset
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
114 (intern (downcase charset)))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
115 (when (coding-system-p coding-system)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
116 (decode-coding-region (point-min) (point-max) coding-system))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
117
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
118 (defun test-rmail-mime-handler ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
119 "Test of a mail using no MIME parts at all."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
120 (let ((mail "To: alex@gnu.org
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
121 Content-Type: text/plain; charset=koi8-r
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
122 Content-Transfer-Encoding: 8bit
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
123 MIME-Version: 1.0
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
124
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
125 \372\304\322\301\327\323\324\327\325\312\324\305\41"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
126 (switch-to-buffer (get-buffer-create "*test*"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
127 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
128 (set-buffer-multibyte nil)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
129 (insert mail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
130 (rmail-mime-show t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
131 (set-buffer-multibyte t)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
132
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
133 (defun rmail-mime-bulk-handler (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
134 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
135 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
136 "Handle the current buffer as an attachment to download."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
137 (setq rmail-mime-total-number-of-bulk-attachments
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
138 (1+ rmail-mime-total-number-of-bulk-attachments))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
139 ;; Find the default directory for this media type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
140 (let* ((directory (catch 'directory
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
141 (dolist (entry rmail-mime-attachment-dirs-alist)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
142 (when (string-match (car entry) (car content-type))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
143 (dolist (dir (cdr entry))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
144 (when (file-directory-p dir)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
145 (throw 'directory dir)))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
146 (filename (or (cdr (assq 'name (cdr content-type)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
147 (cdr (assq 'filename (cdr content-disposition)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
148 "noname"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
149 (label (format "\nAttached %s file: " (car content-type)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
150 (data (buffer-string)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
151 (delete-region (point-min) (point-max))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
152 (insert label)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
153 (insert-button filename
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
154 :type 'rmail-mime-save
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
155 'filename filename
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
156 'directory directory
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
157 'data data)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
158
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
159 (defun test-rmail-mime-bulk-handler ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
160 "Test of a mail used as an example in RFC 2183."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
161 (let ((mail "Content-Type: image/jpeg
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
162 Content-Disposition: attachment; filename=genome.jpeg;
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
163 modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\";
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
164 Content-Description: a complete map of the human genome
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
165 Content-Transfer-Encoding: base64
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
166
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
167 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAABGdBTUEAALGPC/xhBQAAAAZQ
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
168 TFRF////AAAAVcLTfgAAAPZJREFUeNq9ldsOwzAIQ+3//+l1WlvA5ZLsoUiTto4TB+ISoAjy
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
169 +ITfRBfcAmgRFFeAm+J6uhdKdFhFWUgDkFsK0oUp/9G2//Kj7Jx+5tSKOdBscgUYiKHRS/me
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
170 WATQdRUvAK0Bnmshmtn79PpaLBbbOZkjKvRnjRZoRswOkG1wFchKew2g9wXVJVZL/m4+B+vv
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
171 9AxQQR2Q33SgAYJzzVACdAWjAfRYzYFO9n6SLnydtQHSMxYDMAKqZ/8FS/lTK+zuq3CtK64L
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
172 UDwbgUEAUmk2Zyg101d6PhCDySgAvTvDgKiuOrc4dLxUb7UMnhGIexyI+d6U+ABuNAP4Simx
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
173 lgAAAABJRU5ErkJggg==
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
174 "))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
175 (switch-to-buffer (get-buffer-create "*test*"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
176 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
177 (insert mail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
178 (rmail-mime-show)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
179
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
180 (defun rmail-mime-multipart-handler (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
181 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
182 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
183 "Handle the current buffer as a multipart MIME body.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
184 The current buffer should be narrowed to the body. CONTENT-TYPE,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
185 CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING are the values
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
186 of the respective parsed headers. See `rmail-mime-handle' for their
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
187 format."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
188 ;; Some MUAs start boundaries with "--", while it should start
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
189 ;; with "CRLF--", as defined by RFC 2046:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
190 ;; The boundary delimiter MUST occur at the beginning of a line,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
191 ;; i.e., following a CRLF, and the initial CRLF is considered to
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
192 ;; be attached to the boundary delimiter line rather than part
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
193 ;; of the preceding part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
194 ;; We currently don't handle that.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
195 (let ((boundary (cdr (assq 'boundary content-type)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
196 beg end next)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
197 (unless boundary
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
198 (rmail-mm-get-boundary-error-message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
199 "No boundary defined" content-type content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
200 content-transfer-encoding))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
201 (setq boundary (concat "\n--" boundary))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
202 ;; Hide the body before the first bodypart
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
203 (goto-char (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
204 (when (and (search-forward boundary nil t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
205 (looking-at "[ \t]*\n"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
206 (delete-region (point-min) (match-end 0)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
207 ;; Reset the counter
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
208 (setq rmail-mime-total-number-of-bulk-attachments 0)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
209 ;; Loop over all body parts, where beg points at the beginning of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
210 ;; the part and end points at the end of the part. next points at
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
211 ;; the beginning of the next part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
212 (setq beg (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
213 (while (search-forward boundary nil t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
214 (setq end (match-beginning 0))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
215 ;; If this is the last boundary according to RFC 2046, hide the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
216 ;; epilogue, else hide the boundary only. Use a marker for
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
217 ;; `next' because `rmail-mime-show' may change the buffer.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
218 (cond ((looking-at "--[ \t]*\n")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
219 (setq next (point-max-marker)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
220 ((looking-at "[ \t]*\n")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
221 (setq next (copy-marker (match-end 0))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
222 (t
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
223 (rmail-mm-get-boundary-error-message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
224 "Malformed boundary" content-type content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
225 content-transfer-encoding)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
226 (delete-region end next)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
227 ;; Handle the part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
228 (save-match-data
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
229 (save-excursion
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
230 (save-restriction
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
231 (narrow-to-region beg end)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
232 (rmail-mime-show))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
233 (setq beg next)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
234 (goto-char beg))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
235
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
236 (defun test-rmail-mime-multipart-handler ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
237 "Test of a mail used as an example in RFC 2046."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
238 (let ((mail "From: Nathaniel Borenstein <nsb@bellcore.com>
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
239 To: Ned Freed <ned@innosoft.com>
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
240 Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
241 Subject: Sample message
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
242 MIME-Version: 1.0
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
243 Content-type: multipart/mixed; boundary=\"simple boundary\"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
244
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
245 This is the preamble. It is to be ignored, though it
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
246 is a handy place for composition agents to include an
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
247 explanatory note to non-MIME conformant readers.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
248
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
249 --simple boundary
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
250
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
251 This is implicitly typed plain US-ASCII text.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
252 It does NOT end with a linebreak.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
253 --simple boundary
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
254 Content-type: text/plain; charset=us-ascii
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
255
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
256 This is explicitly typed plain US-ASCII text.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
257 It DOES end with a linebreak.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
258
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
259 --simple boundary--
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
260
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
261 This is the epilogue. It is also to be ignored."))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
262 (switch-to-buffer (get-buffer-create "*test*"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
263 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
264 (insert mail)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
265 (rmail-mime-show t)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
266
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
267 ;;; Main code
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
268
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
269 (defun rmail-mime-handle (content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
270 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
271 content-transfer-encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
272 "Handle the current buffer as a MIME part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
273 The current buffer should be narrowed to the respective body, and
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
274 point should be at the beginning of the body.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
275
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
276 CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
277 are the values of the respective parsed headers. The parsed
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
278 headers for CONTENT-TYPE and CONTENT-DISPOSITION have the form
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
279
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
280 \(VALUE . ALIST)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
281
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
282 In other words:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
283
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
284 \(VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
285
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
286 VALUE is a string and ATTRIBUTE is a symbol.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
287
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
288 Consider the following header, for example:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
289
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
290 Content-Type: multipart/mixed;
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
291 boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
292
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
293 The parsed header value:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
294
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
295 \(\"multipart/mixed\"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
296 \(\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
297 ;; Handle the content transfer encodings we know. Unknown transfer
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
298 ;; encodings will be passed on to the various handlers.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
299 (cond ((string= content-transfer-encoding "base64")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
300 (when (ignore-errors
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
301 (base64-decode-region (point) (point-max)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
302 (setq content-transfer-encoding nil)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
303 ((string= content-transfer-encoding "quoted-printable")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
304 (quoted-printable-decode-region (point) (point-max))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
305 (setq content-transfer-encoding nil))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
306 ((string= content-transfer-encoding "8bit")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
307 ;; FIXME: Is this the correct way?
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
308 (set-buffer-multibyte nil)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
309 ;; Inline stuff requires work. Attachments are handled by the bulk
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
310 ;; handler.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
311 (if (string= "inline" (car content-disposition))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
312 (let ((stop nil))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
313 (dolist (entry rmail-mime-media-type-handlers-alist)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
314 (when (and (string-match (car entry) (car content-type)) (not stop))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
315 (progn
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
316 (setq stop (funcall (cadr entry) content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
317 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
318 content-transfer-encoding))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
319 ;; Everything else is an attachment.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
320 (rmail-mime-bulk-handler content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
321 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
322 content-transfer-encoding)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
323
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
324 (defun rmail-mime-show (&optional show-headers)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
325 "Handle the current buffer as a MIME message.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
326 If SHOW-HEADERS is non-nil, then the headers of the current part
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
327 will shown as usual for a MIME message. The headers are also
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
328 shown for the content type message/rfc822. This function will be
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
329 called recursively if multiple parts are available.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
330
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
331 The current buffer must contain a single message. It will be
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
332 modified."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
333 (let ((end (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
334 content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
335 content-transfer-encoding
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
336 content-disposition)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
337 ;; `point-min' returns the beginning and `end' points at the end
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
338 ;; of the headers.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
339 (goto-char (point-min))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
340 ;; If we're showing a part without headers, then it will start
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
341 ;; with a newline.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
342 (if (eq (char-after) ?\n)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
343 (setq end (1+ (point)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
344 (when (search-forward "\n\n" nil t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
345 (setq end (match-end 0))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
346 (save-restriction
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
347 (narrow-to-region (point-min) end)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
348 ;; FIXME: Default disposition of the multipart entities should
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
349 ;; be inherited.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
350 (setq content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
351 (mail-fetch-field "Content-Type")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
352 content-transfer-encoding
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
353 (mail-fetch-field "Content-Transfer-Encoding")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
354 content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
355 (mail-fetch-field "Content-Disposition")))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
356 (if content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
357 (setq content-type (mail-header-parse-content-type
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
358 content-type))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
359 ;; FIXME: Default "message/rfc822" in a "multipart/digest"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
360 ;; according to RFC 2046.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
361 (setq content-type '("text/plain")))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
362 (setq content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
363 (if content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
364 (mail-header-parse-content-disposition content-disposition)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
365 ;; If none specified, we are free to choose what we deem
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
366 ;; suitable according to RFC 2183. We like inline.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
367 '("inline")))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
368 ;; Unrecognized disposition types are to be treated like
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
369 ;; attachment according to RFC 2183.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
370 (unless (member (car content-disposition) '("inline" "attachment"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
371 (setq content-disposition '("attachment")))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
372 ;; Hide headers and handle the part.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
373 (save-restriction
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
374 (cond ((string= (car content-type) "message/rfc822")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
375 (narrow-to-region end (point-max)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
376 ((not show-headers)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
377 (delete-region (point-min) end)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
378 (rmail-mime-handle content-type content-disposition
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
379 content-transfer-encoding))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
380
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
381 (defun rmail-mime ()
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
382 "Copy buffer contents to a temporary buffer and handle MIME.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
383 This calls `rmail-mime-show' to do the real job."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
384 (interactive)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
385 (rmail-swap-buffers-maybe)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
386 (let ((data (with-current-buffer rmail-buffer
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
387 (save-restriction
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
388 (widen)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
389 (buffer-substring
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
390 (rmail-msgbeg rmail-current-message)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
391 (rmail-msgend rmail-current-message)))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
392 (buf (get-buffer-create "*RMAIL*")))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
393 (set-buffer buf)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
394 (let ((inhibit-read-only t))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
395 (erase-buffer)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
396 (insert data)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
397 (rmail-mime-show t))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
398 (view-buffer buf)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
399
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
400 (defun rmail-mm-get-boundary-error-message (message type disposition encoding)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
401 "Return MESSAGE with more information on the main mime components."
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
402 (error "%s; type: %s; disposition: %s; encoding: %s"
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
403 message type disposition encoding))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
404
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
405 (provide 'rmailmm)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
406
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
407 ;; arch-tag: 3f2c5e5d-1aef-4512-bc20-fd737c9d5dd9
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
408 ;;; rmailmm.el ends here