Help for Alpine - Filters
You are in Home > Filters



In a few words, a filter in Alpine 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 Alpine opens a folder, for each message in that 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 open), 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.

You can make Alpine act as many filters are you like on the same message, as long as all the conditions in each 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 in general flag it in any way you want) 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 filtered message is set with the delete flag and hidden from your view.

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 Alpine are trying to apply the same filter to a message. Under certain circumstances a message could be filtered more than once to another folder. It has been acknowledged that this is a limitation of filtering.

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. You can also add a comment, in case you need to remind yourself of anything related to the filter for the future.

When you start seting up a filter, 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 pressing 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.

Filtering on an Arbitrary Header

One of the powers of Alpine (as opposed to any other email program) is that you can filter a message based on any header present in the message. One example of the use of this is when you use an external filter (say) on your e-mail that adds headers that show the result of another filter. A typical case when this happens is when one uses filters to detect spam.

If you would like to filter based on a specific header not in the list of default headers used by Alpine (From:, To:, etc.), 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, Alpine 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.

Setting a pattern to NOT to match

Alpine allows you to match messages that do not satisfy the condition in the header in a way that you do not need to use scores. For example, you can match that a message does not come from a particular 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 Alpine has filtered a message, Alpine will not execute any more filters on the message. If you need to tell Alpine 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 Alpine 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 use of this is to use an external program to determine if a message is spam. Other uses include tests on the message that Alpine does not do (e.g. Alpine does not test for the size of the message, or if a header exists and it is empty).

Alpine 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 Alpine, 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 Alpine as New messages. For example, if you read a message and want to set it to unread, you would flag it new again. A message that is new in this sense is called New (Unseen).

The use of the word New above is used as opposed to a new message that is Recent, that is a message that arrived after that last time that the folder was closed by another process and opened by you in the session that you are trying the filter.

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


This option was created in order to avoid a problem in which Alpine would filter a message twice if, for example, the connection to the server was broken during the normal operation of Alpine. 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 (or more times!), since if two sessions of Alpine 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.

Configuration Options Related to Filters

In the configuration screen of Alpine (press M S C to get there), there are a few options that affect the way that roles work. Here they are all explained.

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