SieveFiler
is a Swift-based DSL to aid in creating Sieve (RFC 5228) "fileinto" rules for server-side mail sorting. The primary goal is to make it easier and less error-prone to creating rules for filing mail into specific folders.
SieveFiler
will:
- Ensure generated sieve rules are ordered from specific to general
- Ensure full email addresses are given for
Addresses()
- Ensure only domain names are given for
Domains()
andSubDomains()
- Ensure conflicting rules are not possible (e.g. cannot specify that the same email address goes to different folders)
- Not overwrite the file if any errors are detected
SubDomains()
matcher makes it easy to specify rules to match either "@domain.xyz" or "*.domain.xyz".
Swift Compiler 5.7+. By utilizing the Swift language, you can use Xcode or any other IDE/text editor to aid in command completion and online help as you write your rules.
The simplest usage is to install swift-sh:
mint install swift-sh
Then create your Sieve script like so:
#!/usr/bin/swift sh
import SieveFiler // @dannys42
import Foundation
try SieveRules {
Folder("Family") {
Fields(.from) {
Domains("myfamily.xyz") // matches exactly the addresses given
}
}
Folder("Parents") {
Fields(.from) {
Addresses("[email protected]", "[email protected]") // matches exactly the addresses given
}
}
Folder("Classmates") {
Fields(.from, .replyTo) {
Domains("myschoolalumnis.edu") // matches exactly emails that have `myschoolalumnis.edu` after the "@" sign
SubDomains("myschool.edu") // matches *.myschool.edu and @myschool.edu
}
}
}.output(".dovecot.sieve")
This will create rules in the following order:
- Mail from
[email protected]
and[email protected]
will go intoParents
- Mail from anyone else in the
myfamily.xyz
domain will go toFamily
- Any mail with a
From
orReply-To
field with a domain of exactlymyschoolalumnis.edu
will go intoClassmates
- Any mail with a
From
orReply-To
field with a domain or any subdomain ofmyschool.edu
will also go intoClassmates
Additional conveniences:
Domains
,SubDomains
, andAddresses
can also take array arguments to allow for flexibility in trailing commas. For example:
Folder("Parents") {
Fields(.from) {
Addresses([
"[email protected]",
"[email protected]",
])
}
}
- In cases where only one type of
Fields
matching is needed, you can specify that field on theFolder()
line. For example:
Folder("Parents", fields: .from) {
Addresses([
"[email protected]",
"[email protected]",
])
}