There are several options depending on what you are wanting to achieve and what you are wanting to do to get there.
Get the IMAP server to do the filtering for you.
This is sometimes an option in web-mail based solutions and allows you to filter the messages based on e.g. the addresses listed in the
Cc: header of each mail. I'm not familiar with Gmail's offerings in this regard.
Manually mark the messages in
mutt and copy them to a new folder on the IMAP server, or to a local mailbox.
Mark the messages you want to move with T followed by the search pattern
~C firstname.lastname@example.org (this tags all messages that were either sent directly to or Cc-ed to the address
email@example.com). Then press ; followed by s to apply the "save" (move) command to all tagged messages. Then enter the IMAP folder path you want to save the messages to.
The IMAP folder path should be specified as
Just to say that the IMAP server that I have access to doesn't like this. There are no errors, but the messages are clearly not copied. Test it on a less important message first! You may obviously save the messages locally instead!
You may also define a macro in
mutt to do this.
Download the messages from the IMAP server and filter and read them locally.
I tend to download the messages off the IMAP server using
fetchmail. This gives me the opportunity to do my own spam filtering and mail sorting on my local machine.
For both these tasks I use
procmail1 which is a fairly advanced mail processing program.
The essential configuration for
fetchmail that I use is
user "myimapusername" password "myimappassword" is "mylocalusername"
mda "/usr/local/bin/procmail -m $HOME/.procmailrc"
ssl sslcertfile /etc/ssl/cert.pem sslcertck
This will fetch any new messages off the IMAP server as they arrive, and deliver them to
procmail for processing. Paths etc. will be different on your system.
Then I filter with
procmail using a configuration (
... for two of the mailing lists I'm on (they will be stored in subdirectories under
$HOME/Mail). Mail not matching any patterns will be stored in
$HOME/Mail/inbox as specified by
DEFAULT. I'm using Maildir mailboxes. Remove the trailing slashes on the paths to get mbox mailboxes.
1 Note that
procmail is retired. I was not aware of this as I've been using is since the 90's without much consideration for any of the up-and-coming alternatives. It seems, after some gentle browsing on the interwebs, that
maildrop is considered a good alternative to
procmail, and I might look into moving my filtering over to