20

I have several folders defined in Mutt:

mailboxes           "~/Mail/inbox"
mailboxes           "~/Mail/sent"
mailboxes           "~/Mail/archive"

I can save (move) a message to archive, by pressing s and then ? to see a list of folders, and then I can choose archive from the list.

Since I always want only to save to archive I would like to have a macro, so that pressing s automatically saves selected message to archive, without asking me.

Can somebody please help?

EDIT: I now have following macro, to save messages to my "archive" folder:

macro index,pager S "<tag-prefix><save-message>=archive<enter>\
  :set delete=yes<enter><sync-mailbox>:set delete=no<enter>"

the problem is, the messages stay in index marked as deleted. They are not "synced" immediately. Second, the <enter> at the end acts as <display-message>, so that when I press S, I end up in the pager of the current message.

In a similar way, I am trying to implement the trash folder in mutt. The following is taken from the Mutt MacroSamples

set maildir_trash=yes
set wait_key=no
folder-hook . 'bind index q quit'
folder-hook inbox 'macro index q ":unset maildir_trash;push \"T~D\\n<tag-prefix-cond>m=trash\\n<end-cond><quit>\"\n"'

but this does not work either. Insted mutt asks me:

Append messages to etmaildir_trash;push"T~D\n<tag-prefix-cond>m=trash\n<end-cond><quit>"/maildir_trash;push"T~D\n<tag-prefix-cond>m=trash\n<end-co ([yes]/no):

what ever I press, nothing happens (the folders trash/{cur,new,tmp} do exist)

user1968963
  • 3,973
  • 13
  • 37
  • 56
  • It's puzzling that `` doesn't seem to do anything. When you use the normal delete command (`d`) and messages are left in the index marked as deleted, what happens when you press `$` (which is the default binding for ``)? – ewhac Dec 05 '13 at 20:20
  • when I press `$` mutt asks me `Purge 1 deleted message?`. I can press `Y` which will delete the message. – user1968963 Dec 06 '13 at 10:01
  • A thought occurs: The `` command is expecting user input (`y`), but seeing the immediately following `:` instead, so the purge doesn't happen. I wonder what might happen if you put a `y` after it... – ewhac Dec 07 '13 at 01:32

2 Answers2

24

tagged mails:

macro index S ":set confirmappend=no delete=yes\n<tag-prefix-cond><save-message>=archive\n<sync-mailbox>:set confirmappend=yes delete=ask-yes\n"

current only:

macro index A ":set confirmappend=no delete=yes\n<save-message>=archive\n<sync-mailbox>:set confirmappend=yes delete=ask-yes\n"

edit

macro index S ":set confirmappend=no delete=yes\n<tag-prefix><save-message>=archive\n<sync-mailbox>:set confirmappend=yes delete=ask-yes\n"

My fault, using tag-prefix instead of tag-prefix-cond, will apply the macro to tagged messages if present, else to the current selected.

Nikos Alexandris
  • 1,460
  • 2
  • 18
  • 41
Alex
  • 2,546
  • 3
  • 20
  • 30
4

The mutt guide has an example macro for your use case:

macro index <tag-prefix-cond><save-message>=foo<enter> "Save tagged messages (if any) to =foo"

You could implement it in your case like so:

macro index,pager A  "<save-message>=Mail/archive<enter>"  "mark message as Archived"

Hitting Shifta in either the index or pager view would save the message to your archive maildir.

pevik
  • 1,397
  • 15
  • 27
jasonwryan
  • 71,734
  • 34
  • 193
  • 226
  • there are two small problems with this solution: 1) I can only "save" one message at a time. I cannot tag several messages and save them all to archive. 2) when I "save" a message, it still appears in inbox marked as deleted. Is it possible to apply the changes immediately (so that it is deleted immediately from inbox) ? – user1968963 Nov 28 '13 at 10:08
  • @user1968963 Answering 2) for future reference: =Mail/archives – Alessandro Macilenti Oct 29 '21 at 10:45