This commit was generated by cvs2svn to compensate for changes in r434,
[elisp/tm.git] / tm-ew-d.el
index 8d6150f..0eabbea 100644 (file)
@@ -4,13 +4,13 @@
 ;;;
 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
 ;;; Copyright (C) 1992 ENAMI Tsugutomo
-;;; Copyright (C) 1993,1994,1995 MORIOKA Tomohiko
+;;; Copyright (C) 1993 .. 1996 MORIOKA Tomohiko
 ;;;
 ;;; Author: ENAMI Tsugutomo <enami@sys.ptg.sony.co.jp>
 ;;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;;; Created: 1993/6/3 (1995/10/3 obsolete tiny-mime.el)
-;;; Version: $Revision: 7.6 $
+;;; Version: $Revision: 7.18 $
 ;;; Keywords: mail, news, MIME, RFC 1522, multilingual, encoded-word
 ;;;
 ;;; This file is part of tm (Tools for MIME).
@@ -41,7 +41,7 @@
 ;;;
 
 (defconst tm-ew-d/RCS-ID
-  "$Id: tm-ew-d.el,v 7.6 1995/12/06 08:15:51 morioka Exp $")
+  "$Id: tm-ew-d.el,v 7.18 1996/08/07 15:50:44 morioka Exp $")
 (defconst mime/eword-decoder-version (get-version-string tm-ew-d/RCS-ID))
 
 
 ;;; @ for string
 ;;;
 
-(defun mime-eword/decode-string (str)
+(defun mime-eword/decode-string (str &optional unfolding)
   (setq str (rfc822/unfolding-string str))
   (let ((dest "")(ew nil)
        beg end)
-    (while (setq beg (string-match mime/encoded-word-regexp str))
+    (while (and (string-match mime/encoded-word-regexp str)
+               (setq beg (match-beginning 0)
+                     end (match-end 0))
+               )
       (if (> beg 0)
-         (if (not (and (eq ew t) (string= (substring str 0 beg) " ")))
-             (setq dest (concat dest (substring str 0 beg)
-                                ))
+         (if (not
+              (and (eq ew t)
+                   (string-match "^[ \t]+$" (substring str 0 beg))
+                   ))
+             (setq dest (concat dest (substring str 0 beg)))
            )
        )
-      (setq end (match-end 0))
-      (setq dest (concat dest
-                        (mime/decode-encoded-word (substring str beg end))
-                        ))
+      (setq dest
+           (concat dest
+                   (mime/decode-encoded-word
+                    (substring str beg end) unfolding)
+                   ))
       (setq str (substring str end))
       (setq ew t)
       )
@@ -90,7 +96,7 @@
 ;;; @ for region
 ;;;
 
-(defun mime-eword/decode-region (beg end &optional unfolding)
+(defun mime-eword/decode-region (beg end &optional unfolding must-unfold)
   (interactive "*r")
   (save-excursion
     (save-restriction
       (goto-char (point-min))
       (let (charset encoding text)
        (while (re-search-forward mime/encoded-word-regexp nil t)
-         (insert (mime/decode-encoded-word 
+         (insert (mime/decode-encoded-word
                   (prog1
                       (buffer-substring (match-beginning 0) (match-end 0))
                     (delete-region (match-beginning 0) (match-end 0))
-                    )
-                  ))
+                    ) must-unfold))
          ))
       )))
 
 ;;; @ encoded-word decoder
 ;;;
 
-(defun mime/decode-encoded-word (word)
+(defun mime/decode-encoded-word (word &optional unfolding)
   (or (if (string-match mime/encoded-word-regexp word)
          (let ((charset
-                (upcase
-                 (substring word (match-beginning 1) (match-end 1))
-                 ))
+                (substring word (match-beginning 1) (match-end 1))
+                )
                (encoding
                 (upcase
                  (substring word (match-beginning 2) (match-end 2))
                (text
                 (substring word (match-beginning 3) (match-end 3))
                 ))
-           (mime/decode-encoded-text charset encoding text)
+           (mime/decode-encoded-text charset encoding text unfolding)
            ))
       word))
 
 ;;; @ encoded-text decoder
 ;;;
 
-(defun mime/decode-encoded-text (charset encoding str)
+(defun mime/decode-encoded-text (charset encoding str &optional unfolding)
   (let ((dest
-        (cond ((string= "B" encoding)
+        (cond ((string-equal "B" encoding)
                (base64-decode-string str))
-              ((string= "Q" encoding)
+              ((string-equal "Q" encoding)
                (q-encoding-decode-string str))
               (t (message "unknown encoding %s" encoding)
                  nil))))
     (if dest
-       (mime/convert-string-to-emacs charset dest)
-      )))
+       (progn
+         (setq dest (decode-mime-charset-string dest charset))
+         (if unfolding
+             (rfc822/unfolding-string dest)
+           dest)
+         ))))
 
 
 ;;; @ end
 ;;;
 
 (provide 'tm-ew-d)
+
+;;; tm-ew-d.el ends here