Procmail has been around for awhile. I used to cover this section on my mutt page but I've switched to maildrop. This page is here for those who would prefer to use procmail. Although this page won't be maintained, I hope it will be of value to some people.
(For information on using maildrop instead, see my mutt page.)
If you get a reasonable amount of email, eventually you'll want to start filtering it.
Much, if not all of this is taken from the Procmail Quickstart Guide which goes into more detail.
First we're going to set up, in the home directory, a .procmailrc file, so open your favorite text editor.
Procmail doesn't (at least according to the quickstart guide) support ~ as a representation of the home directory, so we'll be using $HOME instead. The quickstart guide goes into this in more detail, but I'm giving the bare minimum, and am also skipping their testing part--the reader who wants to get more deeply into this should definitely check out the quickstart guide.
|
PMDIR=$HOME/Procmail VERBOSE=no MAILDIR=$HOME/.maildir INCLUDERC=$PMDIR/rc.lists |
We've set up a few things here--we've told procmail not to be verbose, we've told it to check out the $HOME/Procmail directory for things and to include, in that Procmail directory an examination of the file rc.lists that we're going to put in there.
The MAILDIR line is important--the directory better be there. In Gentoo, it's $HOME/.maildir, in many other distros it's $HOME/Mail. If you're user john, you won't be putting MAILDIR=/home/john/Mail, you would simply be putting $HOME/mail.
So, next we make the procmail directory and the rc.lists files.
|
cd mkdir Procmail cd Procmail |
Open your favorite text editor and create a file called rc.lists. Here's a sample one that will put messages going to freebsd-questions in its own mailbox
|
:0: * ^TO_freebsd-questions@freebsd.org IN-FreeBSD_Questions |
You will have to set up getmail, fetchmail, or the heavier duty mailers such as sendmail and postfix to hand off to procmail. The way to do it with getmail is covered on my getmail page and typical syntax for fetchmail is covered in in another page of mine. I haven't done it with sendmail or postfix in a long time and don't remember how it would be done, but believe that both have ways to hand off mail to a delivery agent like procmail. For purposes of this article, I'll use getmail and mutt, since they're what I use.
Now, when you run getmail or whatever it will filter any messages addressed to freebsd-questions@freebsd.org. The ^TO_ means that it will search for a header beginning with To, Cc, Resent-To or other destination parameter, followed by any (or no) characters, followed by an email address beginning with freebsd-questions@freebsd.org. It's case-insensitive too, which is handy.
You can put as many of these as you like. You don't have to create the FreeBSD_Questions mailbox, it will be created the first time you get a message sent to freebsd-questions.
The quickstart guide recommends putting your busiest mailing lists first. If your two busiest lists are freebsd-questions and archlinux
|
:0: * ^TO_arch IN-Arch |
Note that you can call the mailbox whatever you want (I'm not sure if spaces are alllowed or not, haven't tried it.)
If, as in Gentoo, it uses the .maildir format, the syntax should be slightly different or you might get a segfault from time to time. .maildir doesn't seem to need lockfiles (I don't know enough about this to explain why, it's something that I was told by one of my mentors). So, rather than :0: we do
|
:0 * ^TO_gentoo-user@gentoo.org IN-gentoouser |
The colon following the zero in the example for FreeBSD creates a lockfile. The IN is my convention you can call a mailbox whatever you want, e.g freebsd, gentoo-user, etc.
In some older FreeBSD versions, procmail seemed to ignore the entire .procmailrc file. Doing a bit of searching on googlegroups, nee deja, gave me the solution.
Still in the home directory /home/john in our case, create another file. Open your text editor and create a file called .forward
It should simply read
| "|/usr/local/bin/procmail" |
That's a double quote, pipe, the absolute path to procmail double quote. After doing that, my filters worked without problem. Just to be safe, do a chmod 644 on that file.
I haven't had to create this file in awhile, whether due to FreeBSD upgrades, or procmail upgrades I have no idea. I mention it in case you run into the isssue
So, now run getmail (or if you've let it run as a cronjob, wait for it to run again). After you see that some mail has arrived open your email client. Let's assume that getmail indicated I received 7 messages. This time, when I open mutt, I'll only see two. Anything not covered by my rc.lists file went into my default inbox. In mutt I would then hit
| c |
(That's correct, just the letter c)
I'll see a message
Open mailbox ('?' for list):
If I hit ? I will then see a list of my mailboxes. (The tab key also works) Although it doesn't tell me how many messages in each one, it will show a 0 in front of any empty ones. Then, I just use the arrow key (or vi commands, such as j and k) to highlight the mailbox that I want to examine.
A few other tricks here--you might want to simply have a default personal inbox. In that case, at the bottom of your rc.lists put
|
:0: * ^TO_john@isp.com IN-personal
|
If he needs a second personal box for a second account, say isp1.com , he'd add that as well.
If you want one last rule to catch anything else then
|
:0 * ^T0_.*. IN-misc |
One other trick that you might find handy was given me by my friend George, a sedmeister. Many mailing lists have [mailinglistname] in their subject line. I use the excellent despammed.com to aid in filtering spam, and they put [despammed] in each subject line, which can be a bit of a bother, especially as it will mess up threads on mailing lists. So, I have the following rule at the top of my rc.lists.
:0hf * ^Subject.*\[despammed\] |
This formula can be used whenever you want to remove something from the subject that is in brackets, such as the name of a mailing list.
As I said, I use maildrop these days, but procmail is still quite popular.