(charsets-to-mime-charset): New function; copied from emu.el.
[elisp/semi.git] / eword-encode.el
index bd2350a..222d409 100644 (file)
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
 
 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;; Version: $Revision: 0.6 $
+;; Version: $Revision: 0.12 $
 ;; Keywords: encoded-word, MIME, multilingual, header, mail, news
 
 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
 (require 'mel)
 (require 'std11)
 (require 'mime-def)
-(require 'tl-list)
+(require 'cl)
+
+(defsubst find-non-ascii-charset-string (string)
+  "Return a list of charsets in the STRING except ascii."
+  (delq 'ascii (find-charset-string string))
+  )
+
+(defsubst find-non-ascii-charset-region (start end)
+  "Return a list of charsets except ascii in the region between START and END."
+  (delq 'ascii (find-charset-string (buffer-substring start end)))
+  )
 
 
 ;;; @ version
 ;;;
 
 (defconst eword-encode-RCS-ID
-  "$Id: eword-encode.el,v 0.6 1997-02-22 17:11:31 morioka Exp $")
+  "$Id: eword-encode.el,v 0.12 1997-03-01 04:09:16 tmorioka Exp $")
 (defconst eword-encode-version (get-version-string eword-encode-RCS-ID))
 
 
@@ -63,7 +73,7 @@ If method is nil, this field will not be encoded.")
 
 (defvar eword-generate-X-Nsubject nil
   "*If it is not nil, X-Nsubject field is generated
-when Subject field is encoded by `eword-encode-message-header'.")
+when Subject field is encoded by `eword-encode-header'.")
 
 (defvar eword-charset-encoding-alist
   '((us-ascii          . nil)
@@ -116,14 +126,14 @@ when Subject field is encoded by `eword-encode-message-header'.")
 (defun tm-eword::parse-lc-word (str)
   (let* ((chr (sref str 0))
         (lc (tm-eword::char-type chr))
-        (i (char-length chr))
+        (i (char-bytes chr))
         (len (length str))
         )
     (while (and (< i len)
                (setq chr (sref str i))
                (eq lc (tm-eword::char-type chr))
                )
-      (setq i (+ i (char-length chr)))
+      (setq i (+ i (char-bytes chr)))
       )
     (cons (cons lc (substring str 0 i)) (substring str i))
     ))
@@ -308,7 +318,7 @@ when Subject field is encoded by `eword-encode-message-header'.")
                    (str "") nstr)
               (while (and (< p len)
                           (progn
-                            (setq np (+ p (char-length (sref string p))))
+                            (setq np (+ p (char-bytes (sref string p))))
                             (setq nstr (substring string 0 np))
                             (setq ret (tm-eword::encoded-word-length
                                        (cons nstr (cdr rword))
@@ -531,7 +541,10 @@ when Subject field is encoded by `eword-encode-message-header'.")
     (if (and str (string-match eword-encoded-word-regexp str))
        str)))
 
-(defun eword-encode-message-header (&optional code-conversion)
+(defun eword-encode-header (&optional code-conversion)
+  "Encode header fields to network representation, such as MIME encoded-word.
+
+It refer variable `eword-field-encoding-method-alist'."
   (interactive "*")
   (save-excursion
     (save-restriction
@@ -544,14 +557,14 @@ when Subject field is encoded by `eword-encode-message-header'.")
          (setq field-name (buffer-substring beg (1- (match-end 0))))
          (setq end (std11-field-end))
          (and (find-non-ascii-charset-region beg end)
-              (let ((ret (or (ASSOC (downcase field-name)
-                                    eword-field-encoding-method-alist
-                                    :test (function
-                                           (lambda (str1 str2)
-                                             (and (stringp str2)
-                                                  (string= str1
-                                                           (downcase str2))
-                                                  ))))
+              (let ((ret (or (let ((fname  (downcase field-name)))
+                               (assoc-if
+                                (function
+                                 (lambda (str)
+                                   (and (stringp str)
+                                        (string= fname (downcase str))
+                                        )))
+                                eword-field-encoding-method-alist))
                              (assq t eword-field-encoding-method-alist)
                              )))
                 (if ret
@@ -585,16 +598,14 @@ when Subject field is encoded by `eword-encode-message-header'.")
                           (setq str
                                 (encode-mime-charset-string
                                  str
-                                 (or (cdr (ASSOC
-                                           "x-nsubject"
-                                           eword-field-encoding-method-alist
-                                           :test
+                                 (or (cdr (assoc-if
                                            (function
-                                            (lambda (str1 str2)
-                                              (and (stringp str2)
-                                                   (string= str1
+                                            (lambda (str)
+                                              (and (stringp str)
+                                                   (string= "x-nsubject"
                                                             (downcase str2))
-                                                   )))))
+                                                   )))
+                                           eword-field-encoding-method-alist))
                                      'iso-2022-jp-2)))
                         )
                       (insert (concat "\nX-Nsubject: " str))