Mutt: A faster way to mark messages as read

I was looking for a macro for Mutt to mark all the messages in a mailbox as read and came across this post which suggested:

[cce]macro index M “T.*\n;WN” “Mark all messages as read”[/cce]

However, this is slow because it performs a tag matching against the Regex pattern “.*”, which is computationally intensive. Another post recommended using ~A instead of .*, but this still has to tag everything in your mailbox and that kind of sucks big-time. So, I came up with this instead:

[cce]macro index <esc>m “T~N<enter>;WNT~O<enter>;WO\CT~T<enter>” “mark all messages read”[/cce]

It first selects all messages marked “New” and untags them. Then, it selects all messages marked “Old” but unread and untags them as well. Finally, it gets rid of all the tag markings by doing T ~A.

Seems to be working pretty snappily.

3 Responses to “Mutt: A faster way to mark messages as read”


  • Here’s a slight improvement, perhaps!

    [I’m afraid what will happen if I try to use angle brackets in this form, so I will use double-curly brackets instead.]

    # Something to mark a whole folder as ‘read’
    # Line by line,
    # 1. Tag all Unread or Old messages
    # 2. If any messages are tagged, [macro aborts otherwise]
    # 3. Clear the Unread flag
    # 4. Clear the Old flag
    # 5. Untag all messages
    macro index {{esc}}m ‘\
    {{tag-pattern}}~N|~O{{enter}}\
    {{tag-prefix-cond}}\
    {{tag-prefix}}{{clear-flag}}N\
    {{tag-prefix}}{{clear-flag}}O\
    {{untag-pattern}}~T{{enter}}’ “mark all messages read”

    You can actually do without the first tag-prefix (since tag-prefix-cond both checks for tagged files *and* works as a tag-prefix), but I like to keep it for symmetry.

    The reason for all the bracketed commands is to avoid relying on keyboard bindings by calling the relevant functions directly. But the main improvement is using tag-prefix-cond to avoid generating spurious commands when no messages are unread!

  • Woah, that’s neat. I didn’t know about tag-prefix-cond. Now I know how to fix some of my other macros that break when no messages match. Thanks!

  • The traditional way to untag everything is with ;t. Does T~A or T~T offer any advantages?

Comments are currently closed.