]> code.delx.au - gnu-emacs/commitdiff
Better decoding of HTML payload in Rmail
authorEli Zaretskii <eliz@gnu.org>
Sat, 28 Feb 2015 12:03:34 +0000 (14:03 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 28 Feb 2015 12:03:34 +0000 (14:03 +0200)
 lisp/mail/rmailmm.el (rmail-mime-insert-html): Decode HTML payload
 when the charset is only given by the HTML <head>, and allow to
 specify the encoding with "C-x RET c".

lisp/ChangeLog
lisp/mail/rmailmm.el

index b9681d35cf0b00b4b471ce41750e81e0f914112d..1cfd08fc95d03f0c37868e66179bed6615cca68d 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-28  Eli Zaretskii  <eliz@gnu.org>
+
+       * mail/rmailmm.el (rmail-mime-insert-html): Decode HTML payload
+       when the charset is only given by the HTML <head>, and allow to
+       specify the encoding with "C-x RET c".
+
 2015-02-27  Mark Laws  <mdl@60hz.org>
 
        Support daemon mode on MS-Windows (bug#19688)
index 120d517f55ca63b2514b80304a28edb16a142288..00fc25dd440de5b5de41acb230c7e6f50d98b2ec 100644 (file)
@@ -661,6 +661,7 @@ HEADER is a header component of a MIME-entity object (see
        (transfer-encoding (rmail-mime-entity-transfer-encoding entity))
        (charset (cdr (assq 'charset (cdr (rmail-mime-entity-type entity)))))
        (buffer (current-buffer))
+       (case-fold-search t)
        coding-system)
     (if charset (setq coding-system (coding-system-from-name charset)))
     (or (and coding-system (coding-system-p coding-system))
@@ -674,6 +675,22 @@ HEADER is a header component of a MIME-entity object (see
             (ignore-errors (base64-decode-region (point-min) (point-max))))
            ((string= transfer-encoding "quoted-printable")
             (quoted-printable-decode-region (point-min) (point-max))))
+      ;; Some broken MUAs state the charset only in the HTML <head>,
+      ;; so if we don't have a non-trivial coding-system at this
+      ;; point, make one last attempt to find it there.
+      (if (eq coding-system 'undecided)
+         (save-excursion
+           (goto-char (point-min))
+           (when (re-search-forward
+                  "^<html><head><meta[^;]*; charset=\\([-a-zA-Z0-9]+\\)"
+                  nil t)
+             (setq coding-system (coding-system-from-name (match-string 1)))
+             (or (and coding-system (coding-system-p coding-system))
+                 (setq coding-system 'undecided)))
+           ;; Finally, let them manually force decoding if they know it.
+           (if (and (eq coding-system 'undecided)
+                    (not (null coding-system-for-read)))
+               (setq coding-system coding-system-for-read))))
       (decode-coding-region (point-min) (point) coding-system)
       (if (and
           (or (not rmail-mime-coding-system) (consp rmail-mime-coding-system))