(require 'wl-vars)
(require 'wl-util)
(eval-when-compile
+ (require 'cl) ; cadaar, cddaar
(require 'elmo-msgdb)) ; for inline functions
(defvar wl-score-edit-header-char
(defconst wl-score-header-index
;; Name to function alist.
- '(("number" wl-score-integer elmo-msgdb-overview-entity-get-number) ;;0
- ("subject" wl-score-string 3 charset)
- ("from" wl-score-string 2 charset)
- ("date" wl-score-date elmo-msgdb-overview-entity-get-date) ;;4
- ("message-id" wl-score-string elmo-msgdb-overview-entity-get-id)
- ("references" wl-score-string 1)
- ("to" wl-score-string 5)
- ("cc" wl-score-string 6)
- ("chars" wl-score-integer elmo-msgdb-overview-entity-get-size) ;;7
- ("lines" wl-score-integer wl-score-overview-entity-get-lines)
- ("xref" wl-score-string wl-score-overview-entity-get-xref)
- ("extra" wl-score-extra wl-score-overview-entity-get-extra mime)
- ("followup" wl-score-followup 2 charset)
- ("thread" wl-score-thread 1)))
+ '(("number" wl-score-integer number)
+ ("subject" wl-score-string subject charset)
+ ("from" wl-score-string from charset)
+ ("date" wl-score-date date)
+ ("message-id" wl-score-string message-id)
+ ("references" wl-score-string references)
+ ("to" wl-score-string to)
+ ("cc" wl-score-string cc)
+ ("chars" wl-score-integer size)
+ ("lines" wl-score-integer lines)
+ ("xref" wl-score-string xref)
+ ("extra" wl-score-extra extra mime)
+ ("followup" wl-score-followup from charset)
+ ("thread" wl-score-thread references)))
(defvar wl-score-auto-make-followup-entry nil)
(defvar wl-score-debug nil)
(defun wl-score-overview-entity-get-lines (entity)
(let ((lines (elmo-message-entity-field entity 'lines)))
(and lines
- (string-to-int lines))))
+ (string-to-number lines))))
(defun wl-score-overview-entity-get-xref (entity)
(or (elmo-message-entity-field entity 'xref)
""))
-(defun wl-score-overview-entity-get-extra (entity header &optional decode)
- (let ((extra (elmo-msgdb-overview-entity-get-extra-field entity header)))
- (if (and extra decode)
- (eword-decode-string
- (decode-mime-charset-string extra elmo-mime-charset))
- (or extra ""))))
-
(defun wl-string> (s1 s2)
(not (or (string< s1 s2)
(string= s1 s2))))
-(defmacro wl-score-ov-entity-get-by-index (entity index)
- (` (aref (cdr (, entity)) (, index))))
-
-(defsubst wl-score-ov-entity-get (entity index &optional extra decode)
- (let ((str (cond ((integerp index)
- (wl-score-ov-entity-get-by-index entity index))
- (extra
- (funcall index entity extra decode))
- (t
- (funcall index entity)))))
- (if (and decode (not extra))
- (decode-mime-charset-string str elmo-mime-charset)
- str)))
-
-(defun wl-score-string-index< (a1 a2)
- (string-lessp (wl-score-ov-entity-get-by-index (car a1) wl-score-index)
- (wl-score-ov-entity-get-by-index (car a2) wl-score-index)))
+(defsubst wl-score-ov-entity-get (entity index &optional extra)
+ (elmo-message-entity-field entity (if extra (intern extra) index)
+ ;; FIXME
+ (if (or (eq index 'to) (eq index 'cc))
+ 'string
+ nil)))
-(defun wl-score-string-func< (a1 a2)
- (string-lessp (funcall wl-score-index (car a1))
- (funcall wl-score-index (car a2))))
+(defun wl-score-string< (a1 a2)
+ (string-lessp (wl-score-ov-entity-get (car a1) wl-score-index)
+ (wl-score-ov-entity-get (car a2) wl-score-index)))
(defun wl-score-string-sort (messages index)
- (let ((func (cond ((integerp index)
- 'wl-score-string-index<)
- (t
- 'wl-score-string-func<))))
- (sort messages func)))
+ (sort messages 'wl-score-string<))
(defsubst wl-score-get (symbol &optional alist)
"Get SYMBOL's definition in ALIST."
(defun wl-score-headers (scores &optional force-msgs not-add)
(let* ((elmo-mime-charset wl-summary-buffer-mime-charset)
(folder wl-summary-buffer-elmo-folder)
- (now (wl-day-number (current-time-string)))
+ (now (elmo-time-to-days (current-time)))
(expire (and wl-score-expiry-days
(- now wl-score-expiry-days)))
(wl-score-stop-add-entry not-add)
(message "Scoring...")
;; Create messages, an alist of the form `(ENTITY . SCORE)'.
- (elmo-folder-do-each-message-entity (entity folder)
- (setq num (elmo-message-entity-number entity))
+ (dolist (num (elmo-folder-list-messages folder 'visible 'in-db))
(when (and (not (assq num wl-summary-scored))
(or (memq num force-msgs)
- (member (elmo-message-mark folder num)
+ (member (wl-summary-message-mark folder num)
wl-summary-score-marks)))
(setq wl-scores-messages
- (cons (cons entity (or wl-summary-default-score 0))
+ (cons (cons (elmo-message-entity folder num)
+ (or wl-summary-default-score 0))
wl-scores-messages))))
(save-excursion
nil))
(defmacro wl-score-put-alike ()
- (` (elmo-set-hash-val (format "#%d" (wl-count-lines))
- alike
- wl-score-alike-hashtb)))
+ '(elmo-set-hash-val (format "#%d" (wl-count-lines))
+ alike
+ wl-score-alike-hashtb))
(defmacro wl-score-get-alike ()
- (` (elmo-get-hash-val (format "#%d" (wl-count-lines))
- wl-score-alike-hashtb)))
+ '(elmo-get-hash-val (format "#%d" (wl-count-lines))
+ wl-score-alike-hashtb))
(defun wl-score-insert-header (header messages &optional extra-header)
(let ((mime-decode (nth 3 (assoc header wl-score-header-index)))
(make-local-variable 'wl-score-alike-hashtb)
(setq wl-score-alike-hashtb (elmo-make-hash (* (length messages) 2)))
(when mime-decode
- (elmo-set-buffer-multibyte default-enable-multibyte-characters))
+ (set-buffer-multibyte default-enable-multibyte-characters))
(let (art last this alike)
(while (setq art (pop messages))
(setq this (wl-score-ov-entity-get (car art)
wl-score-index
extra-header))
- (and this (setq this (std11-unfold-string this)))
+ (when (stringp this)
+ (setq this (std11-unfold-string this)))
(if (equal last this)
;; O(N*H) cons-cells used here, where H is the number of
;; headers.
expire
(< expire
(setq day
- (wl-day-number
+ (elmo-time-to-days
(elmo-message-entity-field
(car art) 'date))))))
(when (setq new (wl-score-add-followups
(list (cons "references" news)))))
(defun wl-score-add-followups (header score scores alist &optional thread day)
- (let* ((id (car header))
+ (let* ((id (elmo-message-entity-field header 'message-id))
(scores (car scores))
entry dont)
(when id
(setq dont t)))
(unless dont
(let ((entry (list id score
- (or day (wl-day-number (current-time-string))) 's)))
+ (or day (elmo-time-to-days (current-time))) 's)))
(unless (or thread wl-score-stop-add-entry)
(wl-score-update-score-entry "references" entry alist))
(wl-score-set 'touched '(t) alist)
"Automatically mark messages with score below SCORE as read."
(interactive
(list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
- (string-to-int (read-string "Mark below: ")))))
+ (string-to-number (read-string "Mark below: ")))))
(setq score (or score wl-summary-default-score 0))
(wl-score-set 'mark (list score))
(wl-score-set 'touched '(t))
"Automatically expunge messages with score below SCORE."
(interactive
(list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
- (string-to-int (read-string "Expunge below: ")))))
+ (string-to-number (read-string "Expunge below: ")))))
(setq score (or score wl-summary-default-score 0))
(wl-score-set 'expunge (list score))
(wl-score-set 'touched '(t)))
;; transform from string to int.
(when (eq (nth 1 (assoc (car entry) wl-score-header-index))
'wl-score-integer)
- (setq match (string-to-int match)))
+ (setq match (string-to-number match)))
;; set score
(if score
(setq lscore rscore)
(wl-summary-score-effect (car entry) list (eq (nth 2 list) 'now)))))
(defun wl-score-get-latest-msgs ()
- (let* ((now (wl-day-number (current-time-string)))
+ (let* ((now (elmo-time-to-days (current-time)))
(expire (and wl-score-expiry-days
(- now wl-score-expiry-days)))
(rnumbers (reverse wl-summary-buffer-number-list))
nil t)
(catch 'break
(while rnumbers
- (if (< (wl-day-number
- (elmo-message-entity-field
- (elmo-message-entity wl-summary-buffer-elmo-folder
- (car rnumbers))
- 'date))
+ (if (< (elmo-time-to-days
+ (elmo-message-entity-field wl-summary-buffer-elmo-folder
+ (car rnumbers)
+ 'date))
expire)
(throw 'break t))
(wl-push (car rnumbers) msgs)
(wl-score-ov-entity-get
(elmo-message-entity wl-summary-buffer-elmo-folder
(wl-summary-message-number))
- index extra decode))))
+ index extra))))
(defun wl-score-kill-help-buffer ()
(when (get-buffer "*Score Help*")
(setq wl-score-help-winconf (current-window-configuration))
(let ((cur-win (selected-window))
mes-win)
- (save-excursion
- (set-buffer (get-buffer-create "*Score Help*"))
+ (with-current-buffer (get-buffer-create "*Score Help*")
(buffer-disable-undo (current-buffer))
(delete-windows-on (current-buffer))
(erase-buffer)
;; read the score.
(unless (or score increase)
- (setq score (string-to-int (read-string "Set score: ")))))
+ (setq score (string-to-number (read-string "Set score: ")))))
(message "")
(wl-score-kill-help-buffer))
(perm (cond ((eq perm 'perm)
nil)
((eq perm 'temp)
- (wl-day-number (current-time-string)))
+ (elmo-time-to-days (current-time)))
((eq perm 'now)
perm)))
(new (list match score perm type extra)))
(wl-score-headers scores force-msgs not-add))))
(defun wl-summary-score-update-all-lines (&optional update)
- (let* ((alist wl-summary-scored)
- (count (length alist))
- (i 0)
- (update-unread nil)
- wl-summary-unread-message-hook
- num score dels visible score-mark mark-alist)
+ (let ((alist wl-summary-scored)
+ (update-unread nil)
+ wl-summary-unread-message-hook
+ num score dels visible score-mark mark-alist)
(save-excursion
- (message "Updating score...")
- (while alist
- (setq num (caar alist)
- score (cdar alist))
- (when wl-score-debug
- (message "Scored %d with %d" score num)
- (wl-push (list (elmo-string (wl-summary-buffer-folder-name)) num score)
- wl-score-trace))
- (setq score-mark (wl-summary-get-score-mark num))
- (and (setq visible (wl-summary-jump-to-msg num))
- (wl-summary-set-score-mark score-mark))
- (cond ((and wl-summary-expunge-below
- (< score wl-summary-expunge-below))
- (wl-push num dels))
- ((< score wl-summary-mark-below)
- (if visible
- (wl-summary-mark-as-read num); opened
- (setq update-unread t)
- (wl-summary-mark-as-read num))) ; closed
- ((and wl-summary-important-above
- (> score wl-summary-important-above))
- (if (wl-thread-jump-to-msg num);; force open
- (wl-summary-mark-as-important num " ")))
- ((and wl-summary-target-above
- (> score wl-summary-target-above))
- (if visible
- (wl-summary-set-mark "*"))))
- (setq alist (cdr alist))
- (when (> count elmo-display-progress-threshold)
- (setq i (1+ i))
- (elmo-display-progress
- 'wl-summary-score-update-all-lines "Updating score..."
- (/ (* i 100) count))))
- (when dels
- ;;(let ((marks dels))
- ;;(while marks
- ;;(elmo-message-set-flag wl-summary-buffer-elmo-folder
- ;; (pop marks) 'read)))
- (elmo-folder-kill-messages wl-summary-buffer-elmo-folder dels)
- (wl-summary-delete-messages-on-buffer dels))
- (when (and update update-unread)
- ;; Update Folder mode
- (wl-folder-set-folder-updated (wl-summary-buffer-folder-name)
- (list
- 0
- (let ((pair
- (wl-summary-count-unread)))
- (+ (car pair) (cdr pair)))
- (elmo-folder-length
- wl-summary-buffer-elmo-folder)))
- (wl-summary-update-modeline))
- (message "Updating score...done")
+ (elmo-with-progress-display (wl-update-score (length alist))
+ "Updating score"
+ (while alist
+ (setq num (caar alist)
+ score (cdar alist))
+ (when wl-score-debug
+ (message "Scored %d with %d" score num)
+ (wl-push (list (elmo-string (wl-summary-buffer-folder-name)) num score)
+ wl-score-trace))
+ (setq score-mark (wl-summary-get-score-mark num))
+ (and (setq visible (wl-summary-jump-to-msg num))
+ (wl-summary-set-score-mark score-mark))
+ (cond ((and wl-summary-expunge-below
+ (< score wl-summary-expunge-below))
+ (wl-push num dels))
+ ((< score wl-summary-mark-below)
+ (if visible
+ (wl-summary-mark-as-read num); opened
+ (setq update-unread t)
+ (wl-summary-mark-as-read num))) ; closed
+ ((and wl-summary-important-above
+ (> score wl-summary-important-above))
+ (if (wl-thread-jump-to-msg num);; force open
+ (wl-summary-set-persistent-mark 'important num)))
+ ((and wl-summary-target-above
+ (> score wl-summary-target-above))
+ (if visible
+ (wl-summary-set-mark "*"))))
+ (setq alist (cdr alist))
+ (elmo-progress-notify 'wl-update-score))
+ (when dels
+ (dolist (del dels)
+ (elmo-message-unset-flag wl-summary-buffer-elmo-folder
+ del 'unread))
+ (elmo-folder-kill-messages wl-summary-buffer-elmo-folder dels)
+ (wl-summary-delete-messages-on-buffer dels))
+ (when (and update update-unread)
+ ;; Update Folder mode
+ (wl-folder-set-folder-updated (wl-summary-buffer-folder-name)
+ (list
+ 0
+ (let ((flag-count
+ (wl-summary-count-unread)))
+ (or (cdr (assq 'unread flag-count))
+ 0))
+ (elmo-folder-length
+ wl-summary-buffer-elmo-folder)))
+ (wl-summary-update-modeline)))
dels)))
(defun wl-score-edit-done ()
(defun wl-score-edit-insert-date ()
"Insert date in numerical format."
(interactive)
- (princ (wl-day-number (current-time-string)) (current-buffer)))
+ (princ (elmo-time-to-days (current-time)) (current-buffer)))
(defun wl-score-pretty-print ()
"Format the current score file."
(let ((sum-buf (wl-score-edit-get-summary-buf))
(index (nth 2 (assoc header wl-score-header-index))))
(when (and sum-buf index)
- (save-excursion
- (set-buffer sum-buf)
+ (with-current-buffer sum-buf
(wl-score-get-header header extra)))))
(defun wl-score-edit-insert-number ()
(let ((sum-buf (wl-score-edit-get-summary-buf))
num)
(when sum-buf
- (if (setq num (save-excursion
- (set-buffer sum-buf)
+ (if (setq num (with-current-buffer sum-buf
(wl-summary-message-number)))
(prin1 num (current-buffer))))))