Function: rmail-mime-save
rmail-mime-save is a byte-compiled function defined in rmailmm.el.gz.
Signature
(rmail-mime-save BUTTON)
Documentation
Save the attachment using info in the BUTTON.
Source Code
;; Defined in /usr/src/emacs/lisp/mail/rmailmm.el.gz
(defun rmail-mime-save (button)
"Save the attachment using info in the BUTTON."
(let* ((rmail-mime-mbox-buffer rmail-view-buffer)
(filename (button-get button 'filename))
(directory (button-get button 'directory))
(data (button-get button 'data))
(ofilename filename))
(if (and (not (stringp data))
(rmail-mime-entity-truncated data))
(unless (y-or-n-p "This entity is truncated; save anyway? ")
(error "Aborted")))
(setq filename (expand-file-name
(read-file-name (format-prompt "Save as" filename)
directory
(expand-file-name filename directory))
directory))
;; If arg is just a directory, use the default file name, but in
;; that directory (copied from write-file).
(if (file-directory-p filename)
(setq filename (expand-file-name
(file-name-nondirectory ofilename)
(file-name-as-directory filename))))
(with-temp-buffer
(set-buffer-file-coding-system 'no-conversion)
;; Needed e.g. by jka-compr, so if the attachment is a compressed
;; file, the magic signature compares equal with the unibyte
;; signature string recorded in jka-compr-compression-info-list.
(set-buffer-multibyte nil)
(setq buffer-undo-list t)
(if (stringp data)
(insert data)
;; DATA is a MIME-entity object.
(let ((transfer-encoding (rmail-mime-entity-transfer-encoding data))
(body (rmail-mime-entity-body data)))
(insert-buffer-substring rmail-mime-mbox-buffer
(aref body 0) (aref body 1))
(cond ((string= transfer-encoding "base64")
(ignore-errors (base64-decode-region (point-min) (point-max))))
((string= transfer-encoding "quoted-printable")
(quoted-printable-decode-region (point-min) (point-max))))))
(write-region nil nil filename nil nil nil t))
(pcase rmail-mime-save-action
('nil nil)
('visit-file
(when (yes-or-no-p (format "Visit attachment `%s' in Emacs? "
(file-name-nondirectory filename)))
(find-file filename)))
('visit-directory
(when (yes-or-no-p (format "Visit attachment `%s' in Dired? "
(file-name-nondirectory filename)))
(dired-jump nil filename)))
('open-external
(when (yes-or-no-p (format "Open attachment `%s' with external program? "
(file-name-nondirectory filename)))
(shell-command-do-open (list filename))))
((pred functionp) (funcall rmail-mime-save-action filename)))))