Fix QP double decode bug.
authorShengHuo ZHU <zsh@cs.rochester.edu>
Wed, 26 Jan 2000 17:07:17 +0000 (17:07 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Wed, 26 Jan 2000 17:07:17 +0000 (17:07 +0000)
lisp/ChangeLog
lisp/gnus-art.el
lisp/qp.el

index f5751bc..9927275 100644 (file)
@@ -1,3 +1,10 @@
+2000-01-26 12:01:18  Shenghuo ZHU  <zsh@cs.rochester.edu>
+
+       * qp.el (quoted-printable-decode-region): Add charset parameter.
+       (quoted-printable-decode-string): Ditto.
+       
+       * gnus-art.el (article-de-quoted-unreadable): Use it.
+
 2000-01-21  Simon Josefsson  <jas@pdc.kth.se>
 
        * nnimap.el (nnimap-split-predicate): New variable.
index e709382..765ee41 100644 (file)
@@ -1478,11 +1478,7 @@ or not."
       (when (or force
                (and type (string-match "quoted-printable" (downcase type))))
        (article-goto-body)
-       (save-restriction
-         (narrow-to-region (point) (point-max))
-         (quoted-printable-decode-region (point-min) (point-max))
-         (when charset
-           (mm-decode-body charset)))))))
+       (quoted-printable-decode-region (point) (point-max) charset)))))
 
 (eval-when-compile
   (require 'rfc1843))
index 8643104..fc909e4 100644 (file)
 
 ;;; Code:
 
+(require 'mm-util)
+
 (defvar quoted-printable-encoding-characters
   (mapcar 'identity "0123456789ABCDEFabcdef"))
 
-(defun quoted-printable-decode-region (from to)
-  "Decode quoted-printable in the region between FROM and TO."
+(defun quoted-printable-decode-region (from to &optional charset)
+  "Decode quoted-printable in the region between FROM and TO.
+If CHARSET is non-nil, decode the region with charset."
   (interactive "r")
   (save-excursion
-    (goto-char from)
-    (while (search-forward "=" to t)
-      (cond
-       ;; End of the line.
-       ((eq (char-after) ?\n)
-       (delete-char -1)
-       (delete-char 1))
-       ;; Encoded character.
-       ((and
-        (memq (char-after) quoted-printable-encoding-characters)
-        (memq (char-after (1+ (point)))
-              quoted-printable-encoding-characters))
-       (subst-char-in-region
-        (1- (point)) (point) ?=
-        (string-to-number
-         (buffer-substring (point) (+ 2 (point)))
-         16))
-       (delete-char 2))
-       ;; Quoted equal sign.
-       ((eq (char-after) ?=)
-       (delete-char 1))
-       ;; End of buffer.
-       ((eobp)
-       (delete-char -1))
-       ;; Invalid.
-       (t
-       (message "Malformed MIME quoted-printable message"))))))
-
-(defun quoted-printable-decode-string (string)
-  "Decode the quoted-printable-encoded STRING and return the results."
+    (save-restriction
+      (let (start)
+       (narrow-to-region from to)
+       (goto-char from)
+       (while (not (eobp))
+         (cond 
+          ((eq (char-after) ?=)
+           (delete-char 1)
+           (unless start
+             (setq start (point)))
+           (cond
+            ;; End of the line.
+            ((eq (char-after) ?\n)
+             (delete-char 1))
+            ;; Encoded character.
+            ((and
+              (memq (char-after) quoted-printable-encoding-characters)
+              (memq (char-after (1+ (point)))
+                    quoted-printable-encoding-characters))
+             (insert
+              (string-to-number
+               (buffer-substring (point) (+ 2 (point)))
+               16))
+             (delete-char 2))
+            ;; Quoted equal sign.
+            ((eq (char-after) ?=)
+             (forward-char 1))
+            ;; End of buffer.
+            ((eobp))
+            ;; Invalid.
+            (t
+             (message "Malformed MIME quoted-printable message"))))
+          ((and charset start (not (eq (mm-charset-after) 'ascii)))
+           (mm-decode-coding-region start (point) charset)
+           (setq start nil)
+           (forward-char 1))
+          (t
+           (forward-char 1))))
+       (if (and charset start)
+           (mm-decode-coding-region start (point) charset))))))
+
+(defun quoted-printable-decode-string (string &optional charset)
+  "Decode the quoted-printable-encoded STRING and return the results.
+If CHARSET is non-nil, decode the region with charset."
   (with-temp-buffer
     (insert string)
-    (quoted-printable-decode-region (point-min) (point-max))
+    (quoted-printable-decode-region (point-min) (point-max) charset)
     (buffer-string)))
 
 (defun quoted-printable-encode-region (from to &optional fold class)