* ew-bq.el (ew-ccl-decode-quoted-printable): New CCL program.
[elisp/flim.git] / ew-quote.el
index 66806b2..583d060 100644 (file)
@@ -1,5 +1,6 @@
 ;;; quoted encoded word library
 
+(require 'ew-var)
 (require 'ew-util)
 (require 'ew-line)
 (provide 'ew-quote)
 ;; B : token.
 ;; C : encoded-text.
 
-(defconst ew-quoting-char ?+)
-(defconst ew-quoting-char-singleton (list ew-quoting-char))
+(eval-and-compile
+  (defconst ew-quoting-char ?+))
 (defconst ew-quoting-chars-regexp
-  (concat (regexp-quote (char-to-string ew-quoting-char)) "*"))
-
-(defconst ew-token-regexp "[-!#-'*+0-9A-Z^-~]+")
-(defconst ew-encoded-text-regexp "[!->@-~]+")
-(defconst ew-encoded-word-regexp
-  (concat (regexp-quote "=?")
-          "\\(" ew-token-regexp "\\)"
-          (regexp-quote "?")
-          "\\(" ew-token-regexp "\\)"
-          (regexp-quote "?")
-          "\\(" ew-encoded-text-regexp "\\)"
-          (regexp-quote "?=")))
+  (eval-when-compile
+    (concat (regexp-quote (char-to-string ew-quoting-char)) "*")))
 
 (defconst ew-type2-regexp
-  (concat (regexp-quote "=?")
-          "\\(" ew-token-regexp "\\)"
-          (regexp-quote "?")
-          "\\(" ew-token-regexp "\\)"
-          (regexp-quote "?")
-          "\\(" ew-encoded-text-regexp "\\)"
-          (regexp-quote "?")
-         "\\'"))
+  (eval-when-compile
+    (require 'ew-var)
+    (concat (regexp-quote "=?")
+            "\\(" ew-token-regexp "\\)"
+            (regexp-quote "?")
+            "\\(" ew-token-regexp "\\)"
+            (regexp-quote "?")
+            "\\(" ew-encoded-text-regexp "\\)"
+            (regexp-quote "?")
+            "\\'")))
 
 ;;;
 
    "?="))
 
 (defun ew-encode-crlf (str)
-  (let ((sstart 0)
-       (mstart 0)
-       (end (length str)) result ms me)
-    (while (string-match "\\(\r\n\\)+" str mstart)
-      (setq ms (match-beginning 0)
-           me (match-end 0))
-      (setq mstart me)
-      (when (and (< me end)
-                (member (aref str me) '(?\t ?\ )))
-       (setq me (- me 2)))
-      (when (< ms me)
+  (if ew-remove-bare-crlf
+      (ew-crlf-line-convert str nil nil (lambda (nl) ""))
+    (let ((sstart 0)
+         (mstart 0)
+         (end (length str)) result ms me)
+      (while (string-match "\\(\r\n\\)+" str mstart)
+       (setq ms (match-beginning 0)
+             me (match-end 0))
+       (setq mstart me)
+       (when (and (< me end)
+                  (member (aref str me) '(?\t ?\ )))
+         (setq me (- me 2)))
+       (when (< ms me)
+         (setq result (ew-rcons* result
+                                 (substring str sstart ms)
+                                 "=?+US-ASCII?Q?")
+               sstart me)
+         (while (< ms me)
+           (setq result (ew-rcons* result "=0D=0A")
+                 ms (+ ms 2)))
+         (setq result (ew-rcons* result "?="))))
+      (when (< sstart end)
        (setq result (ew-rcons* result
-                               (substring str sstart ms)
-                               "=?+US-ASCII?Q?")
-             sstart me)
-       (while (< ms me)
-         (setq result (ew-rcons* result "=0D=0A")
-               ms (+ ms 2)))
-       (setq result (ew-rcons* result "?="))))
-    (when (< sstart end)
-      (setq result (ew-rcons* result
-                             (substring str sstart))))
-    (apply 'concat (nreverse result))))
-    
+                               (substring str sstart))))
+      (apply 'concat (nreverse result)))))
 
 '(
 (ew-quote-concat "aaa=?A?B?C?=ccc") ;"aaa=?A?B?C?=ccc"
 (ew-quote-concat "a=?+A?B?C?=?+D?E?F?" '("=?+US-ASCII?Q?z?=")) ;"a=?+++A?B?C?=?+D?E?F?=?+US-ASCII?Q?z?="
 (ew-quote-concat "a=?+A?B?C?=?+D?E?F?=?+G?H?I?" '("=?+US-ASCII?Q?z?=")) ;"a=?+++A?B?C?=?+D?E?F?=?+++++G?H?I?==?+US-ASCII?Q?z?="
 (ew-quote-concat '("a=?++A?B?C?==?+++A?B?C?=c")) ;"a=?A?B?C?=?+A?B?C?=c"
-)
\ No newline at end of file
+)