Filtering and Processing of Messages

From Claws Mail FAQ

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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/sylpheed-claws/" Folder, that move messages older that 60 days to an archive folder:

age_greater 60 move "#mh/mailbox/sylpheed-claws/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-unsensitive 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 messsages 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.

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.

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

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

: error "$@"
: exit 0


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

# 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"

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

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

# 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).