* elmo-mime.el (elmo-mime-header-max-column): Set default value as
authorhmurata <hmurata>
Thu, 17 Nov 2005 12:50:23 +0000 (12:50 +0000)
committerhmurata <hmurata>
Thu, 17 Nov 2005 12:50:23 +0000 (12:50 +0000)
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
elmo/elmo-mime.el
elmo/elmo-util.el

index 03749ea..81f586b 100644 (file)
@@ -1,3 +1,13 @@
+2005-11-17  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
+
+       * 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  <lapis-lazuli@pop06.odn.ne.jp>
 
        * elmo-net.el (elmo-net-folder-set-parameters): Rename argument
index d000a08..f11e0cf 100644 (file)
@@ -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
index 877fe51..ff7ba62 100644 (file)
@@ -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."