X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=ew-quote.el;h=583d06028c6bc9eeaa164d53d3c3d8b2cd2517a3;hb=4a15ad0838f7f2ab125b4f766b127aefc828580c;hp=66806b2b9a1412f1c686879ac69d65f623bafad3;hpb=f87bb7feacfe97e675fd65ef0b3da18a17c52930;p=elisp%2Fflim.git diff --git a/ew-quote.el b/ew-quote.el index 66806b2..583d060 100644 --- a/ew-quote.el +++ b/ew-quote.el @@ -1,5 +1,6 @@ ;;; quoted encoded word library +(require 'ew-var) (require 'ew-util) (require 'ew-line) (provide 'ew-quote) @@ -17,31 +18,23 @@ ;; 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 "?") + "\\'"))) ;;; @@ -161,30 +154,31 @@ "?=")) (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" @@ -196,4 +190,4 @@ (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 +)