Difference between revisions of "Filtering and Processing of Messages"

From Claws Mail FAQ
Jump to: navigation, search
 
m (Reverted edit of Worthlessomen39, changed back to last version by Shlomif)
 
(16 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 +
<div id=age>
 
=== What type of value do the "age ..." match types in the filtering configuration expect? ===
 
=== What type of value do the "age ..." match types in the filtering configuration expect? ===
  
 
You simply have to add the value in days. If you want for example to select messages older than a month, enter 30 or 31.
 
You simply have to add the value in days. If you want for example to select messages older than a month, enter 30 or 31.
  
Example of a folder processing rule of the "mailbox/sylpheed-claws/" Folder, that move messages older that 60 days to an archive folder:
+
Example of a folder processing rule of the "mailbox/claws-mail/" Folder, that move messages older that 60 days to an archive folder:
 
<pre>
 
<pre>
age_greater 60 move "#mh/mailbox/sylpheed-claws/archive"
+
age_greater 60 move "#mh/mailbox/claws-mail/archive"
 
</pre>
 
</pre>
  
 
'''Note:''' Age checks are done against the 'Date'-header in the mail. So if the sender has misconfigured his computer and sends mails with a wrong date, the rule could move mails instantly if the date is more then 60 days in the past or never when it is in the future.
 
'''Note:''' Age checks are done against the 'Date'-header in the mail. So if the sender has misconfigured his computer and sends mails with a wrong date, the rule could move mails instantly if the date is more then 60 days in the past or never when it is in the future.
 
+
</div>
 
=== Can I filter messages based on Content-Type of attachments, for example "application/x-msdownload"? ===
 
=== Can I filter messages based on Content-Type of attachments, for example "application/x-msdownload"? ===
  
Line 15: Line 16:
  
 
Please note that application/octet-stream is also a potential infected content (.pif for instance).
 
Please note that application/octet-stream is also a potential infected content (.pif for instance).
You can also use a more generic case-unsensitive regexp matching rule against the 'Body part' like the following one:<br>
+
You can also use a more generic case-insensitive regexp matching rule against the 'Body part' like the following one:<br>
 
<pre>
 
<pre>
 
Content\-Type: ~[[a-z0-9_/-]]+; name="~[[^\.]]+\.(bat|pif|cmd|vbs|vba|scr|lnk|com|exe|java|asp|cgi)"
 
Content\-Type: ~[[a-z0-9_/-]]+; name="~[[^\.]]+\.(bat|pif|cmd|vbs|vba|scr|lnk|com|exe|java|asp|cgi)"
Line 24: Line 25:
 
=== What is the difference between Filtering, Folder Processing, Pre/Post-processing? ===
 
=== What is the difference between Filtering, Folder Processing, Pre/Post-processing? ===
  
Filtering rules are global. Messages received on an Account can be filtered in 2 ways, automatically or manually. To have the messages filtered automatically the option 'Filter messages on receiving' must be checked on the 'Receive' tab in the Account Preferences. Manual filtering can be performed by using '/Tools/Filter all messsages in folder' or '/Tools/Filter selected messages'.
+
Filtering rules are global. Messages received on an Account can be filtered in 2 ways, automatically or manually. To have the messages filtered automatically the option 'Filter messages on receiving' must be checked on the 'Receive' tab in the Account Preferences. Manual filtering can be performed by using '/Tools/Filter all messages in folder' or '/Tools/Filter selected messages'.
  
Folder Processing rules apply only to the messages contained in that particular folder. A folder's Processing rules are applied upon entering that folder, or on program startup if 'Process at startup' is checked in a folder's Properties.
+
Folder Processing rules apply only to the messages contained in that particular folder. A folder's Processing rules are applied upon entering that folder, or on program startup if 'Process at startup' is checked in a folder's Properties, or on demand by using 'Run processing rules' from the folder's context menu.
  
 
Pre and post-processing rules are global rules which are executed before and after the folder processing rules, respectively.
 
Pre and post-processing rules are global rules which are executed before and after the folder processing rules, respectively.
In other words: Whenever you select a folder, first pre-processing rules are applied, then folder specific processing rules and lastly post-processing rules. See [#Q01 'age'-question] for an example.
+
In other words: Whenever you select a folder, first pre-processing rules are applied, then folder specific processing rules and lastly post-processing rules. See [[Filtering_and_Processing_of_Messages#age|'age'-question]] for an example.
  
 
=== Can a filter modify the contents of a message? ===
 
=== Can a filter modify the contents of a message? ===
Line 42: Line 43:
 
#
 
#
 
# sc-spamc : a script for using SpamAssassin header modification / subject
 
# sc-spamc : a script for using SpamAssassin header modification / subject
# tagging vi Sylpheed-Claws filtering actions.
+
# tagging vi Claws Mail filtering actions.
 
#
 
#
 
# Author: Robert Story
 
# Author: Robert Story
# Send questions or comments to the sylpheed-claws-users mailing list
+
# Send questions or comments to the claws-mail-users mailing list
 
#
 
#
# Based on a simpler script posted to the sylpheed-claws-users mailing list
+
# Based on a simpler script posted to the claws-mail-users mailing list
 
# by Richard A Downing.
 
# by Richard A Downing.
 
#
 
#
Line 79: Line 80:
 
#
 
#
 
mv "$FILE" "$FILE.bak"
 
mv "$FILE" "$FILE.bak"
if ?$? -ne 0; then
+
if test $? -ne 0; then
 
: die "'mv $@' failed!"
 
: die "'mv $@' failed!"
 
fi
 
fi
Line 87: Line 88:
 
#
 
#
 
mv "$TEMP" "$FILE"
 
mv "$TEMP" "$FILE"
if ?! 0 = $?; then
+
if test ! 0 = $?; then
 
: mv "$FILE.bak" "$FILE"
 
: mv "$FILE.bak" "$FILE"
 
: die "spam result rename failed, restoring backup"
 
: die "spam result rename failed, restoring backup"
Line 98: Line 99:
 
#
 
#
 
exit $RC
 
exit $RC
 +
 
</pre>
 
</pre>
 
Now, set up a Filtering rule (test "!(sc-spamc %F)"), with an action for dealing with spam (eg color it, move it to a folder, etc).
 
Now, set up a Filtering rule (test "!(sc-spamc %F)"), with an action for dealing with spam (eg color it, move it to a folder, etc).
 +
 +
=== How do I add a filter for SPF checking? ===
 +
 +
To check if the sender IP address matches the SPF record you can download the script sylpheed-spf.pl from http://www.willamowius.de/claws-spf.html and add a filter with the following condition and move matching mails to your spam folder.
 +
 +
<pre>
 +
test "!(sylpheed-spf.pl -c <%F)"
 +
</pre>
 +
 +
=== My ISP adds headers that identify spam and viruses.  How do I filter on a custom header? ===
 +
 +
You can filter on a custom header.  The drop-down list of headers defaults to the commonly used headers, but you can edit the list and add new entries. Create a filter in the normal way and select "Header" as the condition.  Simply start typing in the list box to edit or add a header.

Latest revision as of 10:26, 26 October 2012

Contents

What type of value do the "age ..." match types in the filtering configuration expect?

You simply have to add the value in days. If you want for example to select messages older than a month, enter 30 or 31.

Example of a folder processing rule of the "mailbox/claws-mail/" Folder, that move messages older that 60 days to an archive folder:

age_greater 60 move "#mh/mailbox/claws-mail/archive"

Note: Age checks are done against the 'Date'-header in the mail. So if the sender has misconfigured his computer and sends mails with a wrong date, the rule could move mails instantly if the date is more then 60 days in the past or never when it is in the future.

Can I filter messages based on Content-Type of attachments, for example "application/x-msdownload"?

Yes. Select Match Type 'Body part' and enter the Value Content-Type: application/x-msdownload.

Please note that application/octet-stream is also a potential infected content (.pif for instance). You can also use a more generic case-insensitive regexp matching rule against the 'Body part' like the following one:

Content\-Type: ~[[a-z0-9_/-]]+; name="~[[^\.]]+\.(bat|pif|cmd|vbs|vba|scr|lnk|com|exe|java|asp|cgi)"

Note: This will also match text inside the message and not only the Content-Type, so be aware of messages discussing the structure of MIME-Mails.

What is the difference between Filtering, Folder Processing, Pre/Post-processing?

Filtering rules are global. Messages received on an Account can be filtered in 2 ways, automatically or manually. To have the messages filtered automatically the option 'Filter messages on receiving' must be checked on the 'Receive' tab in the Account Preferences. Manual filtering can be performed by using '/Tools/Filter all messages in folder' or '/Tools/Filter selected messages'.

Folder Processing rules apply only to the messages contained in that particular folder. A folder's Processing rules are applied upon entering that folder, or on program startup if 'Process at startup' is checked in a folder's Properties, or on demand by using 'Run processing rules' from the folder's context menu.

Pre and post-processing rules are global rules which are executed before and after the folder processing rules, respectively. In other words: Whenever you select a folder, first pre-processing rules are applied, then folder specific processing rules and lastly post-processing rules. See 'age'-question for an example.

Can a filter modify the contents of a message?

None of the built-in filters modify the contents of a message, but you can use the 'test' filter to run a command that can modify the contents of a message. See the next question for an example.

How do I configure a filter for running SpamAssassin?

If you want to use SpamAssassin directly, instead of using the plugin, you can get the SpamAssassin headers added to each message, and/or tag the subject line of spam messages. First, you have to set up SpamAssassin correctly, which is beyond the scope of this FAQ. This example uses the spamc/spamd client server model, but it could easily be adapted for calling SpamAssassin directly. First, save this script somewhere in your PATH (eg $HOME/bin/sc-spamc).

#!/bin/bash
#
# sc-spamc : a script for using SpamAssassin header modification / subject
# tagging vi Claws Mail filtering actions.
#
# Author: Robert Story
# Send questions or comments to the claws-mail-users mailing list
#
# Based on a simpler script posted to the claws-mail-users mailing list
# by Richard A Downing.
#
# Should return the return code from spamc (1=spam, 0=nospam/error)
#

die()
{
: error "$@"
: exit 0
}

FILE=$*
TEMP=sc-spamc.$$

#
# call spamc, redirect output to temporary file, and save return value
#
/usr/bin/spamc -E -t 30 < "$FILE" > "$TEMP"
RC=$?

#
# make sure temp file exists before we replace original message
#
if ! test -s "$TEMP" ; then
: die "spamc result file doesn't exist or is 0 bytes"
fi

#
# backup original
#
mv "$FILE" "$FILE.bak"
if test $? -ne 0; then
: die "'mv $@' failed!"
fi

#
# rename filtered file
#
mv "$TEMP" "$FILE"
if test ! 0 = $?; then
: mv "$FILE.bak" "$FILE"
: die "spam result rename failed, restoring backup"
else
: rm "$FILE.bak"
fi

#
# return spamc exit code
#
exit $RC

Now, set up a Filtering rule (test "!(sc-spamc %F)"), with an action for dealing with spam (eg color it, move it to a folder, etc).

How do I add a filter for SPF checking?

To check if the sender IP address matches the SPF record you can download the script sylpheed-spf.pl from http://www.willamowius.de/claws-spf.html and add a filter with the following condition and move matching mails to your spam folder.

test "!(sylpheed-spf.pl -c <%F)"

My ISP adds headers that identify spam and viruses. How do I filter on a custom header?

You can filter on a custom header. The drop-down list of headers defaults to the commonly used headers, but you can edit the list and add new entries. Create a filter in the normal way and select "Header" as the condition. Simply start typing in the list box to edit or add a header.