welcome: please sign in

Diff for "MemberManual/Email/EximFilter"

Differences between revisions 13 and 23 (spanning 10 versions)
Revision 13 as of 2008-04-24 17:51:29
Size: 3923
Comment:
Revision 23 as of 2020-08-09 21:59:54
Size: 8030
Comment: Added Sieve filter example
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
[[TableOfContents]] <<TableOfContents>>
Line 17: Line 17:
If you want to do anything more complicated than this, the exim project website has some good examples http://www.exim.org/exim-html-3.30/doc/html/filter_29.html. We also have an example .forward file in the following section. If you want to do anything more complicated than this, the exim project website has some good examples http://www.exim.org/exim-html-current/doc/html/spec_html/filter_ch-exim_filter_files.html. We also have an example .forward file in the following section.
Line 76: Line 76:

== StephenMichel ==

=== Sieve Filter ===

I've migrated to using a [[https://www.fastmail.com/help/technical/sieve-howto.html|Sieve filter]], which gives up a little power (that I was not using) for much saner syntax. This is the current version, including a commented-out part that I will probably remove since I don't ''think'' I'm using it any more. I've changed all domains to {{{example.com}}} to avoid spambots picking up email addresses off this page.

{{{
# Sieve filter

require ["fileinto"];

if address :contains ["to", "cc", "bcc"] ["admin@example.com", "community@example.com", "privacy@example.com"] {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.snowdrift.aliases/";
}
elsif address :contains :domain "to" "lists.example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.hcoop/";
}
# elsif address :matches ["to", "cc", "bcc"] ["snowdrift@example.com", "snowdrift+*@example.com"] {
# fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.snowdrift/";
# }
# elsif address :matches ["to", "cc", "bcc"] ["tufts@example.com", "tufts+*@example.com"] {
# fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.tufts/";
# }
elsif address :contains ["to", "from", "cc", "bcc"] "board@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.Board/";
}
elsif address :contains "from" "notifications@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.GitHub/";
}
elsif address :contains "to" "gitlab.com+notifications@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.GitLab/";
}
elsif header :matches "Reply-To" "*@boards.example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.Trello/";
}
elsif address :contains "to" "hnreplies.com@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.HN/";
}
elsif address :contains "to" "2_DO@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.2_DO/";
}
elsif address :contains "to" "2_READ@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.2_READ/";
}
elsif allof (
    address :contains "from" "admin@example.com",
    header :contains "subject" "[Lutris] Your daily moderator mail"
) {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.lutris/";
}
else {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/";
}
stop;
}}}


=== Exim Filter ===

This template filters anything sent to {{{me@example.com}}} ''or'' to {{{me+$anything@example.com}}} into the sub-folder {{{me}}}. This is useful if you have one or more aliases set up, to filter mail for each alias into its own subfolder.
{{{
if "$h_to:, $h_cc:, $h_bcc:" matches "me(\\\\+[\\^@]\\*)\\?@example\\\\.com"
        then save $home/Maildir/.me/
endif
}}}

== Björn Lindström ==

Some rules using {{{matches}}} which allows PCRE style regular expressions.

{{{
# Exim filter

# Log
logfile $home/.logs/mail/exim.log

# Don't do any filtering on delivery failure messages from Exim.
if error_message then finish endif

# Spam
if "${if def:h_X-Spam-Level {def}{undef}}" is "def" then
    # Drops mail with a spam level above 9
    if $h_X-Spam-Level: matches "^\\\\*{9}" then
        seen
        finish
    # Puts other mail with a spam level above 3 into "Spam"
    elif $h_X-Spam-Level: matches "^\\\\*{3}" then
        save $home/Maildir/.Spam/
        finish
    endif
elif "${if def:h_X-Spam-Flag {def}{undef}}" is "def" then
    # Puts other mail with spam flag set into "Spam" also.
    save $home/Maildir/.Spam/
    finish
endif

# Filter into folders
if "$h_to:, $h_cc:, $h_bcc:" matches "\\\\b((bkhl|upp?sala|relax)@fandom\\\\.se|upp?salafandom@dang\\\\.se|fanac@lists\\\\.lysator\\\\.liu\\\\.se)\\\\b" then
    save $home/Maildir/.Fandom/
elif "$h_to:, $h_cc:, $h_bcc:" matches "@(\\.*\\\\.)?hcoop\\\\.net\\\\b" then
    save $home/Maildir/.HCoop/
endif
}}}
Line 78: Line 183:
----
CategoryMemberManual CategoryNeedsWork

This page explains how to use Exim's built-in per-user filtering system to sort your mail into different folders or deliver it elsewhere.

Introduction

We use Exim as our mail daemon. It has a built-in filtering system that allows people to write a ".forward file" to give it custom instructions. Normally this is stored at ~/.forward, but at HCoop we store it at ~/.public/.forward to make it easier to keep the rest of your home directory private. So when we say ".forward" on the rest of this page, we mean ~/.public/.forward.

When email is delivered, the delivery process will run as the USER.daemon user, where USER is your HCoop username.

Delivering all mail to a different address

If you want email sent to your HCoop email address to be forwarded elsewhere, you can do that as follows.

  • Make a .public/.forward file in your home directory.

  • It should contain only one line, consisting of just the e-mail address to which mail should be forwarded.

Putting mail into separate folders

If you want to do anything more complicated than this, the exim project website has some good examples http://www.exim.org/exim-html-current/doc/html/spec_html/filter_ch-exim_filter_files.html. We also have an example .forward file in the following section.

Examples

Please note, an exim filter file, as opposed to a standard UNIX .forward file, must start with a line consisting exactly of the string "# Exim filter". This line is not an ordinary comment and any change will cause Exim to attempt to treat it as a list of forward addresses instead of a filter file.

Also, you should create and subscribe to any folders mentioned in these filters from within your IMAP client before installing these scripts.

NathanKennedy

It is possible to set up custom filters to do fancy things based on the X-Spam-Level: header. Here is NathanKennedy's ~/.public/.forward file. He finds that the default setting of 5.0 is too wimpy, and lets too much spam into his inbox. Virtually no ham that he gets scores less than 3.0, whereas a lot of spam scores less than 5.0, so he'd rather have anything over 3.0 go to his Junk folder. At the same time, he doesn't want to waste time, cycles, disk space or bandwidth with spam over 9.0. Most of his spam does score 9.0, and this goes straight to /dev/null (immediately disposed of) with this filter.

Finally, he has all HCoop list email go into a special HCoop folder.

Without further ado:

# Exim filter
logfile $home/.logs/mail/spamlog
if $header_subject contains "[HCoop"
then
    save $home/Maildir/.HCoop/
    finish
endif
if
    "${if def:h_X-Spam-Level {def}{undef}}" is "def"
then
    if $h_X-Spam-Level: begins "\*\*\*\*\*\*\*\*\*"
    then save "/dev/null" 660
    else
      if $h_X-Spam-Level: begins "\*\*\*"
      then save $home/Maildir/.Junk/
      endif
    endif
    finish
endif
if
    "${if def:h_X-Spam-Flag {def}{undef}}" is "def"
then
    save $home/Maildir/.Junk/
    finish
endif

FrankBynum

# Exim filter
# Lists
if $h_to: contains "lists.hcoop.net"
        then save $home/Maildir/.Causes.Hcoop/
elif $h_to: contains "groups.barackobama.com"
        then save $home/Maildir/.Causes.Obama/
elif $h_X-Generated-By: CONTAINS "Launchpad"
        then save $home/Maildir/.Causes.Floss/
# Junk
elif $h_X-Spam-Level: begins "\*\*\*\*\*\*\*\*\*"
        then save "/dev/null" 660
elif $h_X-Spam-Level: begins "\*\*\*\*"
        then save $home/Maildir/.Junk.Spam/
elif $h_X-Spam-Status: contains "BAYES_99"
        then save $home/Maildir/.Junk.Bayes_99/
endif

StephenMichel

Sieve Filter

I've migrated to using a Sieve filter, which gives up a little power (that I was not using) for much saner syntax. This is the current version, including a commented-out part that I will probably remove since I don't think I'm using it any more. I've changed all domains to example.com to avoid spambots picking up email addresses off this page.

# Sieve filter

require ["fileinto"]; 

if address :contains ["to", "cc", "bcc"] ["admin@example.com", "community@example.com", "privacy@example.com"] {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.snowdrift.aliases/";
}
elsif address :contains :domain "to" "lists.example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.hcoop/";
}
# elsif address :matches ["to", "cc", "bcc"] ["snowdrift@example.com", "snowdrift+*@example.com"] {
#     fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.snowdrift/";
# }
# elsif address :matches ["to", "cc", "bcc"] ["tufts@example.com", "tufts+*@example.com"] {
#     fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.tufts/";
# }
elsif address :contains ["to", "from", "cc", "bcc"] "board@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.Board/";
}
elsif address :contains "from" "notifications@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.GitHub/";
}
elsif address :contains "to" "gitlab.com+notifications@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.GitLab/";
}
elsif header :matches "Reply-To" "*@boards.example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.Trello/";
}
elsif address :contains "to" "hnreplies.com@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.notifications.HN/";
}
elsif address :contains "to" "2_DO@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.2_DO/";
}
elsif address :contains "to" "2_READ@example.com" {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.2_READ/";
}
elsif allof (
    address :contains "from" "admin@example.com",
    header :contains "subject" "[Lutris]  Your daily moderator mail"
) {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/.lutris/";
}
else {
    fileinto "/afs/hcoop.net/user/s/sm/smichel17/Maildir/";
}
stop;

Exim Filter

This template filters anything sent to me@example.com or to me+$anything@example.com into the sub-folder me. This is useful if you have one or more aliases set up, to filter mail for each alias into its own subfolder.

if "$h_to:, $h_cc:, $h_bcc:" matches "me(\\\\+[\\^@]\\*)\\?@example\\\\.com"
        then save $home/Maildir/.me/
endif

Björn Lindström

Some rules using matches which allows PCRE style regular expressions.

# Exim filter

# Log
logfile $home/.logs/mail/exim.log

# Don't do any filtering on delivery failure messages from Exim.
if error_message then finish endif

# Spam
if "${if def:h_X-Spam-Level {def}{undef}}" is "def" then
    # Drops mail with a spam level above 9
    if $h_X-Spam-Level: matches "^\\\\*{9}" then
        seen
        finish
    # Puts other mail with a spam level above 3 into "Spam"
    elif $h_X-Spam-Level: matches "^\\\\*{3}" then
        save $home/Maildir/.Spam/
        finish
    endif
elif "${if def:h_X-Spam-Flag {def}{undef}}" is "def" then
    # Puts other mail with spam flag set into "Spam" also.
    save $home/Maildir/.Spam/
    finish
endif

# Filter into folders
if "$h_to:, $h_cc:, $h_bcc:" matches "\\\\b((bkhl|upp?sala|relax)@fandom\\\\.se|upp?salafandom@dang\\\\.se|fanac@lists\\\\.lysator\\\\.liu\\\\.se)\\\\b" then
    save $home/Maildir/.Fandom/
elif "$h_to:, $h_cc:, $h_bcc:" matches "@(\\.*\\\\.)?hcoop\\\\.net\\\\b" then
    save $home/Maildir/.HCoop/
endif

Filtering out bogus bounce messages

AdamChlipala found a trick a while back that allows you to filter out bogus bounce messages. https://lists.hcoop.net/pipermail/hcoop-discuss/2007-January/000745.html


CategoryMemberManual CategoryNeedsWork

MemberManual/Email/EximFilter (last edited 2020-09-03 21:58:33 by StephenMichel)