Next Previous Contents

6. Automatically sorting mail into folders

If you're like me, you get about 3,500 messages a day. Each time you fetch your mail, you have to wade through all the messages looking for particular ones that interest you.

This is not a problem anymore, thanks to Procmail.

Procmail works like this: Procmail examines each message as it is downloaded, and will perform a series of tasks based upon certain rules that you've specified.

Let's say, for example, that I get about 200 messages every day from a certain mailing list (in this example, I'm using the linux-foo list). Rather than have all those messages go directly into my main inbox, I would rather that they were automatically filtered into a box called "foo-list".

The first step is to take an example mail message that came from that mailing list and examine the mail headers.

I begin to notice a pattern. Every message that comes from that mailing list has a line that says:

Sender: owner-linux-foo@bar.foogers.com

I can now tell procmail to place every message that contains this line into a certain folder.

The way I tell this to procmail is by way of a ".procmailrc" file.

I will use my favorite text editor to create a text file in my home directory called ".procmailrc".

The file will look something like this:


LOGFILE=$HOME/.pmlog
MAILDIR=$HOME/mail
VERBOSE

# linux-foo list
:0 Hw
* ^.*[Ss]ender: owner-linux-foo@bar.foogers.edu
foo-list

# if it got to this point, put it in my new mail folder
:0 Hw
newmail

Examine the "[Ss]ender" line. You'll notice that that line is the one thing that all messages from that mailing list have in common.

That section is telling procmail that when it sees a message come through with a header that looks like the above, to put it into the "foo-list" folder.

The next section is saying that if the message matched nothing above, to just place it into newmail.

Now, let's say that anytime I get a message from my good friend, EJ, I want it to go into a folder called "EJ".

I'll just create a new section of my procmailrc file. See below:


LOGFILE=$HOME/.pmlog
MAILDIR=$HOME/mail
VERBOSE
 
# linux-foo list
:0 Hw
* ^.*[Ss]ender: owner-linux-foo@bar.foogers.edu
foo-list

# Message from E.J.!
:0 Hw
* ^.*[Ff]rom: ej@mypal.com
ej
 
# if it got to this point, put it in my new mail folder
:0 Hw
newmail

Notice the new section for EJ. When a message comes in with his E-Mail address in the "From" field, it will automatically place it into my "ej" folder.

Now, let's say that there's some lamer out there who keeps on E-Mailing me. I don't want to hear from him, but he's persistent. Once again - procmail to the rescue.

So, let's say I don't ever want to see any mail from Bill Gates. I can setup a recipe to delete any mail that comes from him. Look at my new procmailrc:



LOGFILE=$HOME/.pmlog
MAILDIR=$HOME/mail
VERBOSE
 
# Is it coming from Bill Gates?  If yes, DELETE IT!!!
:0 Hw
* ^.*[Ff]rom: bgates@microsoft.com
/dev/null

# linux-foo list
:0 Hw
* ^.*[Ss]ender: owner-linux-foo@bar.foogers.edu
foo-list
 
# Message from EJ!
:0 Hw
* ^.*[Ff]rom: ej@mypal.com
ej
 
# if it got to this point, put it in my new mail folder
:0 Hw
newmail

Now I have a rather nice procmailrc file. Let's examine what procmail will do to each message as it comes in.

At first, it checks the message to see if it is from "bgates@microsoft.com". If it is, delete it, and it's done.

If the message made it through the first check, it will see if it has the "owner-linux-foo@bar.foogers.edu" in the headers. If it does, it will put it into the "foo-list" folder, and it's done.

If the message still makes it past that, then it checks to see if it's from EJ. If it is, it places it into the "ej" folder.

Now, if the message passes all those tests, then it should just place it into my newmail folder.

Once you have these folders in place and procmail is properly filtering the mail, you can just go into TkRat, "Admin - New/Edit Folder" and create the folders for each filename. They will be located under /home/username/mail/foldername.


Next Previous Contents