+(eval-when-compile (require 'cl)
+ (require 'term))
+
+(eval-and-compile
+ (autoload 'mm-inline-partial "mm-partial")
+ (autoload 'mm-inline-external-body "mm-extern")
+ (autoload 'mm-extern-cache-contents "mm-extern")
+ (autoload 'mm-insert-inline "mm-view"))
+
+(defvar gnus-current-window-configuration)
+
+(add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
+
+(defgroup mime-display ()
+ "Display of MIME in mail and news articles."
+ :link '(custom-manual "(emacs-mime)Display Customization")
+ :version "21.1"
+ :group 'mail
+ :group 'news
+ :group 'multimedia)
+
+(defgroup mime-security ()
+ "MIME security in mail and news articles."
+ :link '(custom-manual "(emacs-mime)Display Customization")
+ :group 'mail
+ :group 'news
+ :group 'multimedia)
+
+;;; Convenience macros.
+
+(defmacro mm-handle-buffer (handle)
+ `(nth 0 ,handle))
+(defmacro mm-handle-type (handle)
+ `(nth 1 ,handle))
+(defsubst mm-handle-media-type (handle)
+ (if (stringp (car handle))
+ (car handle)
+ (car (mm-handle-type handle))))
+(defsubst mm-handle-media-supertype (handle)
+ (car (split-string (mm-handle-media-type handle) "/")))
+(defsubst mm-handle-media-subtype (handle)
+ (cadr (split-string (mm-handle-media-type handle) "/")))
+(defmacro mm-handle-encoding (handle)
+ `(nth 2 ,handle))
+(defmacro mm-handle-undisplayer (handle)
+ `(nth 3 ,handle))
+(defmacro mm-handle-set-undisplayer (handle function)
+ `(setcar (nthcdr 3 ,handle) ,function))
+(defmacro mm-handle-disposition (handle)
+ `(nth 4 ,handle))
+(defmacro mm-handle-description (handle)
+ `(nth 5 ,handle))
+(defmacro mm-handle-cache (handle)
+ `(nth 6 ,handle))
+(defmacro mm-handle-set-cache (handle contents)
+ `(setcar (nthcdr 6 ,handle) ,contents))
+(defmacro mm-handle-id (handle)
+ `(nth 7 ,handle))
+(defmacro mm-handle-multipart-original-buffer (handle)
+ `(get-text-property 0 'buffer (car ,handle)))
+(defmacro mm-handle-multipart-from (handle)
+ `(get-text-property 0 'from (car ,handle)))
+(defmacro mm-handle-multipart-ctl-parameter (handle parameter)
+ `(get-text-property 0 ,parameter (car ,handle)))
+
+(defmacro mm-make-handle (&optional buffer type encoding undisplayer
+ disposition description cache
+ id)
+ `(list ,buffer ,type ,encoding ,undisplayer
+ ,disposition ,description ,cache ,id))
+
+(defcustom mm-text-html-renderer
+ (cond ((locate-library "w3") 'w3)
+ ((executable-find "w3m") (if (locate-library "w3m")
+ 'w3m
+ 'w3m-standalone))
+ ((executable-find "links") 'links)
+ ((executable-find "lynx") 'lynx)
+ (t 'html2text))
+ "Render of HTML contents.
+It is one of defined renderer types, or a rendering function.
+The defined renderer types are:
+`w3' : use Emacs/W3;
+`w3m' : use emacs-w3m;
+`w3m-standalone': use w3m;
+`links': use links;
+`lynx' : use lynx;
+`html2text' : use html2text;
+nil : use external viewer."
+ :version "22.1"
+ :type '(choice (const w3)
+ (const w3m)
+ (const w3m-standalone)
+ (const links)
+ (const lynx)
+ (const html2text)
+ (const nil)
+ (function))
+ :group 'mime-display)
+
+(defvar mm-inline-text-html-renderer nil
+ "Function used for rendering inline HTML contents.
+It is suggested to customize `mm-text-html-renderer' instead.")
+
+(defcustom mm-inline-text-html-with-images nil
+ "If non-nil, Gnus will allow retrieving images in HTML contents with
+the <img> tags. It has no effect on Emacs/w3. See also the
+documentation for the `mm-w3m-safe-url-regexp' variable."
+ :version "22.1"
+ :type 'boolean
+ :group 'mime-display)
+
+(defcustom mm-w3m-safe-url-regexp "\\`cid:"
+ "Regexp matching URLs which are considered to be safe.
+Some HTML mails might contain a nasty trick used by spammers, using
+the <img> tag which is far more evil than the [Click Here!] button.
+It is most likely intended to check whether the ominous spam mail has
+reached your eyes or not, in which case the spammer knows for sure
+that your email address is valid. It is done by embedding an
+identifier string into a URL that you might automatically retrieve
+when displaying the image. The default value is \"\\\\`cid:\" which only
+matches parts embedded to the Multipart/Related type MIME contents and
+Gnus will never connect to the spammer's site arbitrarily. You may
+set this variable to nil if you consider all urls to be safe."
+ :version "22.1"
+ :type '(choice (regexp :tag "Regexp")
+ (const :tag "All URLs are safe" nil))
+ :group 'mime-display)
+
+(defcustom mm-inline-text-html-with-w3m-keymap t
+ "If non-nil, use emacs-w3m command keys in the article buffer."
+ :version "22.1"
+ :type 'boolean
+ :group 'mime-display)
+
+(defcustom mm-enable-external t
+ "Indicate whether external MIME handlers should be used.
+
+If t, all defined external MIME handlers are used. If nil, files are saved by
+`mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
+before the external MIME handler is invoked."
+ :version "22.1"
+ :type '(choice (const :tag "Always" t)
+ (const :tag "Never" nil)
+ (const :tag "Ask" ask))
+ :group 'mime-display)
+
+(defcustom mm-inline-media-tests
+ '(("image/p?jpeg"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'jpeg handle)))
+ ("image/png"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'png handle)))
+ ("image/gif"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'gif handle)))
+ ("image/tiff"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'tiff handle)) )
+ ("image/xbm"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'xbm handle)))
+ ("image/x-xbitmap"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'xbm handle)))
+ ("image/xpm"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'xpm handle)))
+ ("image/x-xpixmap"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'xpm handle)))
+ ("image/bmp"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'bmp handle)))
+ ("image/x-portable-bitmap"
+ mm-inline-image
+ (lambda (handle)
+ (mm-valid-and-fit-image-p 'pbm handle)))
+ ("text/plain" mm-inline-text identity)
+ ("text/enriched" mm-inline-text identity)
+ ("text/richtext" mm-inline-text identity)
+ ("text/x-patch" mm-display-patch-inline
+ (lambda (handle)
+ ;; If the diff-mode.el package is installed, the function is
+ ;; autoloaded. Checking (locate-library "diff-mode") would be trying
+ ;; to cater to broken installations. OTOH checking the function
+ ;; makes it possible to install another package which provides an
+ ;; alternative implementation of diff-mode. --Stef
+ (fboundp 'diff-mode)))
+ ("application/emacs-lisp" mm-display-elisp-inline identity)
+ ("application/x-emacs-lisp" mm-display-elisp-inline identity)
+ ("text/dns" mm-display-dns-inline identity)
+ ("text/html"
+ mm-inline-text-html
+ (lambda (handle)
+ (or mm-inline-text-html-renderer
+ mm-text-html-renderer)))
+ ("text/x-vcard"
+ mm-inline-text-vcard
+ (lambda (handle)
+ (or (featurep 'vcard)
+ (locate-library "vcard"))))
+ ("message/delivery-status" mm-inline-text identity)
+ ("message/rfc822" mm-inline-message identity)
+ ("message/partial" mm-inline-partial identity)
+ ("message/external-body" mm-inline-external-body identity)
+ ("text/.*" mm-inline-text identity)
+ ("audio/wav" mm-inline-audio
+ (lambda (handle)
+ (and (or (featurep 'nas-sound) (featurep 'native-sound))
+ (device-sound-enabled-p))))
+ ("audio/au"
+ mm-inline-audio
+ (lambda (handle)
+ (and (or (featurep 'nas-sound) (featurep 'native-sound))
+ (device-sound-enabled-p))))
+ ("application/pgp-signature" ignore identity)
+ ("application/x-pkcs7-signature" ignore identity)
+ ("application/pkcs7-signature" ignore identity)
+ ("application/x-pkcs7-mime" ignore identity)
+ ("application/pkcs7-mime" ignore identity)
+ ("multipart/alternative" ignore identity)
+ ("multipart/mixed" ignore identity)
+ ("multipart/related" ignore identity)
+ ;; Disable audio and image
+ ("audio/.*" ignore ignore)
+ ("image/.*" ignore ignore)
+ ;; Default to displaying as text
+ (".*" mm-inline-text mm-readable-p))
+ "Alist of media types/tests saying whether types can be displayed inline."
+ :type '(repeat (list (regexp :tag "MIME type")
+ (function :tag "Display function")
+ (function :tag "Display test")))
+ :group 'mime-display)
+
+(defcustom mm-inlined-types
+ '("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
+ "message/partial" "message/external-body" "application/emacs-lisp"
+ "application/x-emacs-lisp"
+ "application/pgp-signature" "application/x-pkcs7-signature"
+ "application/pkcs7-signature" "application/x-pkcs7-mime"
+ "application/pkcs7-mime"
+ ;; Mutt still uses this even though it has already been withdrawn.
+ "application/pgp")
+ "List of media types that are to be displayed inline.
+See also `mm-inline-media-tests', which says how to display a media
+type inline."
+ :type '(repeat regexp)
+ :group 'mime-display)
+
+(defcustom mm-keep-viewer-alive-types
+ '("application/postscript" "application/msword" "application/vnd.ms-excel"
+ "application/pdf" "application/x-dvi")
+ "List of media types for which the external viewer will not be killed
+when selecting a different article."
+ :version "22.1"
+ :type '(repeat regexp)
+ :group 'mime-display)
+
+(defcustom mm-automatic-display
+ '("text/plain" "text/enriched" "text/richtext" "text/html" "text/x-verbatim"
+ "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
+ "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
+ "application/emacs-lisp" "application/x-emacs-lisp"
+ "application/x-pkcs7-signature"
+ "application/pkcs7-signature" "application/x-pkcs7-mime"
+ "application/pkcs7-mime"
+ ;; Mutt still uses this even though it has already been withdrawn.
+ "application/pgp")
+ "A list of MIME types to be displayed automatically."
+ :type '(repeat regexp)
+ :group 'mime-display)
+
+(defcustom mm-attachment-override-types '("text/x-vcard"
+ "application/pkcs7-mime"
+ "application/x-pkcs7-mime"
+ "application/pkcs7-signature"
+ "application/x-pkcs7-signature")
+ "Types to have \"attachment\" ignored if they can be displayed inline."
+ :type '(repeat regexp)
+ :group 'mime-display)
+
+(defcustom mm-inline-override-types nil
+ "Types to be treated as attachments even if they can be displayed inline."
+ :type '(repeat regexp)
+ :group 'mime-display)
+
+(defcustom mm-automatic-external-display nil
+ "List of MIME type regexps that will be displayed externally automatically."
+ :type '(repeat regexp)
+ :group 'mime-display)
+
+(defcustom mm-discouraged-alternatives nil
+ "List of MIME types that are discouraged when viewing multipart/alternative.
+Viewing agents are supposed to view the last possible part of a message,
+as that is supposed to be the richest. However, users may prefer other
+types instead, and this list says what types are most unwanted. If,
+for instance, text/html parts are very unwanted, and text/richtext are
+somewhat unwanted, then the value of this variable should be set
+to:
+
+ (\"text/html\" \"text/richtext\")
+
+Adding \"image/.*\" might also be useful. Spammers use it as the
+prefered part of multipart/alternative messages. See also
+`gnus-buttonized-mime-types', to which adding \"multipart/alternative\"
+enables you to choose manually one of two types those mails include."
+ :type '(repeat regexp) ;; See `mm-preferred-alternative-precedence'.
+ :group 'mime-display)
+
+(defcustom mm-tmp-directory
+ (if (fboundp 'temp-directory)
+ (temp-directory)
+ (if (boundp 'temporary-file-directory)
+ temporary-file-directory
+ "/tmp/"))
+ "Where mm will store its temporary files."
+ :type 'directory
+ :group 'mime-display)
+
+(defcustom mm-inline-large-images nil
+ "If non-nil, then all images fit in the buffer."
+ :type 'boolean
+ :group 'mime-display)
+
+(defvar mm-file-name-rewrite-functions
+ '(mm-file-name-delete-control mm-file-name-delete-gotchas)
+ "*List of functions used for rewriting file names of MIME parts.
+Each function takes a file name as input and returns a file name.
+
+Ready-made functions include
+`mm-file-name-delete-control'
+`mm-file-name-delete-gotchas'
+`mm-file-name-delete-whitespace',
+`mm-file-name-trim-whitespace',
+`mm-file-name-collapse-whitespace',
+`mm-file-name-replace-whitespace',
+`capitalize', `downcase', `upcase', and
+`upcase-initials'.")
+
+(defvar mm-path-name-rewrite-functions nil
+ "*List of functions for rewriting the full file names of MIME parts.
+This is used when viewing parts externally, and is meant for
+transforming the absolute name so that non-compliant programs can find
+the file where it's saved.
+
+Each function takes a file name as input and returns a file name.")