;; (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
;;;
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.
(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
(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)