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