Skip to main content

A quick tool for generating Gmail filters from YAML rules.

Project description

gmail-yaml-filters

Build Status

A quick tool for generating Gmail filters from YAML rules.

Interested in helping? See CONTRIBUTING.md for a few guidelines.

Getting Started

By default, the command line script will generate XML to stdout, which you can then upload to Gmail yourself:

$ pip install gmail-yaml-filters
$ 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

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 (also match)
  • does_not_have (also missing, no_match)
  • subject
  • list
  • labeled
  • from, to, cc, and bcc
  • category
  • deliveredto
  • filename
  • larger
  • smaller
  • size
  • rfc822msgid
  • is and has work like Gmail's search operators, for example:
    • has: attachment is translated to match: "has:attachment"
    • is: -snoozed is translated to no_match: "is:snoozed"

Supported actions:

  • archive
  • forward
  • important (also mark_as_important)
  • label, including support for Gmail's category tabs:
    • CATEGORY_PERSONAL
    • CATEGORY_SOCIAL
    • CATEGORY_PROMOTIONS
    • CATEGORY_UPDATES
    • CATEGORY_FORUMS
  • not_important (also never_mark_as_important)
  • not_spam
  • read (also mark_as_read)
  • star
  • trash (also delete)

Any set of rules with ignore: true will be ignored and not written to XML.

Similar Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmail-yaml-filters-0.9.3.tar.gz (11.9 kB view details)

Uploaded Source

File details

Details for the file gmail-yaml-filters-0.9.3.tar.gz.

File metadata

  • Download URL: gmail-yaml-filters-0.9.3.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/2.7.16

File hashes

Hashes for gmail-yaml-filters-0.9.3.tar.gz
Algorithm Hash digest
SHA256 74bcbc6305a98066e7aa0320b5a5c89814dbdb764b98ac94673ed7dd24872fcd
MD5 39ee826c70a9fedbdb2c092c0ec3a10f
BLAKE2b-256 26d5b6ec3f9c7a8ed6152897002dc6a409a42f4b8b411590fee5843593ea1617

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page