Help for Pine - Filters
You are in Home > Filters

On this Page


In a few words, a filter in Pine is a mechanism of selecting mail based on text that the message contains, status (New, Answered, etc), and folder (which folder the message is in).

Filters give you the ability to split your mail into different folders, in this way you can keep different types of mail in different places. For example, I filter my mail so that only personal mail ends in my INBOX, all messages from mailing lists are filtered into different folders, each folder contains only messages received from that particular list. In that way I can

  1. Distinguish easily what my personal mail is.
  2. Check easily when new mail has arrived from a particular mailing list.

Another use of filters is deleting unwanted e-mail (like spam), or using it like a killfile in news.

How do filters work?

Every time Pine opens a folder, for each message in the folder it will scan to check if any of the filters apply to the message, if it does it will execute it and move on to the next message, where the cycle will repeat again. Filters are also executed every time that new mail arrives to the folder (if the folder is already opened), or if the filter depended on its status (message is new, answered), when the folder is about to be closed.

Every filter has two parts, the conditions that activate the filter (e.g. the message is from your boss) and the action to be taken if the conditions are satisfied (e.g. move it to the folder "work").

When you want to define a filter, you must remember that the filter will be activated if all the conditions that you specify are satisfied.

For versions of Pine previous to 4.50, if a message satisfies all the conditions, there will be just one action. Starting with Pine4.50, you can make Pine act as many filters are you like on the same message, as long as all the conditions in the filter match the message. A complete explanation of this feature is given below. If the conditions of a filter match a particular message, you can use the filter to either, delete the message or save it to a folder of your choice.

There is a further interesting consideration about filtering mail, which you need to be aware of, and is the fact that the message that you filter from a folder is not expunged from the folder after it was filtered. The message will be expunged when the folder is closed. This is not intuitive, because when you open the folder you will have the impression that the message is not in the folder anymore, but believe it or not, it is there. It was just marked "hidden" from your view. A message is set with the delete flag only when it's saved to another folder.

It is important to notice that this "hidden" flag that a filtered message has, is set after the message has been filtered. This may trigger a bug, which occurs when two sessions of Pine are trying to apply the same filter to a message. Under certain circumstances a message could be filtered more than once to another folder. At this time this problem does not have a solution.

Another important fact which you should not forget is that creating filters with long patterns may make the filter fail. This is because the UW-IMAP server has a limit of 50 levels of depth for a search program, which means in practice that you can not add more than 25 addresses in the From field (this may not be true for other servers, however). Notice, also, that there's no such limit for local folders, which means that you can add as many parameters as you like to your filters for local folders.

How Do I Set up a Filter?

To get to the filters setup screen you must press M S R F, you have two options essentially, you can press ?, and read help on how to set up filters or press A to add a filter. Remember to give a good nickname to each filter that you create so that you can go back to them afterwards if changes are necessary in the future.

This is the part that confuses most of the people, so before you begin you need to know a few things.

When you start this section you will see several lines that look like

Header pattern = <No Value Set>

If you put the cursor in anyone of them and press RETURN several times you will see that this text will toggle between:

Header pattern = <No Value Set>
Header pattern = <Empty Value>
Here are their meaning:

There is a complete explanation of how to set these conditions in the To Pattern, which you can get by putting the cursor over that line and press the ? key. It is also worth noticing that the ^T command is available for many of these headers. You can read about the importance of this command here.

Notice that a difference between setting filters, and roles or scores is that you need to define at least one condition in order for the filter to be executed. In the case of filters this may be confusing, since it is considered that not defining a pattern is always a pattern match. The reason why you need to define a pattern for filtering is because filtering is a potentially destructive operation, you may delete more e-mail than you intended, so it's a protection measure.

There are also some special patterns that you should know before you start adding filters, they are the Recipient, Participation, AllText Age Interval and Score pattern. Here are their meanings and why you would like (or not like) to use them.

Important: Also notice that if you want to set a filter that applies to all messages you must leave all fields as <No Value Set>, but set the score pattern to be:
Score interval    = (-INF,INF)
otherwise, your filter won't be applied to any message, to protect you from filtering e-mail that should not be filtered.

Adding Extra Headers

Starting with version 4.50 you can filter a message based on any header present in the message. One use of this is when you use a filter on your e-mail that adds headers that show the result of the filter. A typical case when this happens is when one uses filters to detect spam.

If you would like to filter based on a header not in the list of headers used by Pine, you must add it to the list of header first. In order to do so, put the cursor over

Add Extra Headers

and press X. You will be asked to enter the name of the header. Say you wanted to add the extra header X-Extra-Header, then after entering the name of that header, Pine will add a line to the list of headers reading X-Extra-Header Pattern = <No Value Set>, to which you will need to add the value that you want to filter, using the above stated rules.

Adding Leading and Trailing Spaces to Patterns

When you add a pattern, pine strips leading an trailing spaces from the definition of the pattern. This is undesirable if what you are trying to match depends on these spaces. For example, you can't just add a pattern that matches 3 consecutive spaces.

This problem can be avoided if one uses another notation for these spaces. For example, say that you need your pattern to match the word example followed by three spaces, then instead of writing example   , which Pine will truncate to example, you should write =?us-ascii?Q?example___?=. Each underline character _ represents a space. This form of writing a space works well when there are no 8-bit characters. If you intend to add an 8-bit character, you must encode it in some other character set, like iso-8859-1 or utf-8, and the encoding of those characters must be used. There is a restriction of 75 characters in the encoding, so don't make your matches too long.

Setting a pattern to NOT to match

Starting with Pine4.50, Pine allows you to match messages that do not satisfy the condition in the header. For example, you can match that a specific message does not come from a specific person. In order to do this, simply enter the value of the pattern in the header pattern and press the ! key. For example
! From Pattern = Wilma Flinstone
matches a message that does not come from Wilma Flinstone. Notice that
! Cc Pattern = <Empty Value> 
matches only if the message was not Cc'ed to anyone and
! Cc Pattern = <No Value Set> 
is the same as
Cc Pattern = <No Value Set> 

Applying More than One Filter

It is sometimes convenient to apply more than one filter to a message. For example, one could use a filter to move a message to two different folders.

Normally after Pine has filtered a message, Pine will not execute any more filters on the message. If you need to tell Pine that you want to have more filters applied on the same message, you must enable the configuration option

[X] dont-stop-even-if-rule-matches

at the bottom of the filter, so that Pine will continue searching for another filter that matches after it has found a message that matches this filter.

Using External Commands on Filters

You can have an external program analyze your message, and use this information to decide how you want to filter a message. A typical usage of this is to use an external program to determine if a message is spam. Other uses include tests on the message that Pine does not do (e.g. Pine does not test for the size of the message, or if a header exists and it is empty).

Pine includes three variables that control this. They are Command, Exit Status Interval and the Character Limit. Here's how they work

You can read an explicit example on how one can use this method to filter messages.

The Folders Section

In this section you need to specify the folder over which the filter is supposed to act. There are several options, all of them self explanatory. The only non obvious part is how to fill the "Specific" field. If you need to filter from a specific newsgroup you should give the following syntax:


In essence, anything that is non local you must give a location in the format above, or if it's local I recommend to give the full path.

Do not check (*) Email and then enter a specific folder, this causes all Email folders to match.

The Status Section

You can filter a message based on its status, meaning, it's New, Answered, Important or Deleted. The meaning of each of these selections is very clear. The only pattern that may confuse you is the pattern for New message. Unfortunately, there is an inconsistency in the meaning of the word New, which may cause you some grief when setting up a filter.

In the default configuration of Pine, you will think that a message is New when it has the N in the index. If you have never changed the index-format in the index screen, then you will see a N flag on messages that are either new or have not been read, and they are referred by Pine as New messages. For example, if you read a message and want to set it to unread, you would flag it new again. Starting in version 4.50 a message that is new in this sense is called New (Unseen).

In versions previous to 4.50 a message was considered New in a filter if it was not present in the folder the last time this was opened. This includes messages that arrived when the folder was already opened as well as messages that arrived during the period of time that the folder was closed. Starting in version 4.50 a message that is new in this sense is called Recent.

Notice that at the bottom of the selection there is an option


This option was created in order to avoid a bug in which Pine would filter a message twice if, for example, the connection to the server was broken during the normal operation of Pine. In that case, the message was filtered for the second time when a new connection was created. Notice that even with this option enabled, messages can still be filtered twice, since if two sessions of Pine are accessing the INBOX, there's a small chance that this may happen. In any case, the likelihood of messages being filtered twice with this option enabled is very small, and you should set it.

List of Typical Mistakes

  1. One of the most typical mistakes when adding filters is adding the same header to two (or more) header patterns, like To: and Cc:. This is a mistake usually because when somebody sends you a message, your e-mail address is in either the To: field or the Cc: field but not in both. If you intention was to set a filter that worked if your address was in the To: or the Cc: field, use the Recip Pattern as explained before. Also consider using the Partic Pattern for doing this task.
  2. Another typical mistake is that it takes some time to figure out that for filtering a message from a newsgroup you need to write the name of the news server from which the message is going to be filtered. The syntax was explained before in the "folders" section.
  3. Be careful when entering the data, once I intended to enter a period "." and entered a comma ",". In this form I realized later that I was filtering more messages than what I intended, so be careful in your input.
  4. When specifying a folder in the Current Folder Type section, do not check (*) Email and then enter a specific folder, this causes all Email folders to match. In other words, the specific folder is ignored.
  5. Remember that there is a distinction between <Empty Value> and <No value Set>. This is important as it may make the difference between the filter matching the message or not.


Here there is a link to examples of how to set up certain patterns. It is in some sense an expanded version of some of the information given here, but with much more additional information.
You are in Home > Filters