From: akr Date: Fri, 20 Mar 1998 01:04:27 +0000 (+0000) Subject: (eword-decode-string): Treat undecodable encoded-words. X-Git-Tag: akr-199811302358~9 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=593139a8c169abdb0a0b19568bb3b8d59c1e0bc5;p=elisp%2Fsemi.git (eword-decode-string): Treat undecodable encoded-words. --- diff --git a/ChangeLog b/ChangeLog index eac82f9..2d2d420 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1998-03-20 Tanaka Akira + + * eword-decode.el (eword-decode-string): Treat undecodable + encoded-words. + 1998-03-19 Tanaka Akira * eword-decode.el (eword-decode-region): Treat undecodable diff --git a/eword-decode.el b/eword-decode.el index 30cabd5..a7dd200 100644 --- a/eword-decode.el +++ b/eword-decode.el @@ -98,6 +98,30 @@ ;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp)) +;; @ encoded-word's neighbor +;; + +(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 \"\".") + +; (setq eword-decode-before-ewords-regexp "") +; (setq eword-decode-between-ewords-regexp "\\(\n?[ \t]\\)*") +; (setq eword-decode-after-ewords-regexp "") + ;;; @ for string ;;; @@ -112,53 +136,43 @@ decode the charset included in it, it is not decoded. 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)." - (setq string (std11-unfold-string string)) - (let ((dest "")(ew nil) - beg end) - (while (and (string-match eword-encoded-word-regexp string) - (setq beg (match-beginning 0) - end (match-end 0)) - ) - (if (> beg 0) - (if (not - (and (eq ew t) - (string-match "^[ \t]+$" (substring string 0 beg)) - )) - (setq dest (concat dest (substring string 0 beg))) - ) - ) - (setq dest - (concat dest - (eword-decode-encoded-word - (substring string beg end) must-unfold) - )) - (setq string (substring string end)) - (setq ew t) - ) - (concat dest string) - )) + (let ((src (std11-unfold-string string)) + (dst "") + b e ew dw) + (while + (string-match + (concat "\\(" eword-decode-before-ewords-regexp "\\)" + "\\(" eword-encoded-word-regexp "\\)" + "\\(" eword-decode-after-ewords-regexp "\\)") + src) + (setq b (match-beginning 2)) + (setq e (match-end 2)) + (setq ew (substring src b e)) + (setq dw (eword-decode-encoded-word ew must-unfold)) + (setq dst (concat dst (substring src 0 b) dw)) + (setq src (substring src e)) + (if (not (string= ew dw)) + (while + (and + (string-match + (concat "\\`" + "\\(" eword-decode-between-ewords-regexp "\\)" + "\\(" eword-encoded-word-regexp "\\)" + "\\(" eword-decode-after-ewords-regexp "\\)") + src) + (progn + (setq e (match-end 3)) + (setq ew (substring src (match-beginning 3) e)) + (setq dw (eword-decode-encoded-word ew must-unfold)) + (not (string= ew dw)))) + (setq dst (concat dst dw)) + (setq src (substring src e))))) + (concat dst src))) ;;; @ 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. @@ -177,13 +191,15 @@ such as a version of Net$cape)." (goto-char (point-min)) (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) + (progn + (narrow-to-region (point) (point-max)) + (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 ew (buffer-substring b e)) (setq dw (eword-decode-encoded-word ew must-unfold)) (if (not (string= ew dw)) (progn @@ -193,13 +209,13 @@ such as a version of Net$cape)." (while (and (looking-at - (concat eword-decode-between-ewords-regexp + (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 e (match-end 3)) + (setq ew (buffer-substring (match-beginning 3) e)) (setq dw (eword-decode-encoded-word ew must-unfold)) (not (string= ew dw)))) (goto-char e)