tm-ftp is merged to mime-play.el.
[elisp/semi.git] / eword-decode.el
index 69cc972..3fca9ed 100644 (file)
@@ -10,7 +10,7 @@
 ;;     Renamed: 1993/06/03 to tiny-mime.el
 ;;     Renamed: 1995/10/03 from tiny-mime.el (split off encoder)
 ;;     Renamed: 1997/02/22 from tm-ew-d.el
-;; Version: $Revision: 0.3 $
+;; Version: $Revision: 0.14 $
 ;; Keywords: encoded-word, MIME, multilingual, header, mail, news
 
 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
 
 ;;; Code:
 
-(require 'emu)
 (require 'std11)
 (require 'mel)
 (require 'mime-def)
-(require 'tl-str)
 
 
 ;;; @ version
 ;;;
 
 (defconst eword-decode-RCS-ID
-  "$Id: eword-decode.el,v 0.3 1997-02-24 02:26:02 tmorioka Exp $")
+  "$Id: eword-decode.el,v 0.14 1997-02-27 08:56:45 tmorioka Exp $")
 (defconst eword-decode-version (get-version-string eword-decode-RCS-ID))
 
 
          (regexp-quote "?=")))
 
 
+;;; @@ Base64
+;;;
+
+(defconst base64-token-regexp "[A-Za-z0-9+/]")
+(defconst base64-token-padding-regexp "[A-Za-z0-9+/=]")
+
+(defconst eword-B-encoded-text-regexp
+  (concat "\\(\\("
+         base64-token-regexp
+         base64-token-regexp
+         base64-token-regexp
+         base64-token-regexp
+         "\\)*"
+         base64-token-regexp
+         base64-token-regexp
+         base64-token-padding-regexp
+         base64-token-padding-regexp
+          "\\)"))
+
+;; (defconst eword-B-encoding-and-encoded-text-regexp
+;;   (concat "\\(B\\)\\?" eword-B-encoded-text-regexp))
+
+
+;;; @@ Quoted-Printable
+;;;
+
+(defconst quoted-printable-hex-chars "0123456789ABCDEF")
+(defconst quoted-printable-octet-regexp
+  (concat "=[" quoted-printable-hex-chars
+         "][" quoted-printable-hex-chars "]"))
+
+(defconst eword-Q-encoded-text-regexp
+  (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
+;; (defconst eword-Q-encoding-and-encoded-text-regexp
+;;   (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
+
+
 ;;; @ for string
 ;;;
 
@@ -132,14 +167,13 @@ such as a version of Net$cape)."
        (replace-match "\\1\\6")
         (goto-char (point-min))
        )
-      (let (charset encoding text)
-       (while (re-search-forward eword-encoded-word-regexp nil t)
-         (insert (eword-decode-encoded-word
-                  (prog1
-                      (buffer-substring (match-beginning 0) (match-end 0))
-                    (delete-region (match-beginning 0) (match-end 0))
-                    ) must-unfold))
-         ))
+      (while (re-search-forward eword-encoded-word-regexp nil t)
+       (insert (eword-decode-encoded-word
+                (prog1
+                    (buffer-substring (match-beginning 0) (match-end 0))
+                  (delete-region (match-beginning 0) (match-end 0))
+                  ) must-unfold))
+       )
       )))
 
 
@@ -177,6 +211,8 @@ If SEPARATOR is not nil, it is used as header separator."
 ;;; @ encoded-word decoder
 ;;;
 
+(defvar eword-warning-face nil "Face used for invalid encoded-word.")
+
 (defun eword-decode-encoded-word (word &optional must-unfold)
   "Decode WORD if it is an encoded-word.
 
@@ -200,11 +236,12 @@ as a version of Net$cape)."
             (condition-case err
                 (eword-decode-encoded-text charset encoding text must-unfold)
               (error
-               (and (tl:add-text-properties 0 (length word)
-                                            (and tm:warning-face
-                                                 (list 'face tm:warning-face))
-                                            word)
-                    word)))
+               (and
+               (add-text-properties 0 (length word)
+                                    (and eword-warning-face
+                                         (list 'face eword-warning-face))
+                                    word)
+               word)))
             ))
       word))