# README
Mail Rules
A simple IMAP client which continuously applies mail rules to your Inbox. Rules are defined in a file, for example rules.txt
.
The language consists of semicolon-delimited rules, each of which is a predicate followed by an action. For example:
if from = "[email protected]" or subject = "Deal!" then move "Archive";
will move any emails from [email protected]
or the subject Deal!
to your archive.
The predicate is formed of:
- Field equivalence,
to = "[email protected]"
- Field regular expression matches,
to ~ "@example.com$"
- Boolean operators
and
,or
andnot
,to ~ "@example.com$" and not to = "[email protected]"
- Parenthesis for grouping
The action can be one of:
- Move the message to a new folder,
move "Archive"
- Flag the message, optionally with a custom flag,
flag
orflag "My Flag"
Regular expressions provide a powerful matching mechanism, for example:
if to ~ "^marketing\+" then move "Marketing";
will move any email sent to custom addresses like [email protected]
to the folder Marketing
. Likewise the rule:
if from ~ "[@.]llbean.com$" then move "Marketing";
will move any email sent from an llbean.com
email addres, or a subdomain of llbean.com
(such as [email protected]
) to the folder Marketing
.
To Do
Possible future features:
- Reload configuration periodically
- Run at least once every x period
- Support reading from mailboxes other than Inbox
- Support rules that operate on these mailboxes (default to Inbox?)
- Support rules which can use data extracted from the predicate (e.g. regex capture groups can be templated into folder name)
Creds
Use an app-specific password.
Running
To run locally, first install goyacc
:
; go install modernc.org/goyacc@latest
Then generate the parser:
go generate ./parse
Then compile and run mailrules
:
go run . \
--host=imap.mail.me.com:993 \
--username=$(op read op://Personal/mailrules-icloud/username) \
--password=$(op read op://Personal/mailrules-icloud/password) \
--rules=rules.txt
To run within a docker image:
; docker build .
; docker run \
-v $(pwd)/rules.txt:/etc/mailrules/rules.txt \
sha256:1c2fdd985c6b3fae9e7c5613c249c1f3bfb2c3ae788bfabad3134e9b8ab83e86 \
--host=imap.mail.me.com:993 \
--username=$(op read op://Personal/mailrules-icloud/username) \
--password=$(op read op://Personal/mailrules-icloud/password) \
--rules=/etc/mailrules/rules.txt
Deploy
- Create a configmap containing our rules
; kubectl create configmap mailrules-rules --from-file=./rules.txt
- Create a secret with login info
; kubectl create secret generic mailrules-icloud \ --from-literal=username=$(op read op://Personal/mailrules-icloud/username) \ --from-literal=password=$(op read op://Personal/mailrules-icloud/password)
- Run
./deploy
to build the image and template thedeployment.yaml