Commit 73ead349 authored by Paul Reilly's avatar Paul Reilly

Fix the expunge command so that the current message index is correct.

* pmail.el (pmail-expunge-counter): New variable
  (pmail-set-attribute): Canonicalize the calling sequence to index, attribute, state.
  (pmail-show-message, pmail-delete-message, pmail-undelete-previous-message,
   pmail-delete-forward, pmail-mark-message): Use the new canonical calling sequence.
  (pmail-only-expunge): Use the expunge counter to update the current message index.
  (pmail-expunge-callback): Simplify.  Just count the expunged messages with a lower
   index than the current message index.

* pmaildesc.el (pmail-desc-get-previous): Fix an "off by one" issue.
  (pmail-desc-set-attribute): Canonicalize the calling sequence to index, attribute, state.

* pmailout.el (pmail-output-body-to-file): Use the canonical calling sequence.
parent 15c72e1d
......@@ -186,6 +186,11 @@ please report it with \\[report-emacs-bug].")
(defvar pmail-encoded-remote-password nil)
(defvar pmail-expunge-counter 0
"A counter used to keep track of the number of expunged
messages with a lower message number than the current message
index.")
(defcustom pmail-preserve-inbox nil
"*Non-nil means leave incoming mail in the user's inbox--don't delete it."
:type 'boolean
......@@ -1908,7 +1913,7 @@ default, the current message is changed."
(let ((attr-index (pmail-desc-get-attr-index attr)))
(set-buffer pmail-buffer)
(or msgnum (setq msgnum pmail-current-message))
(pmail-desc-set-attribute attr-index state msgnum)
(pmail-desc-set-attribute msgnum attr-index state)
;; Deal with the summary buffer.
(when pmail-summary-buffer
(pmail-summary-update msgnum))))))
......@@ -2143,7 +2148,7 @@ If NO-SUMMARY is non-nil, then do not update the summary buffer."
;; Clear the "unseen" attribute when we show a message, unless
;; it is already cleared.
(when (pmail-desc-attr-p pmail-desc-unseen-index n)
(pmail-desc-set-attribute pmail-desc-unseen-index nil n))
(pmail-desc-set-attribute n pmail-desc-unseen-index nil))
(pmail-display-labels)
;; Deal with MIME
(if (eq pmail-enable-mime t)
......@@ -2554,7 +2559,7 @@ If N is negative, go forwards instead."
(defun pmail-delete-message ()
"Delete this message and stay on it."
(interactive)
(pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message)
(pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t)
(run-hooks 'pmail-delete-message-hook)
(pmail-show-message pmail-current-message))
......@@ -2568,7 +2573,7 @@ If N is negative, go forwards instead."
(setq msg (1- msg)))
(if (= msg 0)
(error "No previous deleted message")
(pmail-desc-set-attribute pmail-desc-deleted-index nil msg)
(pmail-desc-set-attribute msg pmail-desc-deleted-index nil)
(pmail-show-message msg)
(if (pmail-summary-exists)
(save-excursion
......@@ -2584,7 +2589,7 @@ With prefix argument, delete and move backward.
Returns t if a new message is displayed after the delete, or nil otherwise."
(interactive "P")
(pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message)
(pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t)
(run-hooks 'pmail-delete-message-hook)
(let ((del-msg pmail-current-message))
(if (pmail-summary-exists)
......@@ -2621,7 +2626,9 @@ See also user-option `pmail-confirm-expunge'."
(or (eq buffer-undo-list t) (setq buffer-undo-list nil))
;; Remove the messages from the buffer and from the Pmail message
;; descriptor vector.
(setq pmail-expunge-counter 0)
(pmail-desc-prune-deleted-messages 'pmail-expunge-callback)
(setq pmail-current-message (- pmail-current-message pmail-expunge-counter))
;; Deal with the summary buffer and update
;; the User status.
(let* ((omax (- (buffer-size) (point-max)))
......@@ -2650,13 +2657,9 @@ See also user-option `pmail-confirm-expunge'."
message counter."
;; Process the various possible states to set the current message
;; counter.
(setq pmail-total-messages (1- pmail-total-messages)
pmail-current-message
(cond
((= 0 pmail-total-messages) 0)
((> pmail-current-message n) (pmail-desc-get-previous pmail-desc-deleted-index n))
((> pmail-current-message n) 0)
(t pmail-current-message))))
(setq pmail-total-messages (1- pmail-total-messages))
(if (>= pmail-current-message n)
(setq pmail-expunge-counter (1+ pmail-expunge-counter))))
;;; mbox: ready
(defun pmail-expunge ()
......@@ -2793,7 +2796,7 @@ message buffers. MSGNUM-LIST is a list of the form (MSGNUM)."
(let ((n (car msgnum-list)))
(set-buffer pmail-buffer)
(pmail-narrow-to-message n)
(pmail-desc-set-attribute attr-index t n))))
(pmail-desc-set-attribute n attr-index t))))
(defun pmail-narrow-to-message (n)
"Narrow the current (pmail) buffer to bracket message N."
......
......@@ -355,18 +355,18 @@ This includes the attributes."
(nth pmail-desc-date-index (pmail-desc-get-descriptor n))))
(defun pmail-desc-get-previous (n attr-index &optional sense)
"Return the index for the previous matching descriptor.
"Return the message index for the previous matching descriptor.
Starting with descriptor at index N locate the first previous
descriptor such that the attribute ATTR is set. SENSE, if
non-null will reverse the sense of the attribute test."
(let ((index (1- n)) flag result)
(while (and (> index 0) (not result))
(if (listp (aref pmail-desc-vector index))
(setq result (pmail-desc-get-match-index attr-index sense index)))
(if (listp (aref pmail-desc-vector (1- index)))
(setq result (pmail-desc-get-match-index index attr-index sense)))
(setq index (1- index)))
(or result 0)))
(defun pmail-desc-get-match-index (attr-index sense n)
(defun pmail-desc-get-match-index (n attr-index sense)
"Return the index N if the associated descriptor has a matching
attribute, nil otherwise. The attribute value must be set if
SENSE is nil, or unset if SENSE is non-nil."
......@@ -426,7 +426,7 @@ after a message has been deleted.."
(vconcat (delq t (append pmail-desc-vector nil))))
result))
(defun pmail-desc-set-attribute (attr-index state n)
(defun pmail-desc-set-attribute (n attr-index state)
"Set the attribute denoted by ATTR-INDEX in message N according to STATE.
If STATE is non-nil the attribute will be set to the single character code
associated with ATTR-INDEX in pmail-desc-attr-alist, otherwise the attribute is
......
......@@ -244,8 +244,7 @@ FILE-NAME defaults, interactively, from the Subject field of the message."
(error "Operation aborted"))
(write-region (point) (point-max) file-name)
(when (equal major-mode 'pmail-mode)
(pmail-desc-set-attribute pmail-desc-stored-index
t pmail-current-message)))
(pmail-desc-set-attribute pmail-current-message pmail-desc-stored-index t)))
(when pmail-delete-after-output
(pmail-delete-forward)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment