aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatsumi Yamaoka2010-03-31 06:44:35 +0000
committerKatsumi Yamaoka2010-03-31 06:44:35 +0000
commitd40d713a3da7b59ff57bbc5713e45b4ec5334dae (patch)
tree1695d98d6b3ec3426e05952c0c54f92347fa2d14
parent855a0da7fdb9c33761d7ba3ad6ab66a41bc2d1f3 (diff)
downloademacs-d40d713a3da7b59ff57bbc5713e45b4ec5334dae.tar.gz
emacs-d40d713a3da7b59ff57bbc5713e45b4ec5334dae.zip
(gnus-article-browse-html-save-cid-content): Rename from
gnus-article-browse-html-save-cid-image; make it work recursively for forwarded messages as well. (gnus-article-browse-html-parts): Work when prefix arg is given. (gnus-article-browse-html-article): Doc fix.
-rw-r--r--lisp/gnus/gnus-art.el131
1 files changed, 73 insertions, 58 deletions
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 086eb47d76c..8b9d8b69ff4 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -2827,41 +2827,39 @@ summary buffer."
2827 (setq gnus-article-browse-html-temp-list nil)) 2827 (setq gnus-article-browse-html-temp-list nil))
2828 gnus-article-browse-html-temp-list) 2828 gnus-article-browse-html-temp-list)
2829 2829
2830(defun gnus-article-browse-html-save-cid-image (cid dir) 2830(defun gnus-article-browse-html-save-cid-content (cid handles directory)
2831 "Save CID contents to a file in DIR. Return file name." 2831 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2832Return file name."
2832 (save-match-data 2833 (save-match-data
2833 (gnus-with-article-buffer 2834 (let (file type)
2834 (let (cid-handle cid-tmp-file cid-type) 2835 (catch 'found
2835 (mapc 2836 (dolist (handle handles)
2836 (lambda (handle) 2837 (cond
2837 (when (and (listp handle) 2838 ((not (listp handle)))
2838 (stringp (car (last handle))) 2839 ((equal (mm-handle-media-supertype handle) "multipart")
2839 (string= (format "<%s>" cid) 2840 (when (setq file (gnus-article-browse-html-save-cid-content
2840 (car (last handle)))) 2841 cid handle directory))
2841 (setq cid-handle handle) 2842 (throw 'found file)))
2842 (setq cid-tmp-file 2843 ((equal (concat "<" cid ">") (mm-handle-id handle))
2843 (expand-file-name 2844 (setq file
2844 (or (mail-content-type-get 2845 (expand-file-name
2845 (mm-handle-disposition handle) 'filename) 2846 (or (mail-content-type-get
2846 (mail-content-type-get 2847 (mm-handle-disposition handle) 'filename)
2847 (setq cid-type (mm-handle-type handle)) 'name) 2848 (mail-content-type-get
2848 (concat (make-temp-name "cid") 2849 (setq type (mm-handle-type handle)) 'name)
2849 (or (car (rassoc (car cid-type) 2850 (concat
2850 mailcap-mime-extensions)) 2851 (make-temp-name "cid")
2851 ""))) 2852 (car (rassoc (car type) mailcap-mime-extensions))))
2852 dir)))) 2853 directory))
2853 gnus-article-mime-handles) 2854 (mm-save-part-to-file handle file)
2854 (when (and cid-handle cid-tmp-file) 2855 (throw 'found file))))))))
2855 (mm-save-part-to-file cid-handle
2856 cid-tmp-file)
2857 (concat "file://" cid-tmp-file))))))
2858 2856
2859(defun gnus-article-browse-html-parts (list &optional header) 2857(defun gnus-article-browse-html-parts (list &optional header)
2860 "View all \"text/html\" parts from LIST. 2858 "View all \"text/html\" parts from LIST.
2861Recurse into multiparts. The optional HEADER that should be a decoded 2859Recurse into multiparts. The optional HEADER that should be a decoded
2862message header will be added to the bodies of the \"text/html\" parts." 2860message header will be added to the bodies of the \"text/html\" parts."
2863 ;; Internal function used by `gnus-article-browse-html-article'. 2861 ;; Internal function used by `gnus-article-browse-html-article'.
2864 (let (type file charset tmp-file showed) 2862 (let (type file charset content cid-dir tmp-file showed)
2865 ;; Find and show the html-parts. 2863 ;; Find and show the html-parts.
2866 (dolist (handle list) 2864 (dolist (handle list)
2867 ;; If HTML, show it: 2865 ;; If HTML, show it:
@@ -2884,17 +2882,42 @@ message header will be added to the bodies of the \"text/html\" parts."
2884 (setq handle (mm-handle-cache handle) 2882 (setq handle (mm-handle-cache handle)
2885 type (mm-handle-type handle)) 2883 type (mm-handle-type handle))
2886 (equal (car type) "text/html")))) 2884 (equal (car type) "text/html"))))
2887 (when (or (setq charset (mail-content-type-get type 'charset)) 2885 (setq charset (mail-content-type-get type 'charset)
2888 header 2886 content (mm-get-part handle))
2889 (not file)) 2887 (with-temp-buffer
2888 (if (eq charset 'gnus-decoded)
2889 (mm-enable-multibyte)
2890 (mm-disable-multibyte))
2891 (insert content)
2892 ;; resolve cid contents
2893 (let ((case-fold-search t)
2894 cid-file)
2895 (goto-char (point-min))
2896 (while (re-search-forward "\
2897<img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2898 nil t)
2899 (unless cid-dir
2900 (setq cid-dir (make-temp-file "cid" t))
2901 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2902 (setq file nil
2903 content nil)
2904 (when (setq cid-file
2905 (gnus-article-browse-html-save-cid-content
2906 (match-string 2)
2907 (with-current-buffer gnus-article-buffer
2908 gnus-article-mime-handles)
2909 cid-dir))
2910 (replace-match (concat "file://" cid-file)
2911 nil nil nil 1))))
2912 (unless content (setq content (buffer-string))))
2913 (when (or charset header (not file))
2890 (setq tmp-file (mm-make-temp-file 2914 (setq tmp-file (mm-make-temp-file
2891 ;; Do we need to care for 8.3 filenames? 2915 ;; Do we need to care for 8.3 filenames?
2892 "mm-" nil ".html"))) 2916 "mm-" nil ".html")))
2893 ;; Add a meta html tag to specify charset and a header. 2917 ;; Add a meta html tag to specify charset and a header.
2894 (cond 2918 (cond
2895 (header 2919 (header
2896 (let (title eheader body hcharset coding force-charset 2920 (let (title eheader body hcharset coding force-charset)
2897 cid-image-dir)
2898 (with-temp-buffer 2921 (with-temp-buffer
2899 (mm-enable-multibyte) 2922 (mm-enable-multibyte)
2900 (setq case-fold-search t) 2923 (setq case-fold-search t)
@@ -2917,8 +2940,7 @@ message header will be added to the bodies of the \"text/html\" parts."
2917 charset) 2940 charset)
2918 title (when title 2941 title (when title
2919 (mm-encode-coding-string title charset)) 2942 (mm-encode-coding-string title charset))
2920 body (mm-encode-coding-string (mm-get-part handle) 2943 body (mm-encode-coding-string content charset)
2921 charset)
2922 force-charset t) 2944 force-charset t)
2923 (setq hcharset (mm-find-mime-charset-region (point-min) 2945 (setq hcharset (mm-find-mime-charset-region (point-min)
2924 (point-max))) 2946 (point-max)))
@@ -2940,7 +2962,7 @@ message header will be added to the bodies of the \"text/html\" parts."
2940 title (when title 2962 title (when title
2941 (mm-encode-coding-string 2963 (mm-encode-coding-string
2942 title coding)) 2964 title coding))
2943 body (mm-get-part handle)) 2965 body content)
2944 (setq charset 'utf-8 2966 (setq charset 'utf-8
2945 eheader (mm-encode-coding-string 2967 eheader (mm-encode-coding-string
2946 (buffer-string) charset) 2968 (buffer-string) charset)
@@ -2949,7 +2971,7 @@ message header will be added to the bodies of the \"text/html\" parts."
2949 title charset)) 2971 title charset))
2950 body (mm-encode-coding-string 2972 body (mm-encode-coding-string
2951 (mm-decode-coding-string 2973 (mm-decode-coding-string
2952 (mm-get-part handle) body) 2974 content body)
2953 charset) 2975 charset)
2954 force-charset t))) 2976 force-charset t)))
2955 (setq charset hcharset 2977 (setq charset hcharset
@@ -2958,9 +2980,9 @@ message header will be added to the bodies of the \"text/html\" parts."
2958 title (when title 2980 title (when title
2959 (mm-encode-coding-string 2981 (mm-encode-coding-string
2960 title coding)) 2982 title coding))
2961 body (mm-get-part handle))) 2983 body content))
2962 (setq eheader (mm-string-as-unibyte (buffer-string)) 2984 (setq eheader (mm-string-as-unibyte (buffer-string))
2963 body (mm-get-part handle)))) 2985 body content)))
2964 (erase-buffer) 2986 (erase-buffer)
2965 (mm-disable-multibyte) 2987 (mm-disable-multibyte)
2966 (insert body) 2988 (insert body)
@@ -2977,27 +2999,14 @@ message header will be added to the bodies of the \"text/html\" parts."
2977 (re-search-forward 2999 (re-search-forward
2978 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)) 3000 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2979 (insert eheader) 3001 (insert eheader)
2980 ;; resolve cid images
2981 (while (re-search-forward
2982 "<img src=\"\\(cid:\\([^\"]+\\)\\)\""
2983 nil t)
2984 (unless cid-image-dir
2985 (setq cid-image-dir (make-temp-file "cid" t))
2986 (add-to-list 'gnus-article-browse-html-temp-list
2987 cid-image-dir))
2988 (replace-match
2989 (gnus-article-browse-html-save-cid-image
2990 (match-string 2) cid-image-dir)
2991 nil nil nil 1))
2992 (mm-write-region (point-min) (point-max) 3002 (mm-write-region (point-min) (point-max)
2993 tmp-file nil nil nil 'binary t)))) 3003 tmp-file nil nil nil 'binary t))))
2994 (charset 3004 (charset
2995 (mm-with-unibyte-buffer 3005 (mm-with-unibyte-buffer
2996 (insert (if (eq charset 'gnus-decoded) 3006 (insert (if (eq charset 'gnus-decoded)
2997 (mm-encode-coding-string 3007 (mm-encode-coding-string content
2998 (mm-get-part handle) 3008 (setq charset 'utf-8))
2999 (setq charset 'utf-8)) 3009 content))
3000 (mm-get-part handle)))
3001 (if (or (mm-add-meta-html-tag handle charset) 3010 (if (or (mm-add-meta-html-tag handle charset)
3002 (not file)) 3011 (not file))
3003 (mm-write-region (point-min) (point-max) 3012 (mm-write-region (point-min) (point-max)
@@ -3044,17 +3053,23 @@ message header will be added to the bodies of the \"text/html\" parts."
3044 3053
3045(defun gnus-article-browse-html-article (&optional arg) 3054(defun gnus-article-browse-html-article (&optional arg)
3046 "View \"text/html\" parts of the current article with a WWW browser. 3055 "View \"text/html\" parts of the current article with a WWW browser.
3056Inline images embedded in a message using the cid scheme, as they are
3057generally considered to be safe, will be processed properly.
3047The message header is added to the beginning of every html part unless 3058The message header is added to the beginning of every html part unless
3048the prefix argument ARG is given. 3059the prefix argument ARG is given.
3049 3060
3050Warning: Spammers use links to images in HTML articles to verify 3061Warning: Spammers use links to images (using the http scheme) in HTML
3051whether you have read the message. As 3062articles to verify whether you have read the message. As
3052`gnus-article-browse-html-article' passes the HTML content to the 3063`gnus-article-browse-html-article' passes the HTML content to the
3053browser without eliminating these \"web bugs\" you should only 3064browser without eliminating these \"web bugs\" you should only
3054use it for mails from trusted senders. 3065use it for mails from trusted senders.
3055 3066
3056If you always want to display HTML parts in the browser, set 3067If you always want to display HTML parts in the browser, set
3057`mm-text-html-renderer' to nil." 3068`mm-text-html-renderer' to nil.
3069
3070This command creates temporary files to pass HTML contents including
3071images if any to the browser, and deletes them when exiting the group
3072\(if you want)."
3058 ;; Cf. `mm-w3m-safe-url-regexp' 3073 ;; Cf. `mm-w3m-safe-url-regexp'
3059 (interactive "P") 3074 (interactive "P")
3060 (if arg 3075 (if arg