2

I have a gmail account, mutt is configured to get the mail through IMAP. Yesterday I subscribed to a mailing list and now my personal emails are mixed up with the ones from the list.

The list emails are addressed to me and lilypond-user@gnu.org. How can I tell mutt to move all such emails to a separate file, so they wouldn't be mixed with my emails. But I still could read them, opening that file?

4

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 To: or 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 lilypond-user@gnu.org (this tags all messages that were either sent directly to or Cc-ed to the address lilypond-user@gnu.org). 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

    imap[s]:[user[:pw]@]imapserver.example.com[:port]/path
    

    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

poll myimapserver.example.com
    protocol imap
    user "myimapusername" password "myimappassword" is "mylocalusername"
    mda "/usr/local/bin/procmail -m $HOME/.procmailrc"
    ssl sslcertfile /etc/ssl/cert.pem sslcertck
    idle

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 ($HOME/.procmailrc) like

MAILDIR="$HOME/Mail"
DEFAULT="inbox/"

:0
* ^TO_announce@openbsd.org
openbsd-announce/

:0
* ^TO_misc@openbsd.org
openbsd-misc/

... for two of the mailing lists I'm on (they will be stored is sub-directories under $HOME/Mail). Mail not matching any patterns will be stored in $HOME/Mail/inbox as specified by MAILDIR and DEFUALT. 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 maildrop myself.

  • Please note that procmail has been unmaintained for 10+ years. Its last hard-core proponents deserted it a few years ago (I was there when it happened, so I should know). :) It has well-known security vulnerabilities. And there are better alternatives to it these days. There is no reason to suggest it to new users. – Satō Katsura May 11 '17 at 16:07
  • @SatoKatsura As a procmail user since the 90's, I'm less likely to change, given that there is a maintained port on my Unix. However, that also means I'm unaware of the alternatives. Maybe you can give a good example of a well established mail processing tool that would fill procmail's void? – Kusalananda May 11 '17 at 16:16
  • 1
    The main contenders seem to be fdm and maildrop (I personally prefer fdm). Don't know about them being well-established. There's the usual pressure for people to abandon mail in favor of other, presumably easier to track systems. So the landscape of MDAs is already badly skewed. – Satō Katsura May 11 '17 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.