eword-encoded-text-regexp
"\\)"
(regexp-quote "?=")))
+(defconst eword-after-encoded-word-regexp "\\([ \t]\\|$\\)")
+
+(defconst eword-encoded-text-in-phrase-regexp "[-A-Za-z0-9!*+/=_]+")
+(defconst eword-encoded-word-in-phrase-regexp
+ (concat (regexp-quote "=?")
+ "\\("
+ mime-charset-regexp
+ "\\)"
+ (regexp-quote "?")
+ "\\(B\\|Q\\)"
+ (regexp-quote "?")
+ "\\("
+ eword-encoded-text-in-phrase-regexp
+ "\\)"
+ (regexp-quote "?=")))
+(defconst eword-after-encoded-word-in-phrase-regexp "\\([ \t(]\\|$\\)")
+
+(defconst eword-encoded-text-in-comment-regexp "[]!-'*->@-[^-~]+")
+(defconst eword-encoded-word-in-comment-regexp
+ (concat (regexp-quote "=?")
+ "\\("
+ mime-charset-regexp
+ "\\)"
+ (regexp-quote "?")
+ "\\(B\\|Q\\)"
+ (regexp-quote "?")
+ "\\("
+ eword-encoded-text-in-comment-regexp
+ "\\)"
+ (regexp-quote "?=")))
+(defconst eword-after-encoded-word-in-comment-regexp "\\([ \t()\\\\]\\|$\\)")
+
+(defconst eword-encoded-text-in-quoted-string-regexp "[]!#->@-[^-~]+")
+(defconst eword-encoded-word-in-quoted-string-regexp
+ (concat (regexp-quote "=?")
+ "\\("
+ mime-charset-regexp
+ "\\)"
+ (regexp-quote "?")
+ "\\(B\\|Q\\)"
+ (regexp-quote "?")
+ "\\("
+ eword-encoded-text-in-quoted-string-regexp
+ "\\)"
+ (regexp-quote "?=")))
+(defconst eword-after-encoded-word-in-quoted-string-regexp "\\([ \t\"\\\\]\\|$\\)")
;;; @@ Base64
;;;
(defvar eword-decode-sticked-encoded-word nil
- "*If non-nil, decode encoded-words sticked on atoms, other encoded-words, etc.
+ "*If non-nil, decode encoded-words sticked on atoms,
+other encoded-words, etc.
however this behaviour violates RFC2047.")
(defvar eword-decode-quoted-encoded-word nil
- "*If non-nil, decode encoded-words in quoted-string
+ "*If non-nil, decode encoded-words in quoted-string
however this behaviour violates RFC2047.")
-(defun eword-decode-first-encoded-words (string after-regexp &optional must-unfold)
+(defun eword-decode-first-encoded-words (string
+ eword-regexp
+ after-regexp
+ &optional must-unfold)
+ "Decode MIME encoded-words in beginning of STRING.
+
+EWORD-REGEXP is the regexp that matches a encoded-word.
+Usual value is eword-encoded-word-regexp,
+eword-encoded-text-in-phrase-regexp,
+eword-encoded-word-in-comment-regexp or
+eword-encoded-word-in-quoted-string-regexp.
+
+AFTER-REGEXP is the regexp that matches a after encoded-word.
+Usual value is eword-after-encoded-word-regexp,
+eword-after-encoded-text-in-phrase-regexp,
+eword-after-encoded-word-in-comment-regexp or
+eword-after-encoded-word-in-quoted-string-regexp.
+
+If beginning of STRING matches EWORD-REGEXP and AFTER-REGEXP,
+returns a cons cell of decoded string(sequence of characters) and
+the rest(sequence of octets).
+
+If beginning of STRING does not matches EWORD-REGEXP and AFTER-REGEXP,
+returns nil.
+
+If an encoded-word is broken or your emacs implementation can not
+decode the charset included in it, it is returned in decoded part
+as encoded-word form.
+
+If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
+if there are in decoded encoded-words (generated by bad manner MUA
+such as a version of Net$cape)."
(if eword-decode-sticked-encoded-word (setq after-regexp ""))
- (let ((between-ewords-regexp (if eword-decode-sticked-encoded-word "\\(\n?[ \t]\\)*" "\\(\n?[ \t]\\)+"))
+ (let ((between-ewords-regexp
+ (if eword-decode-sticked-encoded-word
+ "\\(\n?[ \t]\\)*"
+ "\\(\n?[ \t]\\)+"))
(src string) ; sequence of octets.
(dst "")) ; sequence of characters.
- (if (string-match (concat "\\`\\(" eword-encoded-word-regexp "\\)" after-regexp) src)
+ (if (string-match
+ (concat "\\`\\(" eword-regexp "\\)" after-regexp) src)
(let* (p
(q (match-end 1))
(ew (substring src 0 q))
(while
(and
(string-match
- (concat "\\`\\(" between-ewords-regexp "\\)\\(" eword-encoded-word-regexp "\\)" after-regexp)
+ (concat "\\`\\(" between-ewords-regexp "\\)"
+ "\\(" eword-regexp "\\)"
+ after-regexp)
src)
(progn
(setq p (match-end 1)
(decoded (and
flag-ew
(eword-decode-first-encoded-words src
- "\\([ \t()\\\\]\\|$\\)" must-unfold))))
+ eword-encoded-word-in-comment-regexp
+ eword-after-encoded-word-in-comment-regexp
+ must-unfold))))
(if (and (not (string= buf ""))
(or decoded (eq ch ?\() (eq ch ?\))))
- (setq dst (concat dst (std11-wrap-as-quoted-pairs (decode-mime-charset-string buf default-mime-charset) '(?\( ?\))))
+ (setq dst (concat dst
+ (std11-wrap-as-quoted-pairs
+ (decode-mime-charset-string buf
+ default-mime-charset)
+ '(?\( ?\))))
buf ""))
(cond
(decoded
- (setq dst (concat dst (std11-wrap-as-quoted-pairs (car decoded) '(?( ?))))
+ (setq dst (concat dst
+ (std11-wrap-as-quoted-pairs
+ (car decoded)
+ '(?( ?))))
src (cdr decoded)))
((or (eq ch ?\() (eq ch ?\)))
(setq dst (concat dst (list ch))
flag-ew eword-decode-sticked-encoded-word))
(t (error "something wrong")))))
(if (not (string= buf ""))
- (setq dst (concat dst (std11-wrap-as-quoted-pairs (decode-mime-charset-string buf default-mime-charset) '(?\( ?\))))))
+ (setq dst (concat dst
+ (std11-wrap-as-quoted-pairs
+ (decode-mime-charset-string buf
+ default-mime-charset)
+ '(?\( ?\))))))
dst))
(defun eword-decode-quoted-string (string &optional must-unfold)
eword-decode-quoted-encoded-word
flag-ew
(eword-decode-first-encoded-words src
- "\\([ \t\"\\\\]\\|$\\)" must-unfold))))
+ eword-encoded-word-in-quoted-string-regexp
+ eword-after-encoded-word-in-quoted-string-regexp
+ must-unfold))))
(if (and (not (string= buf ""))
(or decoded (eq ch ?\")))
(setq dst (concat dst
(std11-wrap-as-quoted-pairs
- (decode-mime-charset-string buf default-mime-charset)
+ (decode-mime-charset-string buf
+ default-mime-charset)
'(?\")))
buf ""))
(cond
(decoded
(setq dst (concat dst
- (std11-wrap-as-quoted-pairs (car decoded) '(?\")))
+ (std11-wrap-as-quoted-pairs
+ (car decoded)
+ '(?\")))
src (cdr decoded)))
((or (eq ch ?\"))
(setq dst (concat dst (list ch))
(if (not (string= buf ""))
(setq dst (concat dst
(std11-wrap-as-quoted-pairs
- (decode-mime-charset-string buf default-mime-charset)
+ (decode-mime-charset-string buf
+ default-mime-charset)
'(?\")))))
dst))
(flag-ew t))
(while (< 0 (length src))
(let ((ch (aref src 0))
- (decoded (and flag-ew (eword-decode-first-encoded-words src "\\([ \t]\\|$\\)" must-unfold))))
+ (decoded (and flag-ew (eword-decode-first-encoded-words src
+ eword-encoded-word-regexp
+ eword-after-encoded-word-regexp
+ must-unfold))))
(if (and (not (string= buf ""))
decoded)
- (setq dst (concat dst (decode-mime-charset-string buf default-mime-charset))
+ (setq dst (concat dst
+ (decode-mime-charset-string buf
+ default-mime-charset))
buf ""))
(cond
(decoded
flag-ew eword-decode-sticked-encoded-word))
(t (error "something wrong")))))
(if (not (string= buf ""))
- (setq dst (concat dst (decode-mime-charset-string buf default-mime-charset))))
+ (setq dst (concat dst
+ (decode-mime-charset-string buf
+ default-mime-charset))))
dst))
(defun eword-decode-string (string &optional must-unfold)
If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
if there are in decoded encoded-words (generated by bad manner MUA
such as a version of Net$cape)."
- (eword-decode-unstructured-string (std11-unfold-string string) must-unfold))
+ (eword-decode-unstructured-string
+ (std11-unfold-string string)
+ must-unfold))
;;; @ for region
(if unfolding
(eword-decode-unfold)
)
- (let ((str (eword-decode-unstructured-string (buffer-substring (point-min) (point-max)) must-unfold)))
+ (let ((str (eword-decode-unstructured-string
+ (buffer-substring (point-min) (point-max))
+ must-unfold)))
(delete-region (point-min) (point-max))
(insert str)))))
(std11-analyze-special string))
(defun eword-analyze-encoded-word (string &optional must-unfold)
- (let ((decoded (eword-decode-first-encoded-words string "\\([ \t(]\\|$\\)" must-unfold)))
+ (let ((decoded (eword-decode-first-encoded-words string
+ eword-encoded-word-in-phrase-regexp
+ eword-after-encoded-word-in-phrase-regexp
+ must-unfold)))
(if decoded
(cons (cons 'atom (car decoded)) (cdr decoded)))))
characters encoded as encoded-words or invalid \"raw\" format.
\"Raw\" non us-ascii characters are regarded as variable
`default-mime-charset'."
- (let ((key (copy-sequence string))
- ret)
- (set-text-properties 0 (length key) nil key)
+ (let* ((str (copy-sequence string))
+ (key (cons str (cons default-mime-charset must-unfold)))
+ ret)
+ (set-text-properties 0 (length str) nil str)
(if (setq ret (assoc key eword-lexical-analyze-cache))
(cdr ret)
- (setq ret (eword-lexical-analyze-internal key must-unfold))
+ (setq ret (eword-lexical-analyze-internal str must-unfold))
(setq eword-lexical-analyze-cache
(cons (cons key ret)
(last eword-lexical-analyze-cache