From: akr Date: Thu, 19 Mar 1998 17:39:45 +0000 (+0000) Subject: (eword-decode-region): Treat undecodable encoded-words. X-Git-Tag: akr-199811302358~10 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41abb1fc7b41f2b447b5b0720b4192ce5f6d51e6;p=elisp%2Fsemi.git (eword-decode-region): Treat undecodable encoded-words. (eword-decode-before-ewords-regexp): New variable. (eword-decode-between-ewords-regexp): New variable. (eword-decode-after-ewords-regexp): New variable. --- diff --git a/ChangeLog b/ChangeLog index 950deb1..eac82f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +1998-03-19 Tanaka Akira + + * eword-decode.el (eword-decode-region): Treat undecodable + encoded-words. + (eword-decode-before-ewords-regexp): New variable. + (eword-decode-between-ewords-regexp): New variable. + (eword-decode-after-ewords-regexp): New variable. + 1998-03-16 MORIOKA Tomohiko * NEWS: New file. diff --git a/eword-decode.el b/eword-decode.el index aa638db..30cabd5 100644 --- a/eword-decode.el +++ b/eword-decode.el @@ -142,6 +142,23 @@ such as a version of Net$cape)." ;;; @ for region ;;; +(defvar eword-decode-before-ewords-regexp "\\=\\|^\\|[ \t]" + "Regexp that matches before encoded words. +This value must not contain grouping construct. +Default value is \"\\\\\\==\\\\|^\\\\|[ \\t]\". +Another useful (but not RFC2047 compliant) value is \"\".") + +(defvar eword-decode-between-ewords-regexp "\\(\n?[ \t]\\)+" + "Regexp that matches between encoded words. +This value must contain exactly one grouping construct. +Default value is \"\\\\(\\n?[ \\t]\\\\)+\". +Another useful (but not RFC2047 compliant) value is \"\\\\(\\n?[ \\t]\\\\)*\".") + +(defvar eword-decode-after-ewords-regexp "[ \t]\\|$" + "Regexp that matches after encoded words. +Default value is \"[ \\t]\\\\|$\". +Another useful (but not RFC2047 compliant) value is \"\".") + (defun eword-decode-region (start end &optional unfolding must-unfold) "Decode MIME encoded-words in region between START and END. @@ -158,20 +175,36 @@ such as a version of Net$cape)." (eword-decode-unfold) ) (goto-char (point-min)) - (while (re-search-forward (concat "\\(" eword-encoded-word-regexp "\\)" - "\\(\n?[ \t]\\)+" - "\\(" eword-encoded-word-regexp "\\)") - nil t) - (replace-match "\\1\\6") - (goto-char (point-min)) - ) - (while (re-search-forward eword-encoded-word-regexp nil t) - (insert (eword-decode-encoded-word - (prog1 - (buffer-substring (match-beginning 0) (match-end 0)) - (delete-region (match-beginning 0) (match-end 0)) - ) must-unfold)) - ) + (let (b e ew dw) + (while + (re-search-forward + (concat "\\(" eword-decode-before-ewords-regexp "\\)" + "\\(" eword-encoded-word-regexp "\\)" + "\\(" eword-decode-after-ewords-regexp "\\)") nil t) + (setq b (match-beginning 2)) + (setq e (match-end 2)) + (setq ew (buffer-substring (match-beginning 2) (match-end 2))) + (setq dw (eword-decode-encoded-word ew must-unfold)) + (if (not (string= ew dw)) + (progn + (goto-char e) + (delete-region b e) + (insert dw) + (while + (and + (looking-at + (concat eword-decode-between-ewords-regexp + "\\(" eword-encoded-word-regexp "\\)" + "\\(" eword-decode-after-ewords-regexp "\\)")) + (progn + (setq b (match-beginning 0)) + (setq e (match-end 2)) + (setq ew (buffer-substring (match-beginning 2) e)) + (setq dw (eword-decode-encoded-word ew must-unfold)) + (not (string= ew dw)))) + (goto-char e) + (delete-region b e) + (insert dw)))))) )))