old-www/HOWTO/TkRat-6.html

120 lines
4.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>TkRat mini-HOWTO: Automatically sorting mail into folders</TITLE>
<LINK HREF="TkRat-7.html" REL=next>
<LINK HREF="TkRat-5.html" REL=previous>
<LINK HREF="TkRat.html#toc6" REL=contents>
</HEAD>
<BODY>
<A HREF="TkRat-7.html">Next</A>
<A HREF="TkRat-5.html">Previous</A>
<A HREF="TkRat.html#toc6">Contents</A>
<HR>
<H2><A NAME="s6">6. Automatically sorting mail into folders</A></H2>
<P>
<P>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.
<P>This is not a problem anymore, thanks to Procmail.
<P>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.
<P>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".
<P>The first step is to take an example mail message that came from that mailing list and examine the mail headers.
<P>I begin to notice a pattern. Every message that comes from that mailing list has a line that says:
<P>Sender: owner-linux-foo@bar.foogers.com
<P>I can now tell procmail to place every message that contains this line into a certain folder.
<P>The way I tell this to procmail is by way of a ".procmailrc" file.
<P>I will use my favorite text editor to create a text file in my home directory called ".procmailrc".
<P>The file will look something like this:
<P>
<HR>
<PRE>
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
</PRE>
<HR>
<P>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.
<P>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.
<P>The next section is saying that if the message matched nothing above, to just place it into newmail.
<P>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".
<P>I'll just create a new section of my procmailrc file. See below:
<P>
<HR>
<PRE>
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
</PRE>
<HR>
<P>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.
<P>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.
<P>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:
<P>
<HR>
<PRE>
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
</PRE>
<HR>
<P>Now I have a rather nice procmailrc file. Let's examine what procmail will do to each message as it comes in.
<P>At first, it checks the message to see if it is from "bgates@microsoft.com". If it is, delete it, and it's done.
<P>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.
<P>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.
<P>Now, if the message passes all those tests, then it should just place it into my newmail folder.
<P>
<P>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.
<P>
<P>
<HR>
<A HREF="TkRat-7.html">Next</A>
<A HREF="TkRat-5.html">Previous</A>
<A HREF="TkRat.html#toc6">Contents</A>
</BODY>
</HTML>