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


  1. Setting Up Headers
  2. Matching the absence of a header
  3. Setting up the Folder Type and Location
  4. Setting the Status of the Message to be Filtered
  5. Using External Commands
  6. Moving Messages Between Folders
  7. Deleting Unwanted Messages Automatically
  8. Setting the Status of the Filtered Message
  9. Using Filters as a Killfile
  10. Filtering From your Pinerc
  11. Having Problems Making the Filter Work?

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 In this case, you would write

From pattern      =

If you also want to filter the messages of Wilma Flintstones (whose address, you guessed it, is 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 	  =,

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, 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

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

You can choose among "any" folder, which means that it will apply to any mail folder or newsgroup, or can set it to be applied for newsgroups, or 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 = {}

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 

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

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/
    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
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.

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

Having Problems Making the Filter Work?

If you are still having problems making the filter work, people in newsgroups or mailing lists will be glad to help you make your filter work. The best way to ask for help is to copy and paste the filter in the body of your post and send it for others to see your filter. The best way to share a filter with others, however, is to post the relevant line from your .pinerc file, that is the variable patterns-filters2.
You are in Home > Filters > Examples