From b79244c7acafd82fd6af6acffedcdde7e794ae4c Mon Sep 17 00:00:00 2001 From: hmurata Date: Thu, 17 Nov 2005 12:50:23 +0000 Subject: [PATCH] * elmo-mime.el (elmo-mime-header-max-column): Set default value as symbol `fill-column'. (elmo-mime-insert-header-from-buffer): Rewrite; ignore errors in decode field value. * elmo-util.el (elmo-mime-string): Ignore errors in eword decode. (elmo-decoded-field-body): Ditto. --- elmo/ChangeLog | 10 +++++ elmo/elmo-mime.el | 111 ++++++++++++++++++++++++++--------------------------- elmo/elmo-util.el | 10 +++-- 3 files changed, 72 insertions(+), 59 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index 03749ea..81f586b 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,3 +1,13 @@ +2005-11-17 Hiroya Murata + + * elmo-mime.el (elmo-mime-header-max-column): Set default value as + symbol `fill-column'. + (elmo-mime-insert-header-from-buffer): Rewrite; ignore errors in + decode field value. + + * elmo-util.el (elmo-mime-string): Ignore errors in eword decode. + (elmo-decoded-field-body): Ditto. + 2005-11-09 Hiroya Murata * elmo-net.el (elmo-net-folder-set-parameters): Rename argument diff --git a/elmo/elmo-mime.el b/elmo/elmo-mime.el index d000a08..f11e0cf 100644 --- a/elmo/elmo-mime.el +++ b/elmo/elmo-mime.el @@ -104,11 +104,13 @@ use for keymap of representation buffer.") (defvar elmo-message-sorted-field-list nil) (defvar elmo-mime-display-header-analysis t) -(defcustom elmo-mime-header-max-column fill-column +(defcustom elmo-mime-header-max-column 'fill-column "*Header max column number. Default is `fill-colmn'. +If a symbol of variable is specified, use its value in message buffer. If a symbol of function is specified, the function is called and its return value is used." :type '(choice (integer :tag "Column Number") + (variable :tag "Variable") (function :tag "Function")) :group 'elmo) @@ -127,67 +129,64 @@ value is used." visible-fields sort-fields) (let ((the-buf (current-buffer)) - (mode-obj (mime-find-field-presentation-method 'wide)) - field-decoder - f-b p f-e field-name field field-body - vf-alist (sl sort-fields)) + (max-column (cond ((functionp elmo-mime-header-max-column) + (funcall elmo-mime-header-max-column)) + ((and (symbolp elmo-mime-header-max-column) + (boundp elmo-mime-header-max-column)) + (symbol-value elmo-mime-header-max-column)) + (t + elmo-mime-header-max-column))) + vf-alist) (save-excursion (set-buffer buffer) (save-restriction (narrow-to-region start end) (goto-char start) (while (re-search-forward std11-field-head-regexp nil t) - (setq f-b (match-beginning 0) - p (match-end 0) - field-name (buffer-substring f-b p) - f-e (std11-field-end)) - (when (mime-visible-field-p field-name - visible-fields invisible-fields) - (setq field (intern - (capitalize (buffer-substring f-b (1- p)))) - field-body (buffer-substring p f-e) - field-decoder - (if elmo-mime-display-header-analysis - (inline (mime-find-field-decoder-internal - field mode-obj)) - (inline (lambda (x y z) x)))) - (setq vf-alist (append (list - (cons field-name - (list field-body field-decoder))) - vf-alist)))) - (and vf-alist - (setq vf-alist - (sort vf-alist - (function (lambda (s d) - (let ((n 0) re - (sf (car s)) - (df (car d))) - (catch 'done - (while (setq re (nth n sl)) - (setq n (1+ n)) - (and (string-match re sf) - (throw 'done t)) - (and (string-match re df) - (throw 'done nil))) - t))))))) - (with-current-buffer the-buf - (while vf-alist - (let* ((vf (car vf-alist)) - (field-name (car vf)) - (field-body (car (cdr vf))) - (field-decoder (car (cdr (cdr vf))))) - (insert field-name) - (insert (if field-decoder - (funcall field-decoder field-body - (string-width field-name) - (if (functionp elmo-mime-header-max-column) - (funcall elmo-mime-header-max-column) - elmo-mime-header-max-column)) - ;; Don't decode - field-body)) - (insert "\n")) - (setq vf-alist (cdr vf-alist))) - (run-hooks 'mmelmo-header-inserted-hook)))))) + (let* ((field-start (match-beginning 0)) + (name-end (match-end 0)) + (field-name (buffer-substring field-start name-end))) + (when (mime-visible-field-p field-name + visible-fields invisible-fields) + (let* ((field (intern + (capitalize + (buffer-substring field-start (1- name-end))))) + (field-body (buffer-substring name-end (std11-field-end))) + (field-decoder + (and elmo-mime-display-header-analysis + (inline (mime-find-field-decoder field 'wide))))) + (setq vf-alist (cons (list field-name field-body field-decoder) + vf-alist))))))) + (and vf-alist + (setq vf-alist + (sort vf-alist + (lambda (s d) + (let ((sf (car s)) + (df (car d))) + (catch 'done + (dolist (re sort-fields) + (when (string-match re sf) + (throw 'done t)) + (when (string-match re df) + (throw 'done nil))) + t)))))) + (set-buffer the-buf) + (while vf-alist + (let* ((vf (car vf-alist)) + (field-name (nth 0 vf)) + (field-body (nth 1 vf)) + (field-decoder (nth 2 vf))) + (insert field-name) + (insert (or (and field-decoder + (ignore-errors + (funcall field-decoder field-body + (string-width field-name) + max-column))) + ;; Don't decode + field-body)) + (insert "\n")) + (setq vf-alist (cdr vf-alist))) + (run-hooks 'mmelmo-header-inserted-hook)))) (luna-define-generic elmo-mime-insert-sorted-header (entity &optional invisible-fields diff --git a/elmo/elmo-util.el b/elmo/elmo-util.el index 877fe51..ff7ba62 100644 --- a/elmo/elmo-util.el +++ b/elmo/elmo-util.el @@ -1003,7 +1003,9 @@ Emacs 19.28 or earlier does not have `unintern'." (and string (elmo-with-enable-multibyte (encode-mime-charset-string - (eword-decode-and-unfold-unstructured-field-body string) + (or (ignore-errors + (eword-decode-and-unfold-unstructured-field-body string)) + string) elmo-mime-charset)))) (defsubst elmo-collect-field (beg end downcase-field-name) @@ -1280,8 +1282,10 @@ SPEC is a list as followed (LABEL MAX-VALUE [FORMAT])." (defun elmo-decoded-field-body (field-name &optional mode) (let ((field-body (elmo-field-body field-name))) (and field-body - (elmo-with-enable-multibyte - (mime-decode-field-body field-body field-name mode))))) + (or (ignore-errors + (elmo-with-enable-multibyte + (mime-decode-field-body field-body field-name mode))) + field-body)))) (defun elmo-address-quote-specials (word) "Make quoted string of WORD if needed." -- 1.7.10.4