]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix rendering non-ASCII text with links
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 26 Sep 2021 06:29:38 +0000 (08:29 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 26 Sep 2021 06:29:38 +0000 (08:29 +0200)
* lisp/gnus/mm-view.el (mm-text-html-renderer-alist): Add a new
form for links.
(mm-links-remove-leading-blank): Make obsolete.
(mm-inline-wash-with-file):
(mm-inline-render-with-file): Make obsolete -- they were awkwardly
defined and only used with links.
(mm-inline-render-with-links): New function.

lisp/gnus/mm-view.el

index 129295474f76394e8962c052768ad24ea039d4e3..56d05c8fa939fcfc6d72acf51c93577f2fd8db7d 100644 (file)
@@ -50,9 +50,7 @@
     (w3m . mm-inline-text-html-render-with-w3m)
     (w3m-standalone . mm-inline-text-html-render-with-w3m-standalone)
     (gnus-w3m . gnus-article-html)
-    (links mm-inline-render-with-file
-          mm-links-remove-leading-blank
-          "links" "-dump" file)
+    (links . mm-inline-render-with-links)
     (lynx mm-inline-render-with-stdin nil
          "lynx" "-dump" "-force_html" "-stdin" "-nolist")
     (html2text mm-inline-render-with-function html2text))
@@ -264,6 +262,7 @@ This is only used if `mm-inline-large-images' is set to
     (mm-inline-render-with-stdin handle nil "w3m" "-dump" "-T" "text/html")))
 
 (defun mm-links-remove-leading-blank ()
+  (declare (obsolete nil "28.1"))
   ;; Delete the annoying three spaces preceding each line of links
   ;; output.
   (goto-char (point-min))
@@ -271,6 +270,7 @@ This is only used if `mm-inline-large-images' is set to
     (delete-region (match-beginning 0) (match-end 0))))
 
 (defun mm-inline-wash-with-file (post-func cmd &rest args)
+  (declare (obsolete nil "28.1"))
   (with-suppressed-warnings ((lexical file))
     (dlet ((file (make-temp-file
                  (expand-file-name "mm" mm-tmp-directory))))
@@ -290,12 +290,41 @@ This is only used if `mm-inline-large-images' is set to
   (and post-func (funcall post-func)))
 
 (defun mm-inline-render-with-file (handle post-func cmd &rest args)
+  (declare (obsolete nil "28.1"))
   (let ((source (mm-get-part handle)))
     (mm-insert-inline
      handle
      (mm-with-unibyte-buffer
        (insert source)
-       (apply #'mm-inline-wash-with-file post-func cmd args)
+       (with-suppressed-warnings ((obsolete mm-inline-wash-with-file))
+         (apply #'mm-inline-wash-with-file post-func cmd args))
+       (buffer-string)))))
+
+(defun mm-inline-render-with-links (handle)
+  (let ((source (mm-get-part handle))
+        file charset)
+    (mm-insert-inline
+     handle
+     (with-temp-buffer
+       (setq charset (mail-content-type-get (mm-handle-type handle) 'charset))
+       (insert source)
+       (unwind-protect
+           (progn
+             (setq file (make-temp-file (expand-file-name
+                                         "mm" mm-tmp-directory)))
+             (let ((coding-system-for-write 'binary))
+               (write-region (point-min) (point-max) file nil 'silent))
+             (delete-region (point-min) (point-max))
+             (if charset
+                 (with-environment-variables (("LANG" (format "en-US.%s"
+                                                              charset)))
+                  (call-process "links" nil t nil "-dump" file))
+               (call-process "links" nil t nil "-dump" file))
+             (goto-char (point-min))
+             (while (re-search-forward "^   " nil t)
+               (delete-region (match-beginning 0) (match-end 0))))
+         (when (and file (file-exists-p file))
+           (delete-file file)))
        (buffer-string)))))
 
 (defun mm-inline-render-with-stdin (handle post-func cmd &rest args)