A quick tool for generating Gmail filters from YAML rules.
Project description
gmail-yaml-filters
A quick tool for generating Gmail filters from YAML rules.
Interested in helping? See CONTRIBUTING.md for a few guidelines.
Getting Started
It's strongly recommended to use a tool like pipx to install this package in an isolated environment:
$ pipx install gmail-yaml-filters
Generating XML
By default, the command line script will generate XML to stdout, which you can then upload to Gmail yourself:
$ gmail-yaml-filters my-filters.yaml > my-filters.xml
Synchronization via Gmail API
If you are the trusting type, you can authorize the script to
upload new filters and remove obsolete filters via Gmail's API.
Before using any of these commands, you will need to create
client_secret.json
and store it in the same directory as your YAML file.
# Upload all filters (and create new labels) from the configuration file
$ gmail-yaml-filters --upload my-filters.yaml
# Delete any filters that aren't defined in the configuration file
$ gmail-yaml-filters --prune my-filters.yaml
# Do both of these steps at once.
$ gmail-yaml-filters --sync my-filters.yaml
# See what would happen but don't apply any changes.
$ gmail-yaml-filters --dry-run --sync my-filters.yaml
# Delete all your filters. (Yikes!)
$ gmail-yaml-filters --delete-all
If you need to pipe configuration from somewhere else, you can do that by passing a single dash as the filename.
# (but why would you need to do this?)
$ cat filters.yaml | gmail-yaml-filters --sync -
Sample Configuration
# Simple example
-
from: googlealerts-noreply@google.com
label: news
not_important: true
# Boolean conditions
-
from:
any:
- alice
- bob
- carol
to:
all: [me, -MyBoss]
label: conspiracy
# Nested conditions
-
from: lever.co
label: hiring
more:
-
has: 'completed feedback'
archive: true
-
has: 'what is your feedback'
star: true
important: true
# Foreach loops
-
for_each:
- list1
- list2
- list3
rule:
to: "{item}@mycompany.com"
label: "{item}"
# Foreach loops with complex structures
-
for_each:
- [mailing-list-1a, list1]
- [mailing-list-1b, list1]
- [mailing-list-1c, list1]
- [mailing-list-2a, list2]
- [mailing-list-2b, list2]
rule:
to: "{item[0]}@mycompany.com"
label: "{item[1]}"
-
for_each:
- {list: list1, domain: example.com}
- {list: list2, domain: whatever.com}
rule:
to: "{list}@{domain}"
label: "{list}"
Configuration
Supported conditions:
has
(alsomatch
)does_not_have
(alsomissing
,no_match
)subject
list
labeled
from
,to
,cc
, andbcc
category
deliveredto
filename
larger
smaller
size
rfc822msgid
is
andhas
work like Gmail's search operators, for example:has: attachment
is translated tomatch: "has:attachment"
is: -snoozed
is translated tono_match: "is:snoozed"
Supported actions:
archive
forward
important
(alsomark_as_important
)label
, including support for Gmail's category tabs:CATEGORY_PERSONAL
CATEGORY_SOCIAL
CATEGORY_PROMOTIONS
CATEGORY_UPDATES
CATEGORY_FORUMS
not_important
(alsonever_mark_as_important
)not_spam
read
(alsomark_as_read
)star
trash
(alsodelete
)
Any set of rules with ignore: true
will be ignored and not written to XML.
Similar Projects
- gmail-britta is written in Ruby and lets you express rules with a DSL.
- gmail-filters is written in Python and has a web frontend.
- google-mail-filter is written in Haskell and lets you express rules with a DSL.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file gmail-yaml-filters-0.10.0.tar.gz
.
File metadata
- Download URL: gmail-yaml-filters-0.10.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bf1b428281c2a1a9534d14fa6ecdd688d98a3da812a0d7a4c3aafd5b64c3fca |
|
MD5 | eeb86d6a32af17e108fe3dc5ede26f6f |
|
BLAKE2b-256 | 5bf2dba4818fec40af6a3c8c571dd889c0f35c5da6858e3fa81bcf3eec677861 |