;;; mm-decode.el --- Functions for decoding MIME things
-;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2013 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
(require 'mail-parse)
(require 'mm-bodies)
-(eval-when-compile (require 'cl)
- (require 'term))
+(eval-when-compile (require 'cl))
(autoload 'gnus-map-function "gnus-util")
(autoload 'gnus-replace-in-string "gnus-util")
(defvar mm-last-shell-command "")
(defvar mm-content-id-alist nil)
(defvar mm-postponed-undisplay-list nil)
+(defvar mm-inhibit-auto-detect-attachment nil)
;; According to RFC2046, in particular, in a digest, the default
;; Content-Type value for a body part is changed from "text/plain" to
(autoload 'message-fetch-field "message")
(defun mm-dissect-buffer (&optional no-strict-mime loose-mime from)
- "Dissect the current buffer and return a list of MIME handles."
+ "Dissect the current buffer and return a list of MIME handles.
+If NO-STRICT-MIME, don't require the message to have a
+MIME-Version header before proceeding."
(save-excursion
(let (ct ctl type subtype cte cd description id result)
(save-restriction
;; Guess what the type of application/octet-stream parts should
;; really be.
(let ((filename (cdr (assq 'filename (cdr cdl)))))
- (when (and (equal (car ctl) "application/octet-stream")
+ (when (and (not mm-inhibit-auto-detect-attachment)
+ (equal (car ctl) "application/octet-stream")
filename
(string-match "\\.\\([^.]+\\)$" filename))
(let ((new-type (mailcap-extension-to-mime (match-string 1 filename))))
(goto-char (point-max))
(if (re-search-backward close-delimiter nil t)
(match-beginning 0)
- (point-max)))))
+ (point-max))))
+ (mm-inhibit-auto-detect-attachment
+ (equal (car ctl) "multipart/encrypted")))
(setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
(while (and (< (point) end) (re-search-forward boundary end t))
(goto-char (match-beginning 0))
(mail-content-type-get
(mm-handle-type handle) 'name)
"<file>"))
- (external mm-enable-external))
- (if (and (mm-inlinable-p ehandle)
- (mm-inlined-p ehandle))
- (progn
- (forward-line 1)
- (mm-display-inline handle)
- 'inline)
- (when (or method
- (not no-default))
- (if (and (not method)
- (equal "text" (car (split-string type "/"))))
- (progn
- (forward-line 1)
- (mm-insert-inline handle (mm-get-part handle))
- 'inline)
- (setq external
- (and method ;; If nil, we always use "save".
+ (external mm-enable-external)
+ (decoder (assoc (car (mm-handle-type handle))
+ (mm-archive-decoders))))
+ (cond
+ ((and decoder
+ (executable-find (caddr decoder)))
+ (mm-archive-dissect-and-inline handle)
+ 'inline)
+ ((and (mm-inlinable-p ehandle)
+ (mm-inlined-p ehandle))
+ (forward-line 1)
+ (mm-display-inline handle)
+ 'inline)
+ ((or method
+ (not no-default))
+ (if (and (not method)
+ (equal "text" (car (split-string type "/"))))
+ (progn
+ (forward-line 1)
+ (mm-insert-inline handle (mm-get-part handle))
+ 'inline)
+ (setq external
+ (and method ;; If nil, we always use "save".
(stringp method) ;; 'mailcap-save-binary-file
(or (eq mm-enable-external t)
(and (eq mm-enable-external 'ask)
(concat
" \"" (format method filename) "\"")
"")
- "? "))))))
- (if external
- (mm-display-external
- handle (or method 'mailcap-save-binary-file))
+ "? "))))))
+ (if external
(mm-display-external
- handle 'mailcap-save-binary-file)))))))))
+ handle (or method 'mailcap-save-binary-file))
+ (mm-display-external
+ handle 'mailcap-save-binary-file)))))))))
(declare-function gnus-configure-windows "gnus-win" (setting &optional force))
(defvar mailcap-mime-extensions) ; mailcap-mime-info autoloads
+(declare-function term-mode "term" ())
+(declare-function term-char-mode "term" ())
(defun mm-display-external (handle method)
"Display HANDLE using METHOD."
(when filename
(setq filename (gnus-map-function mm-file-name-rewrite-functions
(file-name-nondirectory filename))))
- (setq file
- (read-file-name
- (or prompt
- (format "Save MIME part to (default %s): "
- (or filename "")))
- (or mm-default-directory default-directory)
- (expand-file-name (or filename "")
- (or mm-default-directory default-directory))))
+ (while
+ (progn
+ (setq file
+ (read-file-name
+ (or prompt
+ (format "Save MIME part to (default %s): "
+ (or filename "")))
+ (or mm-default-directory default-directory)
+ (expand-file-name (or filename "")
+ (or mm-default-directory default-directory))))
+ (cond ((or (not file) (equal file ""))
+ (message "Please enter a file name")
+ t)
+ ((and (file-directory-p file)
+ (not filename))
+ (message "Please enter a non-directory file name")
+ t)
+ (t nil)))
+ (sit-for 2)
+ (discard-input))
(if (file-directory-p file)
(setq file (expand-file-name filename file))
(setq file (expand-file-name
(insert (prog1
(if (and charset
(setq charset
- (mm-charset-to-coding-system charset))
+ (mm-charset-to-coding-system charset
+ nil t))
(not (eq charset 'ascii)))
(mm-decode-coding-string (buffer-string) charset)
(mm-string-as-multibyte (buffer-string)))
(replace-match (char-to-string char))))
;; Remove "soft hyphens".
(goto-char (point-min))
- (while (search-forward "" nil t)
+ (while (search-forward "Â" nil t)
(replace-match "" t t))
(libxml-parse-html-region (point-min) (point-max))))
(unless (bobp)
(insert "\n"))
+ (mm-convert-shr-links)
(mm-handle-set-undisplayer
handle
`(lambda ()
(delete-region ,(point-min-marker)
,(point-max-marker))))))))
+(defvar shr-map)
+
+(autoload 'widget-convert-button "wid-edit")
+
+(defun mm-convert-shr-links ()
+ (let ((start (point-min))
+ end)
+ (while (and start
+ (< start (point-max)))
+ (when (setq start (text-property-not-all start (point-max) 'shr-url nil))
+ (setq end (next-single-property-change start 'shr-url nil (point-max)))
+ (widget-convert-button
+ 'url-link start end
+ :help-echo (get-text-property start 'help-echo)
+ :keymap shr-map
+ (get-text-property start 'shr-url))
+ (put-text-property start end 'local-map nil)
+ (setq start end)))))
+
(defun mm-handle-filename (handle)
"Return filename of HANDLE if any."
(or (mail-content-type-get (mm-handle-type handle)
(provide 'mm-decode)
+;; Local Variables:
+;; coding: utf-8
+;; End:
+
;;; mm-decode.el ends here