viewmail-info
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[VM] A trash folder for the primary inbox (code review requested)


From: Daniel Barrett
Subject: [VM] A trash folder for the primary inbox (code review requested)
Date: Tue, 16 Sep 2014 16:36:37 -0400

I'd like to share some elisp functions that create a "trash" folder
for the VM primary inbox. Since I rarely program in elisp, I welcome
any code suggestions from more experienced VM developers, for example:

- How can I obtain the strings "Summary" and "Presentation" without
hard-coding them?
- Is there an easy way to write a "trash size" function that says how
many messages are in the trash?
- Am I doing anything the wrong way where elisp/VM is concerned?

This trash folder works only for the primary inbox (by design). My use
case is that I sometimes delete and expunge a message by accident, and
VM provides no backup. This happens most often in the primary inbox.
(Perhaps it would be fancier to provide a list of folders to which the
trash applies.)

For myself, I bind the "d" keystroke to the new command
vm-trash-or-delete-message, which copies the current message to a
"Trash" folder and marks it for deletion. If this command is run
outside the primary inbox, it merely marks the message for deletion
without copying it to the trash.

I also wrote simple functions to visit and empty the Trash folder.

I stole the vm-trash-folder variable and vm-save-message-to-trash
function from http://permalink.gmane.org/gmane.emacs.viewmail/112.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar vm-trash-folder
  (concat vm-folder-directory "Trash")
  "The full path to the Trash folder for VM.")

(defun vm-save-message-to-trash ()
  "Move the current message to the Trash folder and mark it as deleted."
  (interactive)
  (vm-save-message vm-trash-folder))

(defun vm-trash-or-delete-message ()
  "If the current message is in the primary inbox, move it to the trash
and mark it for deletion. Otherwise, just mark it for deletion."
  (interactive)
  ; Name of inbox
  (let ((my-inbox-name
         (file-name-nondirectory vm-primary-inbox)))
    ; Names of buffers
    (let ((my-inbox-summary-buffer-name
           (concat my-inbox-name " Summary"))
          (my-inbox-presentation-buffer-name
           (concat my-inbox-name " Presentation")))

      ; If we're in the inbox, send to trash, otherwise delete
      (cond ((or
              (string= (buffer-name) my-inbox-summary-buffer-name)
              (string= (buffer-name) my-inbox-presentation-buffer-name))
             (vm-save-message-to-trash))
            (t (vm-delete-message 1))))))

(defun vm-visit-trash-folder ()
  "Visit the VM Trash folder as a normal mail folder."
  (interactive)
  (vm-visit-folder vm-trash-folder))

(defun vm-empty-trash-folder ()
  "Permanently delete all messages from the VM Trash folder."
  (interactive)
  (if (file-exists-p vm-trash-folder)
      (let ((ans (yes-or-no-p
                  (concat "OK to empty '" vm-trash-folder "'? "))))
        (if ans
            (write-region "" nil vm-trash-folder)
          (message "Trash folder NOT emptied")))
    (message
     (concat "Trash folder '" vm-trash-folder "' not found"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

--
Dan Barrett
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]