From: morioka Date: Fri, 9 Oct 1998 09:00:31 +0000 (+0000) Subject: (eword-max-size-to-decode): New user option. X-Git-Tag: flim-1_10_3~11 X-Git-Url: http://git.chise.org/gitweb/?p=elisp%2Fflim.git;a=commitdiff_plain;h=6efca58a6c44d0de2fde64b2c3e113993c8f61ce (eword-max-size-to-decode): New user option. (eword-decode-and-fold-structured-field): Do nothing if size of input is bigger than `eword-max-size-to-decode'. --- diff --git a/eword-decode.el b/eword-decode.el index ae8958b..3178737 100644 --- a/eword-decode.el +++ b/eword-decode.el @@ -39,6 +39,12 @@ "Encoded-word decoding" :group 'mime) +(defcustom eword-max-size-to-decode 1000 + "*Max size to decode header field." + :group 'eword-decode + :type '(choice (integer :tag "Limit (bytes)") + (const :tag "Don't limit" nil))) + ;;; @ MIME encoded-word definition ;;; @@ -454,34 +460,37 @@ If MAX-COLUMN is omitted, `fill-column' is used. 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)." - (or max-column - (setq max-column fill-column)) - (let ((c start-column) - (tokens (eword-lexical-analyze string must-unfold)) - (result "") - token) - (while (and (setq token (car tokens)) - (setq tokens (cdr tokens))) - (let* ((type (car token))) - (if (eq type 'spaces) - (let* ((next-token (car tokens)) - (next-str (eword-decode-token next-token)) - (next-len (string-width next-str)) - (next-c (+ c next-len 1))) - (if (< next-c max-column) - (setq result (concat result " " next-str) - c next-c) - (setq result (concat result "\n " next-str) - c (1+ next-len))) - (setq tokens (cdr tokens)) - ) - (let* ((str (eword-decode-token token))) - (setq result (concat result str) - c (+ c (string-width str))) - )))) - (if token - (concat result (eword-decode-token token)) - result))) + (if (and eword-max-size-to-decode + (> (length string) eword-max-size-to-decode)) + string + (or max-column + (setq max-column fill-column)) + (let ((c start-column) + (tokens (eword-lexical-analyze string must-unfold)) + (result "") + token) + (while (and (setq token (car tokens)) + (setq tokens (cdr tokens))) + (let* ((type (car token))) + (if (eq type 'spaces) + (let* ((next-token (car tokens)) + (next-str (eword-decode-token next-token)) + (next-len (string-width next-str)) + (next-c (+ c next-len 1))) + (if (< next-c max-column) + (setq result (concat result " " next-str) + c next-c) + (setq result (concat result "\n " next-str) + c (1+ next-len))) + (setq tokens (cdr tokens)) + ) + (let* ((str (eword-decode-token token))) + (setq result (concat result str) + c (+ c (string-width str))) + )))) + (if token + (concat result (eword-decode-token token)) + result)))) (defun eword-decode-and-unfold-structured-field (string) "Decode and unfold STRING as structured field body.