## 6 Deleting Messages ¶

In VM, messages are flagged for deletion, and then are subsequently expunged or removed from the folder. The messages are not removed from the on-disk copy of the folder until the folder is saved.

`d (`vm-delete-message`)` ¶

  Flags the current message for deletion. A prefix argument n causes the current message and the next n-1 messages to be flagged. A negative n causes the current message and the previous n-1 messages to be flagged.

`u (`vm-undelete-message`)`

  Removes the deletion flag from the current message. A prefix argument n causes the current message and the next n-1 messages to be undeleted. A negative n causes the current message and the previous n-1 messages to be undeleted.

`k (`vm-kill-subject`)`

  Flags all messages with the same subject as the current message (ignoring “Re:”) for deletion.

`K (`vm-kill-thread-subtree`)`

  Flags all messages in the thread subtree of the current message for deletion.

``vm-delete-duplicate-messages``

  Flags duplicate messages for deletion. The duplicate messages are detected by comparing message ID’s.

``vm-delete-duplicate-messages-by-body``

  Flags duplicate messages for deletion. The duplicate messages are detected by comparing message bodies.

`### (`vm-expunge-folder`)`

  Does the actual removal of messages flagged for deletion in the current folder.

Setting the variable `vm-move-after-deleting` non-`nil` causes VM to move past the messages after flagging them for deletion. Setting `vm-move-after-undeleting` non-`nil` causes similar movement after undeletes. Setting `vm-move-after-killing` non-`nil` causes VM to move after killing messages with `vm-kill-subject`. Note that the movement is done by calling `vm-next-message` which means that the value of `vm-circular-folders` applies to the post-command motion as for a motion command, not as for a non-motion command.

Normally, deleted messages are preserved in folders until an explicit `vm-expunge-folder` operation is done. This default behavior can be altered by setting the variables `vm-expunge-before-save` and `vm-expunge-before-quit`. If `vm-expunge-before-save` is set to non-`nil`, then deleted messages are expunged whenever a folder is saved. This is not an undo-able operation and no confirmation is asked for. So you should use this setting only if your normal workflow includes expunging messages as part of save. The variable `vm-expunge-before-quit` can be similarly set to non-`nil` to cause VM to expunge deleted messages whenever you quit the folder.

The commands `vm-save-folder-no-expunge` and `vm-quit-no-expunge` can be used to preserve deleted messages in the saved folders, irrespective of the settings of the above variables. Giving a prefix argument to the `vm-quit` command has the same effect as `vm-quit-no-expunge`.

The function `vm-delete-duplicate-messages` can be used to delete duplicate copies of messages that arrive through various means. For instance, if you are a member of a mailing list, every time somebody responds to one of your messages, they might send the response to you as well as the mailing list. You then receive two copies of the response. If you get a lot of such duplicate copies, you might consider invoking `vm-delete-duplicate-messages` automatically. For instance, the customization in your VM init file can have:

    (add-hook 'vm-arrived-messages-hook 'vm-delete-duplicate-messages)

This causes the duplicate-deletion function to be invoked every time new messages arrive so that you don’t have to worry about the duplicate copies any further. (See Hooks.)