Mercurial > emacs
comparison lisp/gnus/mm-decode.el @ 91239:2fcaae6177a5
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-300
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 16 Dec 2007 05:08:49 +0000 |
parents | 53108e6cea98 b968c7f9a8b4 |
children | 56a72e2bd635 |
comparison
equal
deleted
inserted
replaced
91238:5cf14a2107b5 | 91239:2fcaae6177a5 |
---|---|
24 | 24 |
25 ;;; Commentary: | 25 ;;; Commentary: |
26 | 26 |
27 ;;; Code: | 27 ;;; Code: |
28 | 28 |
29 ;; For Emacs < 22.2. | |
30 (eval-and-compile | |
31 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))) | |
32 | |
29 (require 'mail-parse) | 33 (require 'mail-parse) |
30 (require 'mailcap) | 34 (require 'mailcap) |
31 (require 'mm-bodies) | 35 (require 'mm-bodies) |
36 (require 'gnus-util) | |
32 (eval-when-compile (require 'cl) | 37 (eval-when-compile (require 'cl) |
33 (require 'term)) | 38 (require 'term)) |
34 | 39 |
35 (eval-and-compile | 40 (eval-and-compile |
36 (autoload 'mm-inline-partial "mm-partial") | 41 (autoload 'mm-inline-partial "mm-partial") |
730 (if external | 735 (if external |
731 (mm-display-external | 736 (mm-display-external |
732 handle (or method 'mailcap-save-binary-file)) | 737 handle (or method 'mailcap-save-binary-file)) |
733 (mm-display-external | 738 (mm-display-external |
734 handle 'mailcap-save-binary-file))))))))) | 739 handle 'mailcap-save-binary-file))))))))) |
740 | |
741 (declare-function gnus-configure-windows "gnus-win" (setting &optional force)) | |
735 | 742 |
736 (defun mm-display-external (handle method) | 743 (defun mm-display-external (handle method) |
737 "Display HANDLE using METHOD." | 744 "Display HANDLE using METHOD." |
738 (let ((outbuf (current-buffer))) | 745 (let ((outbuf (current-buffer))) |
739 (mm-with-unibyte-buffer | 746 (mm-with-unibyte-buffer |
988 (let ((object (mm-handle-undisplayer handle))) | 995 (let ((object (mm-handle-undisplayer handle))) |
989 (ignore-errors | 996 (ignore-errors |
990 (cond | 997 (cond |
991 ;; Internally displayed part. | 998 ;; Internally displayed part. |
992 ((mm-annotationp object) | 999 ((mm-annotationp object) |
993 (delete-annotation object)) | 1000 (if (featurep 'xemacs) |
1001 (delete-annotation object))) | |
994 ((or (functionp object) | 1002 ((or (functionp object) |
995 (and (listp object) | 1003 (and (listp object) |
996 (eq (car object) 'lambda))) | 1004 (eq (car object) 'lambda))) |
997 (funcall object)) | 1005 (funcall object)) |
998 ;; Externally displayed part. | 1006 ;; Externally displayed part. |
1229 file))) | 1237 file))) |
1230 (progn | 1238 (progn |
1231 (mm-save-part-to-file handle file) | 1239 (mm-save-part-to-file handle file) |
1232 file)))) | 1240 file)))) |
1233 | 1241 |
1242 (defun mm-add-meta-html-tag (handle &optional charset) | |
1243 "Add meta html tag to specify CHARSET of HANDLE in the current buffer. | |
1244 CHARSET defaults to the one HANDLE specifies. Existing meta tag that | |
1245 specifies charset will not be modified. Return t if meta tag is added | |
1246 or replaced." | |
1247 (when (equal (mm-handle-media-type handle) "text/html") | |
1248 (when (or charset | |
1249 (setq charset (mail-content-type-get (mm-handle-type handle) | |
1250 'charset))) | |
1251 (setq charset (format "\ | |
1252 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">" charset)) | |
1253 (let ((case-fold-search t)) | |
1254 (goto-char (point-min)) | |
1255 (if (re-search-forward "\ | |
1256 <meta\\s-+http-equiv=[\"']?content-type[\"']?\\s-+content=[\"']\ | |
1257 text/\\(\\sw+\\)\\(?:\;\\s-*charset=\\(.+?\\)\\)?[\"'][^>]*>" nil t) | |
1258 (if (and (match-beginning 2) | |
1259 (string-match "\\`html\\'" (match-string 1))) | |
1260 ;; Don't modify existing meta tag. | |
1261 nil | |
1262 ;; Replace it with the one specifying charset. | |
1263 (replace-match charset) | |
1264 t) | |
1265 (if (re-search-forward "<head>\\s-*" nil t) | |
1266 (insert charset "\n") | |
1267 (re-search-forward "<html\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t) | |
1268 (insert "<head>\n" charset "\n</head>\n")) | |
1269 t))))) | |
1270 | |
1234 (defun mm-save-part-to-file (handle file) | 1271 (defun mm-save-part-to-file (handle file) |
1235 (mm-with-unibyte-buffer | 1272 (mm-with-unibyte-buffer |
1236 (mm-insert-part handle) | 1273 (mm-insert-part handle) |
1274 (mm-add-meta-html-tag handle) | |
1237 (let ((current-file-modes (default-file-modes))) | 1275 (let ((current-file-modes (default-file-modes))) |
1238 (set-default-file-modes mm-attachment-file-modes) | 1276 (set-default-file-modes mm-attachment-file-modes) |
1239 (unwind-protect | 1277 (unwind-protect |
1240 ;; Don't re-compress .gz & al. Arguably we should make | 1278 ;; Don't re-compress .gz & al. Arguably we should make |
1241 ;; `file-name-handler-alist' nil, but that would chop | 1279 ;; `file-name-handler-alist' nil, but that would chop |
1248 (let* ((name (mail-content-type-get (mm-handle-type handle) 'name)) | 1286 (let* ((name (mail-content-type-get (mm-handle-type handle) 'name)) |
1249 (command | 1287 (command |
1250 (read-string "Shell command on MIME part: " mm-last-shell-command))) | 1288 (read-string "Shell command on MIME part: " mm-last-shell-command))) |
1251 (mm-with-unibyte-buffer | 1289 (mm-with-unibyte-buffer |
1252 (mm-insert-part handle) | 1290 (mm-insert-part handle) |
1291 (mm-add-meta-html-tag handle) | |
1253 (let ((coding-system-for-write 'binary)) | 1292 (let ((coding-system-for-write 'binary)) |
1254 (shell-command-on-region (point-min) (point-max) command nil))))) | 1293 (shell-command-on-region (point-min) (point-max) command nil))))) |
1255 | 1294 |
1256 (defun mm-interactively-view-part (handle) | 1295 (defun mm-interactively-view-part (handle) |
1257 "Display HANDLE using METHOD." | 1296 "Display HANDLE using METHOD." |
1487 (defsubst mm-set-handle-multipart-parameter (handle parameter value) | 1526 (defsubst mm-set-handle-multipart-parameter (handle parameter value) |
1488 ;; HANDLE could be a CTL. | 1527 ;; HANDLE could be a CTL. |
1489 (when handle | 1528 (when handle |
1490 (put-text-property 0 (length (car handle)) parameter value | 1529 (put-text-property 0 (length (car handle)) parameter value |
1491 (car handle)))) | 1530 (car handle)))) |
1531 | |
1532 (autoload 'mm-view-pkcs7 "mm-view") | |
1492 | 1533 |
1493 (defun mm-possibly-verify-or-decrypt (parts ctl) | 1534 (defun mm-possibly-verify-or-decrypt (parts ctl) |
1494 (let ((type (car ctl)) | 1535 (let ((type (car ctl)) |
1495 (subtype (cadr (split-string (car ctl) "/"))) | 1536 (subtype (cadr (split-string (car ctl) "/"))) |
1496 (mm-security-handle ctl) ;; (car CTL) is the type. | 1537 (mm-security-handle ctl) ;; (car CTL) is the type. |