Help for Pine - Examples of Filters
You are in Home > Filters > Examples

Here there are a few examples that show you how filters work.

  1. Setting up Headers
  2. Setting up the Folder Type and Location
  3. Setting the Status of the Message to be Filtered
  4. Using External Commands
  5. Moving Messages Between Folders
  6. Deleting Unwanted Messages Automatically
  7. Setting the Status of the Filtered Message
  8. Using Filters as a Killfile

Setting up the Conditions of the Filter

As you would expect, filters only act upon a condition being satisfied. There are three types of conditions that must be satisfied for a filter to go in effect. These conditions are of header type (e.g. the message is from a particular person, or it contains a specific word in the subject), they can also be of folder type (which folder is the message that you are reading in), and of status type (which is if the message is new, deleted, etc) at the moment the message is about to be filtered.

Setting Up Headers

This is the most important setting of a filter, there are several important points which you must remember when setting a filter. I discuss more about this in the Filters section.
 

Having said that, let's see a few examples.

Setting the From Pattern

Let us say that you want to filter messages from a particular person, say Peter Flintstones, out of the INBOX. Say that Peter Flintstones, has e-mail address peter@bedrock.com. In this case, you would write

From pattern      = peter@bedrock.com

If you also want to filter the messages of Wilma Flintstones (whose address, you guessed it, is wilma@bedrock.com) in the same way that you are filtering those of Peter, all you need to do is add Wilma to the From pattern, separating it by a comma "," from other entries. It should look as follows

From pattern 	  = peter@bedrock.com, wilma@bedrock.com

Setting the To Pattern

The To field is set in the same way as the From field. No special considerations apply to this field.

Setting the Cc Pattern

The point here is not how to set this field. This field is set in the same way as the From field is set. There is, however, the consideration of when to set this field.

Assume that you filter messages from your long time friend Peter Flintstones, that go To your@address.com, so you have followed the instructions above and have set the "From pattern" and the "To pattern" correctly. Now assume that Peter has decided to send a message to Wilma Flintstones and a copy of the message to you, by filling the Cc: field. What should you do in order to filter this message to the folder where you filter messages from Peter Flintstones?

Should you also add a "Cc Pattern" with your e-mail address in it?. No, don't do that. A filter like that will only be applied if the message that you are filtering has your address in the To: and in the Cc: field, which is a very unlikely thing to happen.

Here are your options to solve this problem
 

Setting the Score Interval

If you have set up scores, all you need to do is to enter here an interval of the form (a,b) that contains the score that you want to filter. For example to filter a message with positive scoring, just set this interval to be:

Score interval    = (0, INF)
(no the number zero is not positive).

The issue with this field is not how to set it, but when to set it. I discuss this in the Score Interval section of the help on Filters.

Matching the absence of a header

Starting in Pine4.50, you can set a filter to match the condition of absence of a header, this is done by setting the header pattern as:

! Header Pattern = <Empty Value>

Setting up the Folder Type and Location

This setting was moved in Pine4.41 (the philosophy that Pine always looks the same does not exist anymore), it used to be at the bottom. Anyway, you can choose "any" folder, which means that it will apply to any mail folder or newsgroup, you can only set it to be applied for newsgroups, for "email", which means that it will be applied if your folder is not a newsgroup (could be local or remote).

You can also filter messages from an incoming folder, all you need to do is write the "nickname" of that incoming folder in the "Folder List", configuration option. There is no default. A typical entry would look like:

       (*)  Specific (Enter Incoming Nicknames or use ^T)
                 Folder List = INBOX
If you need to set up a specific newsgroup, just make it look like
(*) Specific (Enter Incoming Nicknames or use ^T)
      Folder List = {your.news.server/user=yourid/nntp}#news.name.of.newsgroup

Setting the Status of the Message to be Filtered

This section can be ignored, and probably you will hardly ever set the status. This controls what should be the status of a message when the filter is applied (e.g. you can set the filter to only be applied to messages that are New, in this way you may avoid having messages filtered twice). Learning how to set up this part is very easy. I leave it to you.

Using External Commands

In this example we are going to set a filter that executes an external command. We are going to make the external filter look for lines containing a URL from a ".org" domain. If any lines are found, the filter will be considered a match, otherwise it is not a match.

In order to look for a match, I will use the following command

sed 1,/^$/d filename | grep "http://.*\.org"

I am interested in the exit code of this command, so I look at the manual for the grep command, which says:

       Normally, exit status is 0 if selected lines are found and 1 
       otherwise. But the exit status is 2 if an error occurred, unless 
       the -q or --quiet or --silent option is used and a selected line is 
       found.

From here we conclude that we found a match only if the exit status is 0, so we copy this command into a script "spam.org" which reads as follows:

#!/bin/sh
sed 1,/^$/d $1 | grep "http://.*\.org"
exit $?

Now we define the relevant part in the filter as follows

External Categorizer Commands =
    Command              = /home/chappa/scripts/spam.org
    Exit Status Interval = (0,0)
    Character Limit      = 1000

I set the Character Limit variable to be 1000 characters of the body (plus headers), because I assume that if a spammer is going to send me a URL to visit a web site it will be in the beginning of the message, around the first 12 lines (80 x 12 = 960). Of course this is an incorrect assumption, but it will probably catch most messages in this way. If you want to be sure that you will catch all messages, simply replace that 1000 by -1.

Configuring the Action of the Filter

Once you have set up the headers, the folder location and the status, it's time to decide what to do with the message, you can either move it to another folder, delete it, and/or change its status. Let's explore all of them.

Moving Messages Between Folders

In this section we will talk about moving mail to another folder. First you need to decide if the folder is local or remote, if it's local all you need to do is give its path, or if it is in your mail/ folder collection, need to give the path relative to the mail/ directory. Typical entries are:

Filter Action   =
       (*)  Move (Enter folder name(s) in primary collection, or use ^T)
            Folder List = saved-messages
and
Filter Action   =
       (*)  Move (Enter folder name(s) in primary collection, or use ^T)
            Folder List = /full/path/to/location/of/folder

If the folder that you are trying to save to, is a remote folder, then you need to define it more or less as follows

Filter Action   =
 (*)  Move (Enter folder name(s) in primary collection, or use ^T)
      Folder List = {name.of.server/user=yourid}/full/path/to/folder
Notice that "/full/path/to/folder", may not work if that server does not allow full paths to be entered, if that's the case, you can enter a path relative to $HOME (e.g. mail/saved-messages).

Deleting Unwanted Messages Automatically

After having set the conditions on which the filter will apply, all you need to do to delete an unwanted message is set

Filter Action   =
            (*)  Delete                                                      

Use this option at your own risk. If you are using this option to remove spam, I recommend you to take a look at the Received: header and delete messages according to the contents of that header, and even then be careful, you only want to remove according to the contents of the last Received: header in the message. If you know how to read this header, this is the best way to do it, otherwise, don't even try this.

Setting the Status of the Filtered Message

Again this is a trivial thing to learn, and the configuration is very easy. You can use this configuration in conjunction with color settings, to make some messages look in a different color in your index, so for example you can paint important messages in different colors in your index screen, and you can use filtering to just change the status of a message to be important. Notice that if you set

Filter Action   =
            (*)  Just Set Message Status 
the message will remain in the folder from which is being filtered, and only its status will be changed.

Using Filters as a Killfile

A killfile is a file that tells a newsreader which posts you don't want to see, and that they should be automatically deleted. As it was pointed out before, you can set a filter that will delete messages from any newsgroup (or all of them). This is an easy consequence of what we discussed before.
 

Filtering From your Pinerc

The following lines will show you how a filter looks like from the point of view of the pinerc file. You can feel free to copy them and modify them to your liking. These filters were created to be used in version 4.50, or newer. Older versions of Pine may not recognize these filters (or may recognize them incorrectly, at best)

You need to add the following definitions under the variable patterns-filters2=. All filters, except the last one in your list of filters must end with a comma.

Before you copy these filters, you need to know something about how to read them. Since filters are potentially destructive, you need to know how to recognize if a filter deletes a message. If a filter is going to delete a message it will contain the string action="/FILTER=1" in the definition. The important part is the number 1 in the above definition. Other values of FILTER will not delete a message filtered using that rule. Observe that filters that move messages between folders delete those messages from the respective folder being filtered.

  1. Filters that move messages
  2. Filters that delete messages

You are in Home > Filters > Examples