aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatsumi Yamaoka2015-04-03 03:18:52 +0000
committerKatsumi Yamaoka2015-04-03 03:18:52 +0000
commit839decd9ecbfa4ec4183ac69037f5aa882bdc47c (patch)
treec981ad82b85e45fb6bc6b8d1ca8f829c8741c35c
parent0c2ea36d2032ef47a0d6520b3e513459e072a553 (diff)
downloademacs-839decd9ecbfa4ec4183ac69037f5aa882bdc47c.tar.gz
emacs-839decd9ecbfa4ec4183ac69037f5aa882bdc47c.zip
lisp/gnus/gnus-art.el (gnus-article-browse-html-parts): Make external links absolute and cid file names relative
-rw-r--r--lisp/gnus/ChangeLog7
-rw-r--r--lisp/gnus/gnus-art.el60
2 files changed, 40 insertions, 27 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 95ead23cb51..14734e3e40d 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,10 @@
12015-04-03 Katsumi Yamaoka <yamaoka@jpl.org>
2
3 * gnus-art.el (gnus-article-browse-html-save-cid-content):
4 Always return relative file name.
5 (gnus-article-browse-html-parts):
6 Make external links absolute and cid file names relative.
7
12015-04-01 Eric Abrahamsen <eric@ericabrahamsen.net> 82015-04-01 Eric Abrahamsen <eric@ericabrahamsen.net>
2 9
3 * registry.el (registry-prune): Re-use `registry-full' in 10 * registry.el (registry-prune): Re-use `registry-full' in
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 19da2cce42f..5ec1268aee7 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -50,6 +50,7 @@
50(autoload 'ansi-color-apply-on-region "ansi-color") 50(autoload 'ansi-color-apply-on-region "ansi-color")
51(autoload 'mm-url-insert-file-contents-external "mm-url") 51(autoload 'mm-url-insert-file-contents-external "mm-url")
52(autoload 'mm-extern-cache-contents "mm-extern") 52(autoload 'mm-extern-cache-contents "mm-extern")
53(autoload 'url-expand-file-name "url-expand")
53 54
54(defgroup gnus-article nil 55(defgroup gnus-article nil
55 "Article display." 56 "Article display."
@@ -2792,10 +2793,9 @@ summary buffer."
2792 (setq gnus-article-browse-html-temp-list nil)) 2793 (setq gnus-article-browse-html-temp-list nil))
2793 gnus-article-browse-html-temp-list) 2794 gnus-article-browse-html-temp-list)
2794 2795
2795(defun gnus-article-browse-html-save-cid-content (cid handles directory abs) 2796(defun gnus-article-browse-html-save-cid-content (cid handles directory)
2796 "Find CID content in HANDLES and save it in a file in DIRECTORY. 2797 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2797Return absolute file name if ABS is non-nil, otherwise relative to 2798Return file name relative to the parent of DIRECTORY."
2798the parent of DIRECTORY."
2799 (save-match-data 2799 (save-match-data
2800 (let (file afile) 2800 (let (file afile)
2801 (catch 'found 2801 (catch 'found
@@ -2807,7 +2807,7 @@ the parent of DIRECTORY."
2807 ((not (or (bufferp (car handle)) (stringp (car handle))))) 2807 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2808 ((equal (mm-handle-media-supertype handle) "multipart") 2808 ((equal (mm-handle-media-supertype handle) "multipart")
2809 (when (setq file (gnus-article-browse-html-save-cid-content 2809 (when (setq file (gnus-article-browse-html-save-cid-content
2810 cid handle directory abs)) 2810 cid handle directory))
2811 (throw 'found file))) 2811 (throw 'found file)))
2812 ((equal (concat "<" cid ">") (mm-handle-id handle)) 2812 ((equal (concat "<" cid ">") (mm-handle-id handle))
2813 (setq file (or (mm-handle-filename handle) 2813 (setq file (or (mm-handle-filename handle)
@@ -2817,11 +2817,9 @@ the parent of DIRECTORY."
2817 mailcap-mime-extensions)))) 2817 mailcap-mime-extensions))))
2818 afile (expand-file-name file directory)) 2818 afile (expand-file-name file directory))
2819 (mm-save-part-to-file handle afile) 2819 (mm-save-part-to-file handle afile)
2820 (throw 'found (if abs 2820 (throw 'found (concat (file-name-nondirectory
2821 afile 2821 (directory-file-name directory))
2822 (concat (file-name-nondirectory 2822 "/" file)))))))))
2823 (directory-file-name directory))
2824 "/" file))))))))))
2825 2823
2826(defun gnus-article-browse-html-parts (list &optional header) 2824(defun gnus-article-browse-html-parts (list &optional header)
2827 "View all \"text/html\" parts from LIST. 2825 "View all \"text/html\" parts from LIST.
@@ -2857,13 +2855,32 @@ message header will be added to the bodies of the \"text/html\" parts."
2857 (insert content) 2855 (insert content)
2858 ;; resolve cid contents 2856 ;; resolve cid contents
2859 (let ((case-fold-search t) 2857 (let ((case-fold-search t)
2860 abs st cid-file) 2858 st base regexp cid-file)
2861 (goto-char (point-min)) 2859 (goto-char (point-min))
2862 (when (re-search-forward "<head[\t\n >]" nil t) 2860 (when (and (re-search-forward "<head[\t\n >]" nil t)
2863 (setq st (match-end 0) 2861 (progn
2864 abs (or 2862 (setq st (match-end 0))
2865 (not (re-search-forward "</head[\t\n >]" nil t)) 2863 (re-search-forward "</head[\t\n >]" nil t))
2866 (re-search-backward "<base[\t\n >]" st t)))) 2864 (re-search-backward "<base\
2865\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2866 (setq base (match-string 1))
2867 (replace-match "<!--\\&-->")
2868 (setq st (point))
2869 (dolist (tag '(("a" . "href") ("form" . "action")
2870 ("img" . "src")))
2871 (setq regexp (concat "<" (car tag)
2872 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2873 (cdr tag) "=\"\\([^\"]+\\)"))
2874 (while (re-search-forward regexp nil t)
2875 (insert (prog1
2876 (condition-case nil
2877 (save-match-data
2878 (url-expand-file-name (match-string 1)
2879 base))
2880 (error (match-string 1)))
2881 (delete-region (match-beginning 1)
2882 (match-end 1)))))
2883 (goto-char st)))
2867 (while (re-search-forward "\ 2884 (while (re-search-forward "\
2868<img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\"" 2885<img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2869 nil t) 2886 nil t)
@@ -2877,18 +2894,7 @@ message header will be added to the bodies of the \"text/html\" parts."
2877 (match-string 2) 2894 (match-string 2)
2878 (with-current-buffer gnus-article-buffer 2895 (with-current-buffer gnus-article-buffer
2879 gnus-article-mime-handles) 2896 gnus-article-mime-handles)
2880 cid-dir abs)) 2897 cid-dir))
2881 (when abs
2882 (setq cid-file
2883 (if (eq system-type 'cygwin)
2884 (concat "file:///"
2885 (substring
2886 (with-output-to-string
2887 (call-process "cygpath" nil
2888 standard-output
2889 nil "-m" cid-file))
2890 0 -1))
2891 (concat "file://" cid-file))))
2892 (replace-match cid-file nil nil nil 1)))) 2898 (replace-match cid-file nil nil nil 1))))
2893 (unless content (setq content (buffer-string)))) 2899 (unless content (setq content (buffer-string))))
2894 (when (or charset header (not file)) 2900 (when (or charset header (not file))