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 (defsubst ew-eword-p (str)
39 (let ((len (length str)))
44 (eq (aref str (- len 2)) ??)
45 (eq (aref str (1- len)) ?=))))
47 (defun ew-decode-eword (str)
48 (if (string-match ew-anchored-encoded-word-regexp str)
49 (let ((charset (match-string 1 str))
50 (encoding (match-string 2 str))
51 (encoded-text (match-string 3 str))
55 (if (and (setq bdec (ew-byte-decoder encoding))
56 (setq cdec (ew-char-decoder charset)))
57 (if (or (null (setq bcheck (ew-byte-checker encoding)))
58 (funcall bcheck encoding encoded-text))
59 (ew-quote (closure-call cdec (funcall bdec encoded-text)))
61 (ew-quote-eword charset encoding encoded-text)))
64 (defun ew-byte-decoder (encoding)
65 (cdr (assoc (upcase encoding) ew-byte-decoder-alist)))
67 (defun ew-byte-checker (encoding)
68 (cdr (assoc (upcase encoding) ew-byte-checker-alist)))
70 (defalias 'ew-b-decode 'base64-decode-string)
71 (defalias 'ew-q-decode 'q-encoding-decode-string)
73 (defun ew-char-decoder (charset)
74 (let ((sym (intern (downcase charset))))
75 (when (mime-charset-to-coding-system sym 'LF)
77 (lambda (str) (decode-mime-charset-string str sym 'LF))