(eword-encoded-word-regexp): Match for language.
authorshuhei <shuhei>
Sat, 28 Apr 2001 22:55:27 +0000 (22:55 +0000)
committershuhei <shuhei>
Sat, 28 Apr 2001 22:55:27 +0000 (22:55 +0000)
(eword-decode-region): Refer the 7th parens, not 6th.
(eword-decode-encoded-word): Extract language information.
(eword-decode-encoded-text): New optional argument `language'.

eword-decode.el

index e4143e6..1c5ce86 100644 (file)
     (eval-when-compile
       (concat (regexp-quote "=?")
              "\\("
-             mime-charset-regexp
+             mime-charset-regexp       ; 1
              "\\)"
+             "\\("
+             (regexp-quote "*")
+             mime-language-regexp      ; 2
+             "\\)?"
              (regexp-quote "?")
-             "\\([BbQq]\\)"
+             "\\("
+             mime-encoding-regexp      ; 3
+             "\\)"
              (regexp-quote "?")
              "\\("
-             eword-encoded-text-regexp
+             eword-encoded-text-regexp ; 4
              "\\)"
              (regexp-quote "?="))))
   )
@@ -224,7 +230,7 @@ such as a version of Net$cape)."
                                         "\\(\n?[ \t]\\)+"
                                         "\\(" eword-encoded-word-regexp "\\)")
                                 nil t)
-       (replace-match "\\1\\6")
+       (replace-match "\\1\\7")
         (goto-char (point-min))
        )
       (while (re-search-forward eword-encoded-word-regexp nil t)
@@ -532,54 +538,56 @@ if there are in decoded encoded-word (generated by bad manner MUA such
 as a version of Net$cape)."
   (or (if (string-match eword-encoded-word-regexp word)
          (let ((charset
-                (substring word (match-beginning 1) (match-end 1))
-                )
+                (substring word (match-beginning 1)(match-end 1)))
+               (language
+                (when (match-beginning 2)
+                  (intern
+                   (downcase
+                    (substring word (1+ (match-beginning 2))(match-end 2))))))
                (encoding
                 (upcase
-                 (substring word (match-beginning 2) (match-end 2))
-                 ))
+                 (substring word (match-beginning 3)(match-end 3))))
                (text
-                (substring word (match-beginning 3) (match-end 3))
-                ))
+                (substring word (match-beginning 4)(match-end 4))))
             (condition-case err
-                (eword-decode-encoded-text charset encoding text must-unfold)
+                (eword-decode-encoded-text
+                charset language encoding text must-unfold)
               (error
-              (funcall eword-decode-encoded-word-error-handler word err)
-               ))
-            ))
+              (funcall eword-decode-encoded-word-error-handler word err)))))
       word))
 
 
 ;;; @ encoded-text decoder
 ;;;
 
-(defun eword-decode-encoded-text (charset encoding string
+(defun eword-decode-encoded-text (charset language encoding string
                                          &optional must-unfold)
   "Decode STRING as an encoded-text.
 
 If your emacs implementation can not decode CHARSET, it returns nil.
 
+If LANGUAGE is non-nil, it is put to `mime-language' text-property.
 If ENCODING is not \"B\" or \"Q\", it occurs error.
 So you should write error-handling code if you don't want break by errors.
 
 If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
 if there are in decoded encoded-text (generated by bad manner MUA such
 as a version of Net$cape)."
-  (let ((cs (mime-charset-to-coding-system charset)))
-    (if cs
-       (let ((dest (encoded-text-decode-string string encoding)))
-         (when dest
-           (setq dest (decode-mime-charset-string dest charset))
-           (if must-unfold
-               (mapconcat (function
-                           (lambda (chr)
-                             (cond ((eq chr ?\n) "")
-                                   ((eq chr ?\t) " ")
-                                   (t (char-to-string chr)))
-                             ))
-                          (std11-unfold-string dest)
-                          "")
-             dest))))))
+  (when (mime-charset-to-coding-system charset)
+    (let ((dest (encoded-text-decode-string string encoding)))
+      (when dest
+       (setq dest (decode-mime-charset-string dest charset))
+       (when must-unfold
+         (mapconcat
+          (function
+           (lambda (chr)
+             (cond ((eq chr ?\n) "")
+                   ((eq chr ?\t) " ")
+                   (t (char-to-string chr)))))
+          (std11-unfold-string dest) ""))
+       (when language
+         (put-text-property 0 (length dest) 'mime-language language dest))
+       dest))))
 
 
 ;;; @ lexical analyze