1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-22 18:35:09 +00:00
emacs/lisp/gnus/mm-archive.el

110 lines
3.5 KiB
EmacsLisp
Raw Normal View History

;;; mm-archive.el --- Functions for parsing archive files as MIME
;; Copyright (C) 2012-2021 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'mm-decode)
Replace instances of "(eval-when-compile (autoload ...))" * lisp/gnus/gnus-art.el (nneething-get-file-name): Declare rather than autoload. * lisp/gnus/gnus-async.el (gnus-html-prefetch-images): Remove pointless autoload. * lisp/gnus/gnus-sync.el (gnus-group-topic): Autoload at run-time. (gnus-topic-create-topic, gnus-topic-enter-dribble): Declare rather than autoload. * lisp/gnus/mm-archive.el (gnus-recursive-directory-files) (mailcap-extension-to-mime): Autoload at run-time. * lisp/gnus/mm-util.el (latin-unity-massage-name) (latin-unity-maybe-remap, latin-unity-representations-feasible-region) (latin-unity-representations-present-region): Declare rather than autoload. * lisp/gnus/mml-smime.el (epg-make-context) (epg-passphrase-callback-function): Autoload at run-time. (epg-context-set-signers, epg-context-result-for) (epg-new-signature-digest-algorithm) (epg-verify-result-to-string, epg-list-keys, epg-verify-string) (epg-sign-string, epg-encrypt-string) (epg-context-set-passphrase-callback, epg-sub-key-fingerprint) (epg-configuration, epg-expand-group, epa-select-keys): Declare rather than autoload. * lisp/gnus/nnir.el (nnimap-change-group, nnimap-make-thread-query): Autoload at run-time. (gnus-group-topic-name, nnimap-buffer, nnimap-command) (gnus-registry-get-id-key, gnus-registry-action): Declare rather than autoload. * lisp/gnus/nnmail.el (mail-send-and-exit): Autoload at run-time. * lisp/gnus/spam.el (spam-stat-buffer-change-to-non-spam) (spam-stat-buffer-change-to-spam, spam-stat-buffer-is-non-spam) (spam-stat-buffer-is-spam, spam-stat-load, spam-stat-save) (spam-stat-split-fancy): Remove pointless autoloads. * lisp/net/mairix.el: Load gnus-util when compiling. (gnus-group-read-ephemeral-group, gnus-summary-toggle-header) (message-field-value): Declare rather than autoload. (mairix-gnus-ephemeral-nndoc, mairix-gnus-fetch-field): Check gnus-alive-p is fbound. (vm-quit, vm-visit-folder, vm-select-folder-buffer) (vm-check-for-killed-summary, vm-error-if-folder-empty) (vm-get-header-contents, vm-select-marked-or-prefixed-messages): Declare rather than autoload.
2015-05-05 00:38:16 +00:00
(autoload 'gnus-recursive-directory-files "gnus-util")
(autoload 'mailcap-extension-to-mime "mailcap")
(defvar mm-archive-decoders
'(("application/ms-tnef" t "tnef" "-f" "-" "-C")
("application/zip" nil "unzip" "-j" "-x" "%f" "-d")
("application/x-gtar-compressed" nil "tar" "xzf" "-" "-C")
("application/x-tar-gz" nil "tar" "xzf" "-" "-C")
("application/x-tar" nil "tar" "xf" "-" "-C")))
(defun mm-archive-decoders () mm-archive-decoders)
(defun mm-dissect-archive (handle)
(let* ((type (car (mm-handle-type handle)))
(decoder (cddr (assoc type mm-archive-decoders)))
dir)
(unless decoder
(error "No decoder found for %s" type))
(setq dir (make-temp-file (expand-file-name "emm." mm-tmp-directory) 'dir))
(set-file-modes dir #o700)
(unwind-protect
(progn
(mm-with-unibyte-buffer
(mm-insert-part handle)
(if (member "%f" decoder)
(let ((file (expand-file-name "mail.zip" dir)))
(write-region (point-min) (point-max) file nil 'silent)
(setq decoder (copy-sequence decoder))
(setcar (member "%f" decoder) file)
(apply 'call-process (car decoder) nil nil nil
(append (cdr decoder) (list dir)))
(delete-file file))
(apply 'call-process-region (point-min) (point-max) (car decoder)
nil (get-buffer-create "*tnef*")
nil (append (cdr decoder) (list dir)))))
`("multipart/mixed"
,handle
,@(mm-archive-list-files (gnus-recursive-directory-files dir))))
(delete-directory dir t))))
(defun mm-archive-list-files (files)
(let ((handles nil)
type disposition)
(dolist (file files)
(with-temp-buffer
(when (string-match "\\.\\([^.]+\\)$" file)
(setq type (mailcap-extension-to-mime (match-string 1 file))))
(unless type
(setq type "application/octet-stream"))
(setq disposition
(if (string-match "^image/\\|^text/" type)
"inline"
"attachment"))
(insert (format "Content-type: %s\n" type))
(insert "Content-Transfer-Encoding: 8bit\n\n")
(insert-file-contents file)
(push
(mm-make-handle (mm-copy-to-buffer)
(list type)
'8bit nil
`(,disposition (filename . ,file))
nil nil nil)
handles)))
handles))
(defun mm-archive-dissect-and-inline (handle)
(let ((start (point-marker)))
(save-restriction
(narrow-to-region (point) (point))
(dolist (handle (cddr (mm-dissect-archive handle)))
(goto-char (point-max))
(mm-display-inline handle))
(goto-char (point-max))
(mm-handle-set-undisplayer
handle
`(lambda ()
(let ((inhibit-read-only t)
(end ,(point-marker)))
(remove-images ,start end)
(delete-region ,start end)))))))
(provide 'mm-archive)
;; mm-archive.el ends here