User:Wraeth/Sieve

From Gentoo Wiki
Jump to: navigation, search

The following are sieve scripts that should help manage and organize Gentoo-related mail. This slightly expands upon the example given in the Project:Infrastructure/Developer E-Mail/Sieve Example page. For more information about sieve itself, see the External resources section below.

The master.sieve script is selected as the active script and simply loads the remainder and provides a fallback action. Each rule also issues a stop statement so that further processing of the message doesn't take place.

Setup

To set this up, create a directory on dev.gentoo.org called ~/sieve. Within this directory you place each of your sieve scripts (named <scriptname>.sieve). You then point to the master sieve script and tell the LDA to use the sieve scripts using the below:

user $ln -s sieve/master.sieve ~/.dovecot.sieve
user $echo '| "/usr/libexec/dovecot/deliver"' > ~/.forward

Note that mail-client/thunderbird has an extension to manage sieve scripts, however the current version from the Mozilla repository doesn't work - you will need to download a development build from the GitHub repository.

Note
The path separator for folders is ., not /, so a path of INBOX.bugs actually means a folder named bugs that is inside your INBOX.

The scripts

FILE ~/sieve/master.sieve
require ["include", "fileinto"];

include :personal "spam";
include :personal "testing";
include :personal "bugs";
include :personal "lists";
include :personal "aliases";

# Default action
keep;
FILE ~/sieve/spam.sieve
require ["envelope", "fileinto", "mailbox"];

if exists "X-Spam-Flag" {
  if header :contains "X-Spam-Level" "*****" {
    fileinto :create "Junk";
    stop;
  }
}
FILE ~/sieve/testing.sieve
require ["regex", "mailbox", "fileinto", "variables", "envelope", "subaddress"];

# obviously you may want to disable these at some point
if header :regex "Subject" "another (.*)" {
  fileinto "INBOX.${1}";
  stop;
}

if envelope :detail "To" "test" {
  # matches 'wraeth+test@gentoo.org'
  fileinto :create "INBOX.test";
  stop;
}

#if header :contains "From" "wraeth@wraeth.id.au" {
#  fileinto :create "INBOX.test";
#  stop;
#}
FILE ~/sieve/lists.sieve
require ["fileinto", "mailbox", "regex", "variables"];

# Gentoo Lists
if header :regex "List-Id" "gentoo-(.*)\.gentoo\.org" {
  fileinto :create "INBOX.list.${1}";
  stop;
}
FILE ~/sieve/aliases.sieve
require [
  "duplicate",
  "fileinto",
  "mailbox",
  "regex",
  "variables"
];

# this will need any new aliases added to the regex match
if not header :is ["To", "CC"] "wraeth@gentoo.org" {
  if header :regex ["To", "CC"] "(proxy-maint|sci-geo|maintainer-needed).*@gentoo.org" {
    if not duplicate {
      fileinto :create "INBOX.proj.${1}";
      stop;
    } else {  # this is a safeguard for duplicates
      fileinto :create "INBOX.test";
      stop;
    }
  }
}
FILE ~/sieve/bugs.sieve
require ["fileinto", "mailbox"];

if allof (
    header "To" "wraeth@gentoo.org",
    header "From" "bugzilla-daemon@gentoo.org") {
  fileinto :create "INBOX.bugs";
  stop;
}

External resources