Skip to navigation

Mutt and Gmail via IMAP: How to delete messages

Mutt is a very fast and highly configurable mail reader. Gmail now supports IMAP, and so I read my Gmail mail using mutt.

The relevant lines in my ~/.muttrc look like this:

account-hook imaps://imap.gmail.com 'set imap_user=USERNAME@gmail.com imap_pass=PASSWORD'
folder-hook imaps://imap.gmail.com 'set folder=imaps://imap.gmail.com'

So far, I was happily deleting messages from my Gmail inbox by hitting “d” in mutt as usual (I have set delete=yes, so messages get purged when I leave the inbox. Now, I discovered that the messages never got deleted, but instead were moved to Gmail’s “All mail” folder (imaps://imap.gmail.com/[Gmail]/All Mail for mutt).

Turns out, to delete messages in Gmail you need to move them to the [Gmail]/Trash imap mailbox on Gmail. Messages will be purged automatically after 30 days.

To get mutt to move the messages to Gmail’s trash folder, I had to set up a trash folder in mutt (never did that before). Mutt needs a trash folder patch applied for that, but luckily, mutt -v revealed that my precompiled Ubuntu version of mutt already comes with the patch.

So I put this in my ~/.muttrc:

folder-hook . 'unset trash'
folder-hook imaps://imap.gmail.com 'set trash="=[Gmail]/Trash"'

The fist line is important because I use several different imap accounts with mutt, not just Gmail, and I want mutt’s normal deleting behavior for all the other accounts.

But when I’m one of my Gmail folders, hitting “d” either in the index or pager view now moves the message to the Gmail trash.

5 Responses to “Mutt and Gmail via IMAP: How to delete messages”

  1. Matteo Riva Says:

    Hello, I found this article very useful. I have another issue with mutt + gmail + imap, I still have not found the solution so I thought I’d ask you: I’d like to read mail on mutt and find messages as read when I open gmail in the browser. At the moment the “newness” of messages seems client side. Is there a way to do this?

  2. Marianne Says:

    Sorry, I don’t know how to solve your problem — I am currently synchronizing Gmail’s IMAP mailboxes using offlineimap, and that works just fine.

    I think that when I used mutt to read Gmail’s IMAP mailbox directly, the “read” message state after reading an e-mail with mutt translated just fine to Gmail. Did you make sure mutt writes the changes? (command “sync-mailbox”, bound to “$” by default)

  3. Matteo Riva Says:

    Yes the problem was actually write the changes made, “sync-mailbox” was just what was needed. Thanks a lot!

  4. Marianne Says:

    Great, glad I could help.

  5. Alexander Says:

    Thank you for this post. Been trying to figure out all day how I could properly delete a message in mutt using Gmail, but this certainly did the trick.

Leave a Reply