After using KMail for a while, you may find that you have trouble sorting out the new messages in your inbox when they arrive. Filters allow you to automatically perform certain actions on incoming messages and to manually perform actions on selected messages in a folder.
Usually, filters are used on incoming messages, but they can also be applied to a message or group of messages. To selectively filter messages in a message folder, select the messages you want to filter and type Ctrl-J or select Message->Apply Filters. Note that this will apply all of your filters to that message; there is no way to apply only certain filters to a message.
If you ever need to remove a filter, select it from the Filter Rules window and press the Delete button.
The most common use of filters is to sort incoming messages to certain folders. This can be done by choosing transfer. But there are other actions a filter can start:
transfer will move the message to another folder.
set identity will set your identity if you reply to this message
set transport will set the method of transport (e.g. SMTP) if you reply to the message.
set Reply-To will modify the Reply-To field of this message. This can be useful for mailing lists that automatically set a Reply-To which you don't like.
forward to will forward the message to another email address.
execute will execute a program, but will not modify the message. Specify the full path to any program you want to execute. KMail will block until the program returns. You can feed the program with the parts of the mail: %0, %1, etc will stand for files representing the message parts. For common mails %0 is the text, %1 the first attachment and so on.
filter app will feed the message to a program. If that program returns output, the entire message (including the headers) will be replaced with this output. If the program doesn't return output, the message won't change. Specify the full path to the program. Be cautious with this action, as it will easily mess up your messages if the filter program does return garbage or extra lines.
If I am subscribed to the KDE User List, I could create a folder for the list (I'll call it KDE-User) and use a filter to automatically transfer new messages from my inbox to my KDE-User folder if they are from the KDE User List. Here is how to create this filter:
Think of a unique way of identifying the messages you want to filter. The unique property of my KDE User List messages is that they always contain "kde-user@kde.org" in the To: or Cc: field.
Select Settings->Filter Rules....
Press the New button to create an empty filter. It will appear as Unnamed.
The right side of the Filter window contains two sections: matching criteria and actions. In the matching criteria area, select <To: or Cc:> from the first pull-down menu, contains from the second pull-down menu, and type kde-user@kde.org in the text field.
Skip down to the actions section. Select transfer from the first pull-down menu. A new pull-down menu containing a list of folders will appear. Select the folder that you want the filtered messages to be transferred to if they match the criteria you selected. For this example, you would select "KDE-User" from the pull-down menu.
You may find that you need to use more complicated criteria to properly filter your messages. For example, you may only want to save the KDE User List messages that are written by your friend Fred Johnson <fj@anywhere.com>. This is where the rest of the matching criteria section comes into play:
Open up the Filter Rules window and select the filter you just created.
Since you want to filter all messages that have "kde-user@kde.org" in the To: or Cc: field AND that are from Fred, select the and option from the pull down menu between the two criteria sections.
Now, go to the bottom criteria section and select the following from the pull-down menus: From, contains. Now, type fj@anywhere.com in the text field.
You now have a filter that transfers all KDE User List messages that are from Fred Johnson.