8 (defconst ew-anchored-encoded-word-regexp
9 (concat "\\`" ew-encoded-word-regexp "\\'"))
25 (defconst ew-q-regexp "\\`\\([^=?]\\|=[0-9A-Fa-f][0-9A-Fa-f]\\)*\\'")
27 (defconst ew-byte-decoder-alist
31 (defconst ew-byte-checker-alist
35 (defun ew-b-check (encoding encoded-text) (string-match ew-b-regexp encoded-text))
36 (defun ew-q-check (encoding encoded-text) (string-match ew-q-regexp encoded-text))
38 (defun ew-eword-p (str)
39 (let ((len (length str)))
42 (string= (substring str 0 2) "=?")
43 (string= (substring str (- len 2) len) "?="))))
45 (defun ew-decode-eword (str &optional eword-filter1 eword-filter2)
46 (if (string-match ew-anchored-encoded-word-regexp str)
47 (let ((charset (match-string 1 str))
48 (encoding (match-string 2 str))
49 (encoded-text (match-string 3 str))
53 (if (and (setq bdec (ew-byte-decoder encoding))
54 (setq cdec (ew-char-decoder charset)))
55 (if (or (null (setq bcheck (ew-byte-checker encoding)))
56 (funcall bcheck encoding encoded-text))
58 (setq tmp (closure-call cdec (funcall bdec encoded-text)))
59 (when eword-filter1 (setq tmp (closure-call eword-filter1 tmp)))
60 (setq tmp (ew-quote tmp))
61 (when eword-filter2 (setq tmp (closure-call eword-filter2 tmp)))
64 (ew-quote-eword charset encoding encoded-text)))
67 (defun ew-byte-decoder (encoding)
68 (cdr (assoc (upcase encoding) ew-byte-decoder-alist)))
70 (defun ew-byte-checker (encoding)
71 (cdr (assoc (upcase encoding) ew-byte-checker-alist)))
73 (defalias 'ew-b-decode 'base64-decode-string)
74 (defalias 'ew-q-decode 'q-encoding-decode-string)
76 (defconst ew-charset-aliases
77 '((us-ascii . iso-8859-1)
78 (iso-2022-jp-2 . iso-2022-7bit-ss2)))
79 (defun ew-char-decoder (charset)
81 (setq charset (downcase charset))
82 (let ((sym (intern charset))
84 (when (setq tmp (assq sym ew-charset-aliases))
86 (setq cs (intern (concat (symbol-name sym) "-unix")))
87 (when (coding-system-p cs)
89 (closure-make (lambda (str) (decode-coding-string str cs)) cs)))