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)

3
  • It's puzzling that <sync-mailbox> 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 <sync-mailbox>)?
    – ewhac
    Dec 5, 2013 at 20:20
  • when I press $ mutt asks me Purge 1 deleted message?. I can press Y which will delete the message. Dec 6, 2013 at 10:01
  • A thought occurs: The <sync-mailbox> 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 7, 2013 at 1:32

2 Answers 2

24
+100

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.

7
  • when I add your macro and start mutt and pres S, mutt says: nothing to do Dec 7, 2013 at 20:26
  • Do you tag some mail?
    – Alex
    Dec 7, 2013 at 20:29
  • great, it works. How could I make it work on current message aswell (without having to tag it first) ? Dec 7, 2013 at 20:42
  • 1
    @user1968963 see the update.
    – Alex
    Dec 7, 2013 at 23:58
  • 1
    @user1968963 maybe using tag-prefix-cond to set a different command/variable (for my understanding is executed only if there are tagged mail), I'll try but will require some time, will let you know.
    – Alex
    Dec 8, 2013 at 15:43
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.

2
  • 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) ? Nov 28, 2013 at 10:08
  • @user1968963 Answering 2) for future reference: <save-message>=Mail/archives<enter><enter><sync-mailbox><enter> Oct 29, 2021 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .