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)))
44 (eq (aref str (- len 2)) ??)
45 (eq (aref str (1- len)) ?=))))
47 (defun ew-decode-eword (str &optional eword-filter1 eword-filter2)
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))
60 (setq tmp (closure-call cdec (funcall bdec encoded-text)))
61 (when eword-filter1 (setq tmp (closure-call eword-filter1 tmp)))
62 (setq tmp (ew-quote tmp))
63 (when eword-filter2 (setq tmp (closure-call eword-filter2 tmp)))
66 (ew-quote-eword charset encoding encoded-text)))
69 (defun ew-byte-decoder (encoding)
70 (cdr (assoc (upcase encoding) ew-byte-decoder-alist)))
72 (defun ew-byte-checker (encoding)
73 (cdr (assoc (upcase encoding) ew-byte-checker-alist)))
75 (defalias 'ew-b-decode 'base64-decode-string)
76 (defalias 'ew-q-decode 'q-encoding-decode-string)
78 (defun ew-char-decoder (charset)
79 (let ((sym (intern (downcase charset))))
80 (when (mime-charset-to-coding-system sym 'LF)
82 (lambda (str) (decode-mime-charset-string str sym 'LF))